Day: 71/365 📌 LeetCode POTD: Count Submatrices with Top-Left Element and Sum Less Than k Medium Key takeaways/Learnings from this problem: 1. Prefix sum is the hero here—once you precompute it, submatrix sum becomes instant lookup instead of recomputing every time. 2. Fixing the top-left corner simplifies things a lot, turning a 2D problem into something more manageable. 3. Instead of brute forcing all submatrices, you just expand and check smartly using precomputed sums. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
LeetCode POTD: Counting Submatrices with Top-Left Element and Sum Less Than k
More Relevant Posts
-
Day: 72/365 📌 LeetCode POTD: Count Submatrices With Equal Frequency of X and Y Medium Key takeaways/Learnings from this problem: 1. The key idea is converting the problem into numbers (like +1 and -1) so equal frequency turns into a sum = 0 problem. 2. 2D prefix sums really help here—you can quickly get submatrix sums without recalculating every time. 3. It’s a nice extension of 1D subarray problems to 2D, so knowing those basics pays off big time. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
Day: 76/365 📌 LeetCode POTD: Maximum Non Negative Product in a Matrix Medium Key takeaways/Learnings from this problem: 1. This problem shows why tracking only max isn’t enough—you need both max and min products because negatives can flip the result. 2. Classic DP twist where each cell depends on top and left, but with sign handling making it interesting. 3. Big takeaway: whenever multiplication + negatives are involved, always think about dual states (min & max). #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
Solved a problem where we need to check if two strings can be made equal using a special operation. The rule is: you can swap characters only if the distance between their positions is even. So basically, characters at even indices can only swap among themselves, and same for odd indices. Idea: Instead of actually swapping, I just counted characters separately for even and odd positions in both strings. If both match, then it’s possible — otherwise not. Simple concept, but interesting twist! 😊 #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day: 75/365 📌 LeetCode POTD: Determine Whether Matrix Can Be Obtained By Rotation Easy Key takeaways/Learnings from this problem: 1. This problem shows that sometimes brute force (trying all 4 rotations) is perfectly fine and clean. 2. Rotating a matrix becomes easy once you remember the transpose + reverse trick. 3. Always compare after each rotation instead of overcomplicating the logic upfront. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
Day: 74/365 📌 LeetCode POTD: Flip Square Submatrix Vertically Easy Key takeaways/Learnings from this problem: 1. This one highlights how matrix manipulation is mostly about correct indexing, not complex logic. 2. Flipping vertically is just swapping rows within the selected submatrix—visualizing it helps a lot. 3. Good reminder to be careful with boundaries when working on submatrices, not the whole grid. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
🚀 𝗗𝗮𝘆 𝟭𝟬 𝗼𝗳 𝟭𝟬𝟬: 𝗦𝗼𝗹𝘃𝗶𝗻𝗴 LeetCode! Today I focused on applying the 𝗣𝗿𝗲𝗳𝗶𝘅 𝗦𝘂𝗺 concept to identify balanced positions in an array. 📌 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀 𝗦𝗼𝗹𝘃𝗲𝗱 𝗧𝗼𝗱𝗮𝘆 (𝗗𝗮𝘆 𝟭𝟬) 🔹 𝗙𝗶𝗻𝗱 𝘁𝗵𝗲 𝗠𝗶𝗱𝗱𝗹𝗲 𝗜𝗻𝗱𝗲𝘅 𝗶𝗻 𝗔𝗿𝗿𝗮𝘆 ✅ Goal: Find an index where the sum of elements on the left is equal to the sum on the right. If multiple exist, return the leftmost one. Approach: Calculated the total sum of the array, then traversed it while maintaining a running left sum. At each index, compared left sum with "(total sum - left sum - current element)" to check if it satisfies the condition, achieving O(n) time complexity. #100DaysOfCode #DSA #LeetCode #Java #ProblemSolving #CodingJourney #PrefixSum #Arrays
To view or add a comment, sign in
-
-
Day 31/50 🚀 — Reverse Vowels of a String (LeetCode 345) Today’s problem was a great reminder that sometimes the simplest approaches are the most efficient. 🔹 Used the two-pointer technique 🔹 Focused on in-place swapping 🔹 Optimized for both time (O(n)) and space (O(1)) Key takeaway: Instead of overthinking, break the problem into smaller checks—identify vowels, move pointers smartly, and swap only when needed. Clean and efficient 💡 Happy to see this solution performing well: ⚡ Runtime: 2 ms (faster than 99%+) 📦 Space: Decent optimization #Day31 #LeetCode #DSA #Java #CodingJourney #50DaysOfCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
Solved LeetCode 2839 – Check if Strings Can be Made Equal With Operations I today. In simple terms, we are given two strings and allowed to swap characters only at positions that are 2 indices apart (like index 0 with 2, 1 with 3). So instead of trying all swaps, the idea is to separate characters at even and odd positions and check if both strings have the same characters in those positions. If the frequency of characters matches for even and odd indices separately, then the strings can be made equal. A simple yet interesting problem that improves thinking around patterns and constraints. #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day: 95/365 📌 LeetCode POTD: Minimum Distance Between Three Equal Elements II Medium Key takeaways/Learnings from this problem: 1. This one highlights how tracking indices smartly is more important than checking all triplets brute-force. 2. Using previous occurrences helps you narrow down valid triples quickly instead of re-scanning the array. 3. Big takeaway: problems with “equal elements” often reduce to index management + pattern observation. 4. Also a good reminder that optimizing from O(n³) thinking to near O(n) comes down to storing the right info while iterating. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
🚀 𝐃𝐚𝐲 86/100 – 𝐋𝐨𝐧𝐠𝐞𝐬𝐭 𝐂𝐨𝐧𝐬𝐞𝐜𝐮𝐭𝐢𝐯𝐞 𝐒𝐞𝐪𝐮𝐞𝐧𝐜𝐞 Today’s problem was Longest Consecutive Sequence — a great example of optimizing from brute force to an efficient solution using hashing. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: Sorting would take O(n log n), but we can solve this in O(n) using a HashSet. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Store all elements in a set for O(1) lookup Only start counting when the current number is the start of a sequence 𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? This ensures we only count each sequence once, avoiding unnecessary repeated work. ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Add all elements to a HashSet Iterate through the set: If (num - 1) doesn’t exist → start a sequence Keep increasing and count streak Track maximum length ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) #Day86 #100DaysOfCode #Java #DSA #LeetCode #HashSet #CodingJourney
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development