🚀 Day 8/100 — #100DaysOfLeetCode Another day, another concept unlocked 💻🔥 ✅ Problem Solved: 🔹 LeetCode 73 — Set Matrix Zeroes 💡 Problem Idea: If any element in a matrix is 0, its entire row and column must be converted to 0 — and the challenge is to do this in-place without using extra space. 🧠 Algorithm & Tricks Learned: Instead of using extra arrays, we can use the first row and first column as markers. First pass → mark rows and columns that should become zero. Second pass → update the matrix based on those markers. Carefully handle the first row and first column separately to avoid losing information. ⚡ Key Insight: The matrix itself can act as storage, reducing extra memory usage. 📊 Complexity Analysis: Time Complexity: O(m × n) → traverse matrix twice Space Complexity: O(1) → solved in-place without extra data structures This problem taught me how small optimizations can significantly improve space efficiency. Learning to think beyond brute force every day 🚀 #100DaysOfLeetCode #LeetCode #DSA #MatrixProblems #Algorithms #Java #ProblemSolving #CodingJourney #LearningInPublic
LeetCode 73 Set Matrix Zeroes in-place without extra space
More Relevant Posts
-
🚀 Day 55 of #100DaysOfCode – Rotate Image Today I worked on an interesting matrix problem: Rotate Image (90° clockwise) 🔄 💡 Key Learning: Instead of using extra space, the challenge is to rotate the matrix in-place. 🧠 Approach I used: 1️⃣ Transpose the matrix (convert rows → columns) 2️⃣ Reverse each row This combination effectively rotates the matrix by 90° clockwise without using extra memory. 📌 Example: Input: [[1,2,3], [4,5,6], [7,8,9]] Output: [[7,4,1], [8,5,2], [9,6,3]] ⚡ Complexity: Time: O(n²) Space: O(1) (in-place) 💻 Implemented in Java and successfully passed all test cases ✅ This problem really helped me strengthen my understanding of matrix manipulation and in-place algorithms. #LeetCode #DataStructures #Java #CodingPractice #ProblemSolving #Algorithms #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 574 of #750DaysOfCode 🚀 🔍 Problem Solved: Detect Cycles in 2D Grid Today’s problem was a great example of how graph concepts show up in grids 👀 💡 Key Insight: A grid can be treated as a graph where: Each cell = node Adjacent same-value cells = edges 👉 The task is to detect a cycle of same characters with length ≥ 4 🧠 Approach (DFS + Parent Tracking): Traverse each cell Start DFS if not visited While exploring: Move only to same character cells Track previous (parent) cell If we visit an already visited cell (not parent) → ✅ cycle found 📈 Complexity: Time: O(m × n) Space: O(m × n) ✨ Takeaway: 👉 Many grid problems are just graph problems in disguise 👉 Cycle detection becomes easy with DFS + parent tracking Another solid concept added to the toolkit 💪 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #Graphs #DFS #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
💡 Day 64 of LeetCode Problem Solved! 🔧 🌟 2033. Minimum Operations to Make a Uni-Value Grid 🌟 🔗 Solution Code: https://lnkd.in/gts2KBqr 🧠 Approach: • Flattened the 2D grid into a sorted 1D list. • Chose the median as the target value — it minimises total absolute deviation mathematically. • Early-exit with -1 if any element has a different remainder mod x than the median. • Summed |element - median| / x for all elements to get the answer. ⚡ Key Learning: • The median is the optimal target for minimising sum of absolute differences — a powerful mathematical insight that replaces brute-force enumeration entirely. • A simple remainder check handles all impossible cases upfront. ⏱️ Complexity: • Time: O(m·n·log(m·n)) • Space: O(m·n) #LeetCode #Java #DSA #ProblemSolving #Consistency #CodingJourney #Algorithms #Grid
To view or add a comment, sign in
-
-
💡 Day 56 of LeetCode Problem Solved! 🔧 🌟 Mirror of an Integer 🌟 🔗 Solution Code: https://lnkd.in/gvaEY4Sw 🧠 Approach: • Digit Extraction & Reversal Extract digits from right to left using modulo (% 10) and rebuild the reversed number dynamically. • Calculate the absolute difference abs(n - reversed) at the end to find the mirror distance. ⚡ Key Learning: • Mastering number manipulation with fundamental math operators (% and /) is a game-changer for processing integers efficiently without relying on space-consuming String conversions. ⏱️ Complexity: • Time: O(log₁₀(n)) (proportional to the number of digits) • Space: O(1) #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfCode #CodingJourney #MathLogic #DataStructures
To view or add a comment, sign in
-
-
Day 79/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Flatten Binary Tree to Linked List A powerful tree transformation problem using pointer manipulation. Problem idea: Convert a binary tree into a linked list in-place following preorder traversal. Key idea: Iterative traversal + rewiring (similar to Morris traversal idea). Why? • We need preorder sequence (Root → Left → Right) • Instead of extra space, we modify pointers in-place • Efficient and avoids recursion stack How it works: • Traverse using a pointer curr • If left child exists: → Find rightmost node of left subtree → Connect it to current’s right subtree → Move left subtree to right → Set left = null • Move to next node (curr.right) Time Complexity: O(n) Space Complexity: O(1) Big takeaway: Tree problems can often be optimized using in-place pointer rewiring, avoiding extra space. 🔥 This pattern is very useful for tree flattening and traversal optimizations. Day 79 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinaryTree #MorrisTraversal #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
Day 85/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Populating Next Right Pointers in Each Node A clean pointer-manipulation problem that strengthens tree traversal intuition without extra space. Problem idea: Given a perfect binary tree, connect each node to its next right node using a next pointer. Key idea: Level-by-level traversal using already established next pointers (no queue needed). Why? • The tree is perfect → every level is fully filled • We can use existing next links to move horizontally • This avoids extra space (unlike BFS with a queue) How it works: • Start from the leftmost node of each level • Connect left child → right child • If a next node exists, connect right child → next node’s left child • Move across the level using next pointers • Then go down to the next level Time Complexity: O(n) Space Complexity: O(1) Big takeaway: When a tree is perfect, you can often avoid extra space by cleverly using existing structure (like next pointers). 🔥 This is a powerful pattern for constant-space tree traversal problems. Day 85 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinaryTree #Pointers #TreeTraversal #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🚀 Solved LeetCode 2515 – Shortest Distance to Target String in a Circular Array Today I tackled an interesting problem that highlights the importance of handling circular data structures efficiently. 🔍 Problem Insight: Given a circular array of words, a target string, and a starting index, the goal is to find the minimum number of steps required to reach the target by moving either left or right. 💡 Key Learnings: Circular arrays require thinking beyond linear traversal Always consider both directions (forward & backward) Optimizing distance using min(distance, n - distance) is the key trick Simple logic + correct observation = optimal solution ⚙️ Approach Used: Traverse the array to find all occurrences of the target Calculate distance from the starting index Take the minimum considering circular movement 📈 Complexity: Efficient O(n) solution with constant space 🔥 Takeaway: This problem reinforced how small tweaks (like circular behavior) can change the entire approach. A great example of combining logic + observation for clean and optimal solutions. #LeetCode #Algorithms #ProblemSolving #CodingJourney #Java #DataStructures #CompetitiveProgramming
To view or add a comment, sign in
-
-
Day 6 of #100DaysOfLeetCode ✅ Today I solved LeetCode 128 — Longest Consecutive Sequence. 🧩 Problem Summary: Given an unsorted array of integers, the task is to find the length of the longest sequence of consecutive numbers. The challenge is to solve it in O(n) time complexity, which means sorting is not allowed. 💡 Key Learning: Instead of sorting, I used a HashSet for O(1) lookup. The main intuition: 👉 A number starts a sequence only if (num - 1) does NOT exist in the set. Then we expand forward (num + 1) to count the sequence length. ⚡ Concepts Practiced: • HashSet / Hashing • Optimized Searching (O(1) lookup) • Sequence Detection Pattern • Time Complexity Optimization 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) Every day improving problem-solving skills and understanding data structures deeper 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 566 of #750DaysOfCode 🚀 🔍 Problem Solved: Mirror Distance of an Integer Today’s problem was simple but a great reminder of how powerful basic number manipulation can be. 💡 Problem Insight: We define the mirror distance of a number as: 👉 abs(n - reverse(n)) So the task is: Reverse the digits of the number Compute the absolute difference 🧠 Approach: Extract digits using % 10 Build the reversed number Compute absolute difference 📊 Complexity: Time: O(d) → where d = number of digits Space: O(1) 🔥 Key Takeaway: Even the easiest problems reinforce fundamentals like digit extraction, reversal, and absolute difference — building blocks for more complex algorithms. #Day566 #750DaysOfCode #LeetCode #Java #CodingJourney #ProblemSolving #Algorithms #BeginnerFriendly
To view or add a comment, sign in
-
-
Day 45 of Daily DSA 🚀 Solved LeetCode 867: Transpose Matrix ✅ Problem: Given a 2D matrix, return its transpose (rows become columns and columns become rows). Approach: Created a new matrix and swapped indices while traversing. Steps: Get number of rows and columns Create a new matrix of size cols x rows Traverse original matrix Assign: trans[j][i] = matrix[i][j] Return the new matrix ⏱ Complexity: • Time: O(n × m) • Space: O(n × m) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 46.46 MB Simple transformations like transpose build strong fundamentals for matrix-based problems 💡 #DSA #LeetCode #Java #Arrays #Matrix #CodingJourney #ProblemSolving
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