🚀 Day 19 of 100 Days LeetCode Challenge Problem: Count Submatrices With Equal Frequency of X and Y Today’s problem was a solid combination of 2D Prefix Sum + Hashing concept 🔥 💡 Key Insight: We need submatrices that: Include the top-left cell (0,0) Have equal number of 'X' and 'Y' Contain at least one 'X' 👉 Trick: Convert the grid into values: 'X' → +1 'Y' → -1 '.' → 0 🔍 Core Approach: 1️⃣ 2D Prefix Sum Transformation Build prefix sum based on above conversion 2️⃣ Check Each Submatrix (0,0 → i,j) If sum == 0 → equal number of X and Y ✅ 3️⃣ Extra Condition: Ensure at least one 'X' exists 👉 Track X count separately using another prefix matrix 🔥 What I Learned Today: Transforming problems into numbers simplifies logic Prefix sums + condition checks = powerful combo Always handle extra constraints carefully 📈 Challenge Progress: Day 19/100 ✅ Almost hitting Day 20! LeetCode, Prefix Sum, Matrix, Hashing, Problem Transformation, Algorithms, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #PrefixSum #Matrix #Hashing #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
LeetCode Challenge: Count Submatrices With Equal Frequency of X and Y
More Relevant Posts
-
🚀 Day 18 of 100 Days LeetCode Challenge Problem: Count Submatrices with Top-Left Element and Sum ≤ k Today’s problem is a clean application of 2D Prefix Sum (Cumulative Sum) 🔥 💡 Key Insight: All valid submatrices must: Start from the top-left corner (0,0) Extend to any cell (i, j) 👉 So instead of checking all submatrices, we just: Compute sum from (0,0) to (i,j) Check if it’s ≤ k 🔍 Core Approach: 1️⃣ Build Prefix Sum Matrix prefix[i][j] = sum of all elements from (0,0) to (i,j) 2️⃣ Iterate Through Grid For every (i, j): If prefix[i][j] ≤ k → count it ✅ 👉 That’s it! No need for complex nested submatrix checks 🚀 🔥 What I Learned Today: Constraints simplify problems → use them wisely 2D prefix sum reduces O(n⁴) → O(n²) Always check if the problem has a fixed starting point 📈 Challenge Progress: Day 18/100 ✅ Almost 20 days consistency! LeetCode, Prefix Sum, Matrix, 2D Arrays, Optimization, Algorithms, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #PrefixSum #Matrix #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 29 of 100 Days LeetCode Challenge Problem: Check if Strings Can be Made Equal With Operations I Day 29 is a short but pattern + constraint observation problem 🔥 💡 Key Insight: We can only swap characters where: 👉 j - i = 2 For a string of length 4, possible swaps: Index 0 ↔ 2 Index 1 ↔ 3 👉 That means: Positions (0,2) form one group Positions (1,3) form another group 🔍 Core Approach: 1️⃣ Group Characters Extract characters from: Even indices → [0, 2] Odd indices → [1, 3] 2️⃣ Compare Groups Sort both groups for s1 and s2 If both corresponding groups match → ✅ true Else → ❌ false 💡 Why This Works: You can rearrange freely within each group But cannot mix between groups 🔥 What I Learned Today: Limited operations define independent groups Think in terms of index grouping Small problems still test logical clarity 📈 Challenge Progress: Day 29/100 ✅ One day to 30! LeetCode, Strings, Swapping, Greedy, Pattern Recognition, Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Strings #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 14 of 100 Days LeetCode Challenge Problem: The K-th Lexicographical String of All Happy Strings of Length n Today’s problem is a perfect blend of Backtracking + Lexicographical Ordering 🔥 💡 Key Insight: A happy string: Uses only 'a', 'b', 'c' No two adjacent characters are the same 👉 Instead of generating all strings blindly, we: Build valid strings using backtracking Maintain lexicographical order naturally 🔍 Core Approach: 1️⃣ Backtracking (DFS) Start building string character by character At each step: Choose from 'a', 'b', 'c' Skip if same as previous character 2️⃣ Lexicographical Order Always try characters in order: 'a' → 'b' → 'c' 3️⃣ Stop Early Once we reach the k-th string, stop recursion 👉 If total strings < k → return "" 🔥 What I Learned Today: Backtracking is powerful for constraint-based generation Ordering decisions early helps avoid extra sorting Early stopping = major optimization 📈 Challenge Progress: Day 14/100 ✅ 2 weeks strong! LeetCode, Backtracking, Recursion, Lexicographical Order, Strings, DFS, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Backtracking #Recursion #Strings #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 23 of 100 Days LeetCode Challenge Problem: Maximum Non-Negative Product in a Matrix Today’s problem was a deep dive into Dynamic Programming with edge cases (negative values) 🔥 💡 Key Insight: Since the grid contains negative numbers, the product can flip sign. 👉 So at each cell, we must track: Maximum product so far Minimum product so far Because: Negative × Negative = Positive 💥 🔍 Core Approach (DP): 1️⃣ DP State: For each cell (i, j) maintain: maxProduct[i][j] minProduct[i][j] 2️⃣ Transition: From top (i-1, j) and left (i, j-1): Multiply current value with both max & min Take: max → for maxProduct min → for minProduct 3️⃣ Final Answer: If final max ≥ 0 → return max % (10⁹ + 7) Else → return -1 🔥 What I Learned Today: Negative values require tracking both extremes DP is not always just “max”—sometimes it’s min + max together Edge cases define the real difficulty of a problem 📈 Challenge Progress: Day 23/100 ✅ Getting stronger with DP! LeetCode, Dynamic Programming, Matrix, Optimization, Negative Numbers, Algorithms, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #DynamicProgramming #Matrix #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
Day 77 on LeetCode Find Smallest Letter Greater Than Target 🔤🔍✅ Continuing the streak with a clean Binary Search application — keeping things simple and consistent during mids 💯 🔹 Approach Used in My Solution The goal was to find the smallest character strictly greater than the target in a sorted array, with wrap-around behavior. Key idea: • Apply binary search on the sorted array • Whenever letters[mid] > target, store it as a potential answer • Move left to find an even smaller valid character • If no such character exists, return letters[0] (wrap-around case) This ensures we always get the next greatest letter efficiently. ⚡ Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) 💡 Key Takeaways: • Practiced binary search for “next greater element” problems • Learned how to handle wrap-around edge cases • Reinforced writing clean and optimized search logic 🔥 Small wins every day consistency is the real progress. #LeetCode #DSA #Algorithms #DataStructures #BinarySearch #Arrays #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #Consistency #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 72 on LeetCode Search a 2D Matrix 🔍📊✅ Today’s problem was a great application of Binary Search in 2D, breaking it down into two efficient steps. 🔹 Approach Used in My Solution The goal was to determine whether a target exists in a sorted 2D matrix. Key idea in the solution: • First, apply binary search on rows to find the potential row where the target could exist – Check if target lies between matrix[mid][0] and matrix[mid][cols-1] • Once the correct row is found, apply binary search within that row • Return true if found, otherwise false This avoids scanning the entire matrix and ensures efficiency. 🔹 Why This Works Because: • Each row is sorted • The first element of each row is greater than the last of the previous row So we can treat it like a two-level binary search problem. ⚡ Complexity: • Time Complexity: O(log m + log n) • Space Complexity: O(1) 💡 Key Takeaways: • Learned how to extend binary search to 2D structures • Practiced breaking problems into smaller searchable spaces • Reinforced thinking in terms of hierarchical searching 🔥 Another solid step in mastering binary search patterns! #LeetCode #DSA #Algorithms #DataStructures #BinarySearch #Matrix #2DArray #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
🚀 Day 24 of 100 Days LeetCode Challenge Problem: Construct Product Matrix Today’s problem is a 2D extension of a classic concept: 👉 “Product of Array Except Self” 🔥 💡 Key Insight: For each cell (i, j), we need: Product of all elements except grid[i][j] Without using division (important!) 🔍 Core Approach: 1️⃣ Flatten the Matrix Treat the matrix like a 1D array 2️⃣ Prefix Product Store product of elements before index 3️⃣ Suffix Product Store product of elements after index 4️⃣ Final Value: p[i][j] = prefix * suffix % 12345 👉 This avoids division and works efficiently 💡 Optimization: Use modulo at every step to prevent overflow Space can be optimized by reusing arrays 🔥 What I Learned Today: Classic problems can appear in different forms (1D → 2D) Prefix & suffix patterns are extremely reusable Avoiding division is a common constraint in interviews 📈 Challenge Progress: Day 24/100 ✅ Almost 25 days strong! LeetCode, Prefix Product, Suffix Product, Matrix, Arrays, Optimization, Modular Arithmetic, DSA Practice, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #PrefixSum #Optimization #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
Day 80 on LeetCode Next Greater Element I 🔍📈✅ Not the optimal solution this time, but the focus remains the same consistency over perfection 💯 🔹 Approach Used in My Solution (Brute Force) The goal was to find the next greater element of each value in nums1 based on its position in nums2. Key idea: • For each element in nums1 → find its position in nums2 • From that index, scan to the right • The first element greater than current → that’s the answer • If none found → return -1 A straightforward approach that gets the job done. ⚡ Complexity: • Time Complexity: O(n * m) • Space Complexity: O(1) (excluding output) 🔹 Optimal Insight (For Next Time) • Use a monotonic decreasing stack on nums2 • Precompute next greater for all elements • Store results in a hash map for O(1) lookup 💡 Key Takeaways: • Even brute force builds understanding of the problem • Learned how nested traversal simulates next greater search • Not every day is about optimization — discipline matters more 🔥 Streak > Speed. Showing up daily is the real win. #LeetCode #DSA #Algorithms #DataStructures #Stack #MonotonicStack #Arrays #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #Consistency #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 73 on LeetCode Find First and Last Position of Element in Sorted Array 🎯🔍✅ Today’s problem focused on a classic and very important Binary Search variation. 🔹 Approach Used in My Solution The goal was to find the first and last occurrence of a target in a sorted array. Key idea in the solution: • Use two separate binary searches 🔸 Find First Occurrence: • When nums[mid] >= target, move left • If nums[mid] == target, store index and continue searching left 🔸 Find Last Occurrence: • When nums[mid] <= target, move right • If nums[mid] == target, store index and continue searching right • Combine both results to get final answer This ensures we don’t just find a match, but the complete range of the target. ⚡ Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) 💡 Key Takeaways: • Learned how to modify binary search to find boundaries instead of single elements • Strengthened understanding of first/last occurrence patterns • Realized how small logic changes turn binary search into powerful variants 🔥 This pattern is extremely common in interview problems! #LeetCode #DSA #Algorithms #DataStructures #BinarySearch #Arrays #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Day 81 on LeetCode Remove Linked List Elements 🔗🧹✅ Still prioritizing consistency during busy days — and today’s problem was a solid linked list traversal & deletion practice 💯 🔹 Approach Used in My Solution The goal was to remove all nodes with a given value from a linked list. Key idea: • First, handle edge cases where head itself contains the target value • Move head forward until it points to a valid node • Then traverse the list using two pointers: – prev → last valid node – temp → current node • If temp->val == val → skip the node by linking prev->next • Otherwise → move both pointers forward This ensures all matching nodes are removed efficiently. ⚡ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 💡 Key Takeaways: • Practiced pointer manipulation in linked lists • Learned how to safely handle deletions, especially at head • Reinforced importance of edge case handling 🔥 Small consistent steps → strong fundamentals. #LeetCode #DSA #Algorithms #DataStructures #LinkedList #Pointers #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #Consistency #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
Explore related topics
- LeetCode Array Problem Solving Techniques
- Leetcode Problem Solving Strategies
- Approaches to Array Problem Solving for Coding Interviews
- Tips for Coding Interview Preparation
- Strategies for Solving Algorithmic Problems
- Common Algorithms for Coding Interviews
- Why Use Coding Platforms Like LeetCode for Job Prep
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