🚀 Day 87/100: #LeetCodeChallenge 📌 Problem: Minimum Swaps to Arrange a Binary Grid Today’s challenge was all about optimizing space and time — and it paid off! 🎯 I tackled the problem by first counting trailing zeros in each row, then simulating the minimum number of adjacent swaps required to bring rows with enough trailing zeros to the top. ✅ Runtime: 2 ms (Beats 96.23%) ✅ Memory: 49.54 MB (Beats 73.13%) 📈 Key Insight: The core idea is to ensure that for each row i (0-based from top), it must have at least n - i - 1 trailing zeros. By precomputing trailing zero counts and swapping rows upward as needed, we can achieve the target configuration with minimal swaps. 💡 Takeaway: Breaking down the problem into smaller subproblems — like counting zeros first and then swapping — helped simplify the logic and optimize performance. On to the next! 🔥 #100DaysOfCode #CodingJourney #Java #Algorithms #ProblemSolving #Grid #Efficiency #DevCommunity #LeetCode #CodeNewbie #Programming
Minimum Swaps to Arrange Binary Grid
More Relevant Posts
-
🚀Day 39 #LeetCode 199 – Binary Tree Right Side View Ever wondered what a binary tree looks like from the right side? 👀 Let’s break it down! 🧠 Problem Insight When you observe a binary tree from the right, at every level you only see one node — the rightmost node. 👉 So the goal is simple: Capture the last node at each level ⚡ Approach (Level Order Traversal - BFS) ✔ Traverse the tree level by level ✔ At each level, pick the last node ✔ Add it to the result 📊 Complexity ⏱ Time: O(n) 📦 Space: O(n) 🔥 Key Takeaway 👉 Rightmost node at each level = Visible node 💡 Example Input: [1,2,3,null,5,null,4] Output: [1,3,4] 💬 Have you tried solving this using DFS (Right-first traversal)? Drop your approach below! #LeetCode #DataStructures #BinaryTree #CodingInterview #Java #Programming
To view or add a comment, sign in
-
-
🚀 Day 14/100 – #100DaysOfCode Challenge 🔍 Problem Solved: Single Number (LeetCode 136) Today’s problem was about finding the element that appears only once in an array where every other element appears twice. 💡 Key Insight: Used the power of XOR (^) bit manipulation Same numbers cancel out → a ^ a = 0 XOR with 0 gives the number → a ^ 0 = a 👉 By XOR-ing all elements, duplicates vanish, leaving the unique number! ⚡ Approach: Traverse the array once Apply XOR on each element Result = single number ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 🔥 What I Learned: Bit manipulation can simplify problems drastically XOR is super powerful for pairing problems #Day14 #CodingChallenge #Java #DataStructures #Algorithms #BitManipulation #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 13/100 – LeetCode DSA Challenge 🔹 Problem Solved: 238. Product of Array Except Self Today’s problem was a great exercise in array manipulation and optimization. 📌 Problem Summary: Given an array nums, return a new array where each element is the product of all elements except itself. 📊 Example: Input: [1,2,3,4] Output: [24,12,8,6] 💡 What I Learned: How to handle edge cases like zeros in an array Importance of time complexity O(n) Why some solutions (like division) are not always valid Concept of prefix & suffix products (optimal approach) ⚠️ Challenge: Cannot use division Must solve in linear time 🧠 My Approach: First tried using total product and division Faced issues with zero values (division by zero error) Improved the logic by handling zero cases carefully 🔥 Key Insight: If there is: More than 1 zero → all outputs = 0 Exactly 1 zero → only that index gets product No zero → normal calculation works 📈 Next Goal: Learn and implement the optimal solution without division (prefix + suffix method) #Day13 #100DaysOfCode #LeetCode #DSA #Java #CodingJourney #ProblemSolving #FutureDeveloper
To view or add a comment, sign in
-
-
🚀 Day 61/100 – LeetCode Challenge ✅ Solved: 125. Valid Palindrome Today’s problem was all about string manipulation + two-pointer technique. 🔍 Approach: Ignored all non-alphanumeric characters Converted characters to lowercase Used two pointers (left & right) to compare characters If mismatch → not a palindrome 💡 Key Learning: Instead of creating a new string, using the two-pointer approach helps achieve O(1) space complexity, making the solution more efficient. ⚡ Performance: Runtime: 2 ms (Beats 99.35%) Memory: 44 MB 🔥 Small problem, but a great reminder that clean logic + optimization matters! #Day61 #LeetCode #100DaysOfCode #Java #CodingJourney #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 50 / 100 – LeetCode Challenge Solved 108. Convert Sorted Array to Binary Search Tree 🌳 Today’s problem was all about building a height-balanced BST from a sorted array using a smart approach. 💡 Key Insight: Instead of inserting elements one by one, pick the middle element as root. This ensures the tree remains balanced. 🔁 Approach: Choose middle element → Root Left half → Left subtree Right half → Right subtree Apply recursively (Divide & Conquer) 🧠 Why it works? Because the array is sorted, the middle element naturally divides values into left < root < right. ⚡ Complexity: Time: O(n) Space: O(log n) ✅ Result: Accepted | 0 ms runtime | 100% performance Consistency is the real win here 💪 Halfway through the challenge! #Day50 #LeetCode #100DaysOfCode #Java #CodingJourney #DSA #BinaryTree #TechGrowth
To view or add a comment, sign in
-
-
Day 50/75 — Climbing Stairs Today’s problem was a classic dynamic programming question — counting the number of distinct ways to reach the top. Approach: • Recognize it as a Fibonacci pattern • Each step = sum of previous two steps • Optimize space using two variables instead of an array Key logic: int current = prev1 + prev2; prev2 = prev1; prev1 = current; Time Complexity: O(n) Space Complexity: O(1) A fundamental problem that builds strong intuition for DP and recurrence relations. Halfway there — consistency paying off 🔥 50/75 🚀 #Day50 #DSA #DynamicProgramming #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 10 of LeetCode Today I tackled one of the classic dynamic programming challenges — Regular Expression Matching. The problem involves matching a string with a pattern that includes: matches any single character matches zero or more of the preceding element Approach: Built a 2D DP table where dp[i][j] represents whether substring s[0..i-1] matches p[0..j-1] Carefully handled * with two cases: Zero occurrence One or more occurrences Initialized edge cases for patterns like a*, a*b* Result: Accepted with optimal performance! This problem really strengthens understanding of: Pattern matching DP state transitions Edge case handling Consistency is key — one hard problem at a time #LeetCode #DataStructures #Algorithms #DynamicProgramming #Java #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 82: Navigating Negative Products 📉 Problem 1594: Maximum Non-Negative Product in a Matrix Today’s challenge was a classic Dynamic Programming problem with a twist: negative numbers. In multiplication, two negatives make a positive, which means the "worst" path could suddenly become the "best" one. The Strategy: • Dual DP Tables: Maintained both a max and a min DP table. Why? Because a very small negative number multiplied by another negative can result in a massive positive. • Path Dependency: For every cell, I tracked four potential products (from the top and from the left, using both previous max and min values). • The Result: Finalized the maximum non-negative product at the bottom-right corner, applying the modulo as required. This problem is a great reminder that DP isn't always about just finding the "local max." Sometimes, you have to keep track of the extremes to catch those unexpected flips. 🚀 #LeetCode #Java #DynamicProgramming #Algorithms #DailyCode
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟓𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding the maximum product subarray. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Maximum Product Subarray 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 • Tracked two values at each step: • Current maximum product • Current minimum product • Why both? • A negative number can turn a small product into a large one • For each element: • Calculated new max and min using previous values • Updated the result with the maximum product found 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Negative numbers can flip the result completely • Tracking both max and min is crucial • DP can be optimized using variables instead of arrays • Edge cases (like zero) reset the product 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Sometimes the minimum value is just as important as the maximum — because it might become the next maximum. 53 days consistent 🚀 On to Day 54. #DSA #Arrays #DynamicProgramming #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 82 - LeetCode Journey 🚀 Solved LeetCode 92: Reverse Linked List II (Medium) — a powerful problem that takes basic reversal to the next level. We already know how to reverse an entire linked list. But here, the challenge is to reverse only a specific portion — between positions left and right — while keeping the rest intact. 💡 Core Idea (Partial Reversal + Pointer Rewiring): Use a dummy node to simplify edge cases Move a pointer (prev) to the node just before position left Start reversing nodes one by one within the given range Reconnect the reversed sublist back to the original list This is done using in-place pointer manipulation. 🤯 Why it works? Because instead of reversing the entire list, we carefully rewire only the required segment, preserving connections before and after the range. ⚡ Key Learning Points: • Partial reversal of linked list • Advanced pointer manipulation • Importance of dummy node in edge cases • In-place modification without extra space • Maintaining O(n) time and O(1) space This problem is a big step up from basic linked list reversal. Also, this pattern connects with: Reverse Linked List (full reversal) Reverse Nodes in k-Group Reorder List Palindrome Linked List ✅ Better control over pointer operations ✅ Strong understanding of in-place transformations ✅ Confidence with medium-level linked list problems From full reversal to selective reversal — this is real progress 🚀 #LeetCode #DSA #Java #LinkedList #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
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