🚀 Day 21 of 100 Days LeetCode Challenge Problem: Flip Square Submatrix Vertically Day 21 brings a clean matrix manipulation problem—simple logic, but important for fundamentals 🔥 💡 Key Insight: We are given: Top-left corner (x, y) Size k 👉 We need to flip the k x k submatrix vertically → Meaning: reverse the order of rows inside that square 🔍 Core Approach: 1️⃣ Identify Submatrix Boundaries Rows: x → x + k - 1 Columns: y → y + k - 1 2️⃣ Swap Rows Vertically Swap: Row x ↔ Row x + k - 1 Row x + 1 ↔ Row x + k - 2 Continue until middle 👉 Only swap elements within column range [y, y + k - 1] 💡 Visualization: Top row ⬇️ becomes bottom Bottom row ⬆️ becomes top 🔥 What I Learned Today: Matrix problems often come down to index manipulation Clear boundary definition avoids mistakes Simple operations can still test precision 📈 Challenge Progress: Day 21/100 ✅ 3 Weeks Consistency Strong! 💪 LeetCode, Matrix Manipulation, Arrays, Simulation, Indexing, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #Arrays #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
Flip Square Submatrix Vertically on LeetCode
More Relevant Posts
-
🚀 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
-
-
🚀 Day 22 of 100 Days LeetCode Challenge Problem: Determine Whether Matrix Can Be Obtained By Rotation Day 22 is a classic matrix rotation + simulation problem 🔥 💡 Key Insight: We can rotate the matrix in 90° steps (up to 4 times): 90° 180° 270° 360° (back to original) 👉 If at any step mat == target → ✅ True 🔍 Core Approach: 1️⃣ Rotate Matrix (90° Clockwise) Transpose the matrix Reverse each row 👉 This gives one 90° rotation 2️⃣ Repeat Rotation 4 Times After each rotation: Compare with target 👉 If match found → return true 👉 Else after 4 rotations → false 💡 Optimization: Early exit when match is found Avoid unnecessary rotations 🔥 What I Learned Today: Matrix rotation is a standard pattern Simulation problems require step-by-step accuracy Reusing logic reduces complexity 📈 Challenge Progress: Day 22/100 ✅ Staying consistent & sharp! LeetCode, Matrix, Rotation, Simulation, Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #Rotation #Simulation #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 16 of 100 Days LeetCode Challenge Problem: Get Biggest Three Rhombus Sums in a Grid Today’s problem was a matrix + geometry + prefix sum optimization challenge 🔥 💡 Key Insight: A rhombus is basically a rotated square, and we only need the border sum, not the entire area. 👉 Brute force works, but it’s slow. So we optimize using diagonal prefix sums. 🔍 Core Approach: 1️⃣ Understand Rhombus Shape Defined by a center and a “radius” Four edges → top, right, bottom, left 2️⃣ Efficient Border Sum Use diagonal prefix sums to quickly calculate edges Avoid recomputing each cell repeatedly 3️⃣ Track Top 3 Unique Sums Use a set or priority structure Keep only the largest 3 distinct values 🔥 What I Learned Today: Geometry-based problems require visual thinking Prefix sums are powerful beyond simple arrays Optimization matters when dealing with nested loops 📈 Challenge Progress: Day 16/100 ✅ Still consistent, still growing! LeetCode, Matrix, Prefix Sum, Geometry, Optimization, Arrays, DSA Practice, Coding Challenge, Problem Solving #100DaysOfCode #LeetCode #DSA #CodingChallenge #Matrix #PrefixSum #ProblemSolving #TechJourney #ProgrammerLife #SoftwareDeveloper #CodingLife #LearnToCode #Developers #Consistency #GrowthMindset #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 6 — Remove Duplicates from Sorted Array Continuing my journey of improving problem-solving skills with consistency and discipline — one problem every day. Today’s problem focused on optimizing space and modifying arrays efficiently in-place. 🧩 Problem Solved: • Remove Duplicates from Sorted Array (LeetCode #26) 📚 Topic: Two Pointers + Array Manipulation 💡 Key Insight: Since the array is already sorted, duplicates are adjacent — making it possible to remove them using a two-pointer approach without extra space. ⚡ Approach: • Initialize a pointer i to track unique elements • Traverse array using another pointer j • Compare nums[j] with nums[i] • If different → move i forward and update value • Return i + 1 as the count of unique elements 🎯 Takeaway: Understanding problem constraints (like sorted input) can lead to more efficient and elegant solutions. ⏱ Complexity: • Time → O(n) • Space → O(1) 💻 Example: Input → [1, 1, 2] Output → 2 (Array becomes [1, 2, _]) Input → [0,0,1,1,1,2,2,3,3,4] Output → 5 (Array becomes [0,1,2,3,4,_,_,_,_,_]) Efficiency isn’t always about doing more — sometimes it’s about doing less, smarter 🚀 #ProblemSolving #LeetCode #TwoPointers #CodingJourney #100DaysOfCode #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 10 — Check if Array is Sorted and Rotated Continuing my journey of improving problem-solving skills with consistency and discipline — one problem every day. Today’s challenge was interesting — combining sorting logic with rotation detection. 🧩 Problem Solved: • Check if Array Is Sorted and Rotated (LeetCode #1752) 📚 Topic: Arrays + Circular Traversal 💡 Key Insight: In a sorted and rotated array, there will be at most one point where the order breaks (i.e., where nums[i] > nums[i+1]). ⚡ Approach: • Traverse the array • Compare each element with the next (circularly) • Count how many times the order is violated • If violations > 1 → return False • Otherwise → return True 🎯 Takeaway: Thinking in a circular way helps solve problems involving rotations efficiently. ⏱ Complexity: • Time → O(n) • Space → O(1) 💻 Example: Input → [3, 4, 5, 1, 2] → Output → True Input → [2, 1, 3, 4] → Output → False Sometimes shifting perspective (literally!) makes problems easier to solve 🚀 #ProblemSolving #Arrays #LeetCode #CodingJourney #100DaysOfCode #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 79 on LeetCode Smallest Index With Digit Sum Equal to Index 🔢✅ Keeping the streak going with a simple yet interesting digit manipulation + simulation problem 💯 🔹 Approach Used in My Solution The goal was to find the smallest index i such that the sum of digits of nums[i] equals i. Key idea: • Traverse the array from left to right • For each element, calculate the digit sum • Compare it with the current index • Return the first index where the condition satisfies • If none found → return -1 A clean and direct implementation without overcomplication. ⚡ Complexity: • Time Complexity: O(n * d) (d = number of digits) • Space Complexity: O(1) 💡 Key Takeaways: • Practiced digit extraction using modulo and division • Reinforced writing simple simulation-based solutions • Reminder: not every problem needs optimization — clarity matters 🔥 Consistency maintained, step by step progress continues. #LeetCode #DSA #Algorithms #DataStructures #Arrays #Math #Simulation #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 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 43 of #GeekStreak60 Today’s problem: Painting the Fence (DP) 🎨 Solved a classic Dynamic Programming problem where the goal was to count the number of ways to paint "n" fence posts using "k" colors such that no more than two consecutive posts have the same color. 💡 Learning Takeaway: This problem helped me understand how to break a complex constraint into manageable states. By dividing the problem into two cases — when the last two posts have the same color and when they are different — I was able to build a recurrence relation. It reinforced the idea that many DP problems are about identifying patterns in choices and transitions rather than brute forcing all combinations. ✅ Key Benefits: • Strengthened my understanding of state transitions in DP • Learned how to optimize space by avoiding unnecessary arrays • Improved ability to convert real-world constraints into recurrence relations 📈 Consistency is the real game changer. Showing up daily builds clarity and confidence. 🔥 Current Streak: 43 Days Let’s keep pushing — one problem at a time 💪 #GeekStreak60 #Day43 #DataStructures #Algorithms #DynamicProgramming #CodingJourney #Consistency #PlacementPrep
To view or add a comment, sign in
-
-
📌 Strengthening DSA Concepts through Problem Solving Recently, I worked on LeetCode 42 – Trapping Rain Water At first glance, it looks like a simple array problem… but the challenge? Figuring out how water actually accumulates between heights 🌧️ 🔍 Problem You’re given an array representing elevation heights: 👉 Each bar has width = 1 👉 After raining, calculate how much water gets trapped Rules: ➡️ Water can only be trapped between taller bars ➡️ You need to calculate total accumulated water ➡️ Return the total units of trapped water 🧠 Naive Thinking → For every element, check left max and right max But this leads to: ❌ Time complexity O(n²) ❌ Repeated calculations 💡 Optimized Approach (Two-Pointer Technique) 👉 Use two pointers (left & right) 👉 Track leftMax and rightMax while traversing 👉 Move the pointer with smaller height 🔑 Key Idea 1️⃣ Water depends on the smaller boundary (min of leftMax & rightMax) 2️⃣ If left height is smaller → process left side 3️⃣ If right height is smaller → process right side 👉 Pattern: Two Pointers + Greedy Decision 🚀 Why this is powerful 👉 Reduces time complexity to O(n) 👉 Eliminates need for extra arrays 👉 Efficient single-pass solution ⚙️ Important Concepts ✔️ Two-pointer technique ✔️ Greedy decision ✔️ Prefix max / suffix max intuition ✔️ Space optimization ⏱️ Complexity 👉 Time Complexity: O(n) 👉 Space Complexity: O(1) #DSA #Arrays #TwoPointers #LeetCode #CodingInterview #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
🚀 Day 14 — Max Consecutive Ones Continuing my journey of improving problem-solving skills with consistency and discipline — one problem every day. Today’s problem was about identifying patterns in sequences — simple logic, but very useful in many real-world scenarios. 🧩 Problem Solved: • Max Consecutive Ones (LeetCode #485) 📚 Topic: Arrays + Traversal 💡 Key Insight: We can track consecutive 1’s using a counter and reset it whenever we encounter a 0 — keeping track of the maximum along the way. ⚡ Approach: • Initialize count = 0 and max_count = 0 • Traverse the array • If element is 1 → increment count • Update max_count • If element is 0 → reset count to 0 • Return max_count 🎯 Takeaway: Tracking patterns during traversal is a powerful technique for solving sequence-based problems. ⏱ Complexity: • Time → O(n) • Space → O(1) 💻 Example: Input → [1,1,0,1,1,1] → Output → 3 Input → [1,0,1,1,0,1] → Output → 2 Small patterns reveal big insights 🚀 #ProblemSolving #LeetCode #Arrays #CodingJourney #100DaysOfCode #Consistency #LearningInPublic
To view or add a comment, sign in
-
Explore related topics
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