🚀 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
SURIYA D’s Post
More Relevant Posts
-
🚀 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
To view or add a comment, sign in
-
-
🚀 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 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 17 of 100 Days LeetCode Challenge Problem: Largest Submatrix With Rearrangements Today’s problem is a powerful mix of matrix + greedy + sorting optimization 🔥 💡 Key Insight: We are allowed to rearrange columns, which changes everything! 👉 Instead of fixed positions: Focus on heights of consecutive 1’s in each column 🔍 Core Approach: 1️⃣ Build Heights Matrix For each cell: If 1 → increase height from previous row If 0 → reset to 0 👉 This converts the problem into a histogram per row 2️⃣ Sort Each Row (Greedy Move) Sort heights in descending order Why? → To maximize width for larger heights 3️⃣ Calculate Max Area For each position j: Area = height[j] × (j + 1) Track maximum across all rows 🔥 What I Learned Today: Rearrangement problems → think flexibility optimization Converting matrix → histogram simplifies logic Sorting can unlock hidden maximums 📈 Challenge Progress: Day 17/100 ✅ Strong consistency streak! LeetCode, Matrix, Greedy Algorithm, Sorting, Histogram, Optimization, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #GreedyAlgorithm #Sorting #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
𝗖𝗼𝗱𝗲 𝗿𝗲𝘃𝗶𝗲𝘄 𝗶𝘀𝗻’𝘁 𝗷𝘂𝘀𝘁 𝗮𝗯𝗼𝘂𝘁 𝗰𝗼𝗱𝗲. It’s about emotions. You submit a PR. First comment: • “𝗖𝗮𝗻 𝘄𝗲 𝗿𝗲𝗻𝗮𝗺𝗲 𝘁𝗵𝗶𝘀 𝘃𝗮𝗿𝗶𝗮𝗯𝗹𝗲?” You fix it. Second comment: • “𝗧𝗵𝗶𝘀 𝗹𝗼𝗴𝗶𝗰 𝗰𝗮𝗻 𝗯𝗲 𝘀𝗶𝗺𝗽𝗹𝗶𝗳𝗶𝗲𝗱.” You fix it. Third comment: • “𝗪𝗵𝘆 𝗱𝗶𝗱 𝘄𝗲 𝗱𝗼 𝗶𝘁 𝘁𝗵𝗶𝘀 𝘄𝗮𝘆?” Now you start questioning your life. By the end: Code is better. You are not. #DeveloperLife #TechHumor #EngineeringLife #ProgrammingLife #DevSecOps
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
-
-
I spent 30 minutes overthinking a problem that had a 2-minute solution. Problem: Construct Uniform Parity Array I At first, it feels like a construction + constraints problem. You start thinking about cases, patterns, edge conditions… But then I stepped back and looked at the operations: nums2[i] = nums1[i] nums2[i] = nums1[i] - nums1[j] (j ≠ i) Now ask a better question: 👉 What happens to parity under these operations? Same value => parity unchanged Difference of two numbers => can be even or odd depending on choice That’s the key. You can control parity freely. Just to make the entire array all even or all odd And that’s always possible. So the answer would be always TRUE . #FirstPrinciples #ProblemSolving #CodingJourney #LeetCode #DSA #Algorithms #SoftwareEngineering #Developers #CodeNewbie #LearnToCode #ProgrammingLife #TechThinking #LogicalThinking #BuildInPublic #DeveloperMindset #CleanThinking #CodingLife #TechCareers #GrowthMindset #ThinkDifferent
To view or add a comment, sign in
-
-
Many people claim that SOLID is merely a theoretical concept that lacks practical application. I used to share that sentiment. However, my perspective changed when I began focusing on testable code. While it's not always necessary to write unit tests for every class, practicing unit testing shifts your mindset regarding class design. - Hardcoded dependencies make testing difficult, preventing you from isolating behavior or properly mocking components. This is where Dependency Inversion becomes relevant. - When a class takes on too many responsibilities, tests become complicated and hard to maintain, prompting you to break it down. This aligns with the Single Responsibility Principle (SRP). - If adding a new feature requires modifying existing code, tests may break, leading you to design for extension, which reflects the Open/Closed Principle (OCP). - If changing one implementation causes tests to fail, it indicates a flaw in your abstraction, relating to the Liskov Substitution Principle (LSP). - Large interfaces lead to tests depending on unused components, necessitating their division, which is the Interface Segregation Principle (ISP). Testability is what truly makes SOLID resonate. Theory explains what SOLID is, while testing illustrates its significance. Once you grasp this connection, SOLID evolves from mere rules into instinct. #SOLIDPrinciples #CleanCode #SoftwareEngineering #UnitTesting #TestableCode #CodeQuality #SystemDesign #SoftwareDevelopment #Programming #DevCommunity #Refactoring #DeveloperMindset
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
-
-
Thanks Azim Siddiqui for explaining SOLID principles. A few months ago, I kept running into the same problem… every time I changed one part of my code, something else broke. That’s when I truly started understanding SOLID principles—not just as theory, but as something that saves you from chaos. Single Responsibility hit me first. I stopped stuffing everything into one class. Things became easier to read, test, and fix. Then Open/Closed made me rethink how I add features. Instead of editing old code (and risking bugs), I started extending it. Much safer. Liskov taught me a hard lesson: just because inheritance works syntactically doesn’t mean it works logically. Interface Segregation helped me simplify. Smaller interfaces = less confusion. And Dependency Inversion? That changed how I structure everything. Depending on abstractions made my code more flexible than I expected. I won’t say I follow SOLID perfectly every time. But even trying to apply it has made me a better developer. If your code feels messy, don’t start over. Start small. One principle at a time. #SoftwareEngineering #CleanCode #SOLIDPrinciples #Programming #SystemDesign
To view or add a comment, sign in
Explore related topics
- LeetCode Array Problem Solving Techniques
- Approaches to Array Problem Solving for Coding Interviews
- Leetcode Problem Solving Strategies
- Why Use Coding Platforms Like LeetCode for Job Prep
- Common Coding Interview Mistakes to Avoid
- How to Use Arrays in Software Development
- Common Algorithms for Coding Interviews
- Strategies for Solving Algorithmic Problems
- How to Improve Array Iteration Performance in Code
- Solving Sorted Array Coding Challenges
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