Day 90/100 🚀 | #100DaysOfDSA Solved LeetCode 240 – Search a 2D Matrix II today. Approach: Used the top-right corner traversal (greedy + matrix property). Key observation: • Each row is sorted left → right • Each column is sorted top → bottom So: • Start at top-right corner • If current value > target → move left (col--) • If current value < target → move down (row++) • If equal → found This eliminates one row or column in each step. Time Complexity: O(m + n) Space Complexity: O(1) Key takeaway: For sorted 2D matrices, don’t jump to binary search immediately — sometimes a clever starting point (like top-right) gives a simpler linear solution. #100DaysOfDSA #LeetCode #DSA #Java #Matrix #BinarySearch #Greedy #ProblemSolving #Consistency
Solved LeetCode 240 Search a 2D Matrix II with Top-Right Traversal
More Relevant Posts
-
Day 85/100 🚀 | #100DaysOfDSA Solved LeetCode 300 – Longest Increasing Subsequence (LIS) today. Initially, the brute force / DP approach (O(n²)) is intuitive, but I implemented the optimized O(n log n) solution using Binary Search. Approach (Patience Sorting Idea): Used an array tails[] where: • tails[i] = smallest possible tail of an increasing subsequence of length i+1 For each number: • Used binary search to find its correct position in tails • Replaced the element at that position • If it extends the largest subsequence → increased size ⚠️ Important: tails does NOT store the actual subsequence, but helps compute the length efficiently. Time Complexity: O(n log n) Space Complexity: O(n) Key takeaway: When you see “longest increasing subsequence”, think: • O(n²) → DP • O(n log n) → Binary Search + Greedy (optimal) This is a classic interview problem and a big step up from basic questions — good progress. #100DaysOfDSA #LeetCode #DSA #Java #DynamicProgramming #BinarySearch #Greedy #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
✅ LeetCode Top Interview 150 – Day 94 Today I solved Evaluate Division Key Idea : Model the problem as a graph Each variable is a node, equations form weighted edges Build adjacency list with forward and reciprocal values Use DFS/BFS traversal to find path between variables Multiply edge weights along the path to get result This approach efficiently evaluates division queries using graph traversal #DSA #Java #Leetcode #Day94
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
-
-
🚀 Day 66/100 Solved a problem on String Manipulation — Score of a String. 🔍 Problem Insight: Calculated the total score by summing absolute differences between ASCII values of adjacent characters. 💡 Approach: - Iterated through the string once - Used "Math.abs()" to compute differences - Maintained a running sum ⚡ Complexity: Time: O(n) Space: O(1) ✅ Result: All test cases passed Runtime: 1 ms (Beats 99.77%) 📚 Key Learning: Small optimizations and clean logic can lead to highly efficient solutions. Consistency is the key — showing up every day 💪 #Java #DSA #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 75 of #100DaysOfCode Solved 103. Binary Tree Zigzag Level Order Traversal on LeetCode 🔗 🧠 Key Insight: This is a variation of level order traversal where: 👉 Levels alternate between left → right and right → left ⚙️ Approach (BFS + Direction Toggle): 1️⃣ Use a queue for level order traversal 2️⃣ Maintain a flag (leftToRight or sign) 🔹 true → left → right 🔹 false → right → left 3️⃣ For each level: 🔹 Create a list 🔹 Traverse all nodes in that level 4️⃣ Insert values based on direction: 🔹 If left → right → addLast(val) 🔹 Else → addFirst(val) 5️⃣ Add level list to result 6️⃣ Flip direction: 👉 sign *= -1 or toggle boolean ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) #100DaysOfCode #LeetCode #DSA #BinaryTree #BFS #Queue #Java #InterviewPrep #CodingJourney
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 23/100 — #100DaysOfLeetCode Another challenging day — pushing deeper into advanced Sliding Window problems 💻🔥 ✅ Problem Solved: 🔹 LeetCode 76 — Minimum Window Substring 💡 Concepts Used: Sliding Window HashMap Frequency Counting Two Pointer Optimization 🧠 Key Learning: The goal was to find the smallest substring containing all characters of another string. Key approach: Expand the window until all required characters are included. Track character frequencies carefully. Shrink the window while maintaining validity to get the minimum length. ⚡ Big Insight: Sliding Window isn’t only about longest substrings — it can also efficiently solve minimum window optimization problems. This problem really tested attention to detail and window management logic. Consistency is turning difficult problems into enjoyable challenges 🚀 #100DaysOfLeetCode #LeetCode #DSA #SlidingWindow #Algorithms #Java #ProblemSolving #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 3 of #LeetCodeDailyChallenge Showing up daily, even when the problem pushes me out of my comfort zone. Today’s problem: Longest Substring Without Repeating Characters 📌 Topic: Sliding Window, HashMap ⚡ Difficulty: Medium What I learned today: How the sliding window technique optimizes substring problems Using a HashMap to track last seen positions of characters Adjusting the window smartly to avoid rechecking elements Thinking in terms of O(n) optimization instead of brute force This one really changed how I approach string problems — from checking everything to working smarter with patterns. #DSA #LeetCode #Java #SlidingWindow #ProblemSolving #LearningInPublic #Consistency
To view or add a comment, sign in
-
✅ LeetCode Top Interview 150 – Day 96 Today I solved Construct Quad Tree Key Idea : Use Divide and Conquer (Recursion) Check if current grid is uniform (all 0’s or all 1’s) If yes → create a leaf node Else → divide grid into 4 quadrants Recursively build Quad Tree for each quadrant This approach efficiently represents the grid using hierarchical decomposition #DSA #Java #Leetcode #Day96
To view or add a comment, sign in
-
-
🔄 Solved “Spiral Matrix”, a classic matrix traversal problem using boundary-based approach. ✦ What This Problem Taught Me: • How to traverse a 2D matrix layer by layer using boundaries • Effective use of four pointers (top, bottom, left, right) • Managing direction-based traversal (→ ↓ ← ↑) • Importance of shrinking boundaries after each iteration • Avoiding duplicate traversals using proper conditions • Strengthened understanding of 2D arrays and indexing 🚀 Problems like this show how controlling boundaries and direction can simplify complex matrix traversals into a clean O(m × n) solution. On to solving more matrix and pattern-based problems 💪🔥 #LeetCode #DSA #Matrix #TwoPointers #CodingJourney #ProblemSolving #Java #100DaysOfCode
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