Day 18 of my LeetCode Journey: Problem: Search in a 2D Matrix Approach: Started from the top-right corner of the matrix. At each step: If the value is greater than target → move left If smaller → move down If equal → found the target This works because rows and columns are both sorted, allowing us to eliminate one row or column at every step. Time Complexity: O(m + n) Space Complexity: O(1) Key insight: Using matrix properties smartly can avoid unnecessary binary searches. Using matrix properties smartly can avoid unnecessary binary searches. On to Day 19 💪 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #1001DaysOfCode
Search 2D Matrix with LeetCode
More Relevant Posts
-
🚀 Day 147 | Frequency Counting Across Multiple Strings Today’s problem was a clean exercise in comparing character frequencies across multiple inputs. 🧩 Problem Solved: 1002. Find Common Characters 🔍 Approach: • Initialized a frequency array using the first word. • For each subsequent word, counted character frequencies and kept the minimum count for each character. • Constructed the result by adding each character as many times as its final minimum frequency. ✨ Key Insight: Using minimum frequency across all strings ensures only truly common characters are included. 📚 Topics: Hashing · Strings · Frequency Counting 💻 Platform: LeetCode #LeetCode #DSA #ProblemSolving #DailyCoding #Strings #Hashing #Java #Consistency
To view or add a comment, sign in
-
-
🚀 Day 13 of #100DaysOfCode – Binary Search in Action-Today I solved LeetCode 1283: Find the Smallest Divisor Given a Threshold and it was a great example of how Binary Search can be applied beyond sorted arrays. 👉 This monotonic behavior makes the problem perfect for Binary Search. ⏱️ Complexity Time: O(n log max(nums)) Space: O(1) 📌 Key Takeaway Binary Search isn’t just for sorted arrays — 👉 If the answer space is monotonic, Binary Search can optimize it efficiently. #100DaysOfCode #Day12 #BinarySearch #LeetCode #Java #DSA #ProblemSolving #CodingJourney 💻✨
To view or add a comment, sign in
-
-
Day 42 — LeetCode 215 | Kth Largest Element in an Array (Java) Solved the problem using a Min Heap (PriorityQueue) instead of sorting. Why? Because sorting works, but it’s not optimal. 🔹 Took user input for array size, elements, and k 🔹 Maintained a heap of size k 🔹 Returned the kth largest element efficiently Complexity matters: • Time — O(n log k) • Space — O(k) This approach scales better and is closer to what interviewers expect when they say “optimize your solution.” Building problem-solving depth one question at a time. 🚀 #DSA #Java #LeetCode #PriorityQueue #Heap #DataStructureAndAlgorithm #ProblemSolving #CodingJourney #DailyPractice
To view or add a comment, sign in
-
-
🔹 Day 97 – LeetCode Practice 📌 Problem: Divide Array Into Equal Pairs (LeetCode #2206) 📊 Difficulty: Easy 🧠 Problem Overview: You’re given an integer array containing 2n elements. The goal is to check whether the array can be divided into n pairs such that: Every element is used exactly once Both elements in each pair are equal ✅ Approach Used: Sorted the array to bring identical elements together. Traversed the array while counting occurrences of each number. Verified that every number appears an even number of times, ensuring valid pairs. 📈 Submission Results: Status: Accepted ✅ Runtime: 8 ms Memory Usage: 46.94 MB 💡 Reflection: This problem is a great reminder that sorting can simplify pairing logic significantly. Once the array is ordered, validating pairs becomes straightforward and efficient. #LeetCode #ProblemSolving #Arrays #Java #DSA #CodingPractice #Consistency
To view or add a comment, sign in
-
-
Solved LeetCode 4 – Median of Two Sorted Arrays ✅ Yeah, I know. This is a Hard problem and the expected solution is O(log(min(n, m))) using binary search and partitioning. But today, I went with clarity first. I combined both arrays, sorted them, and directly computed the median. 📌 Result? ✔️ All test cases passed ✔️ Correct output ✔️ Clear logic Is it the optimal solution? ❌ Is it a valid one? ✅ And that’s the point. Sometimes the real learning is: Understanding why a brute-force solution works Then understanding why it’s not optimal And only then moving to the complex solution Hard problems aren’t solved in one jump. They’re solved in iterations. Binary search partitioning is next. But today, correctness comes first. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
#Day_64 Problem: Merge Strings Alternately (LeetCode 1768) A classic two-pointer problem that strengthens loop control 🔁 🧠 Insights: • Alternate characters from both strings • Continue appending remaining characters if lengths differ • Loop until both strings are fully processed ⚙️ Approach Used: • Use two indices i and j • Append from word1 and word2 alternately • Handle extra characters gracefully 📌 What this improved: • Two-pointer technique • Loop condition clarity • Writing clean iterative logic ✨ Simple logic, solid fundamentals. #Day63 #MergeStrings #LeetCode #Java #TwoPointers #DSA #DailyCoding
To view or add a comment, sign in
-
-
🚀 Day 22 of #100DaysOfCode Problem: Rearrange Array Elements by Sign Today’s problem was about rearranging an array so that positive and negative numbers appear alternately, while maintaining their relative order. 🔍 Approach I used: Traverse the array once and separate positives and negatives into two arrays. Use two pointers to merge them back alternately into the original array. This keeps the logic simple and easy to understand. 💡 Key Learnings: Breaking a problem into smaller steps makes it easier to solve. Extra space can sometimes simplify implementation and improve clarity. Pointer-based merging is a powerful technique in array problems. ✅ Time & Space Complexity: Time: O(n) Space: O(n) #DSA #Java #Arrays #ProblemSolving #Consistency #LearningEveryDay #100DaysOfCode
To view or add a comment, sign in
-
-
📅 Day 46 of #100DaysOfLeetCode 🧩 Problem: 2054. Two Best Non-Overlapping Events ⚙️ Difficulty: Medium 🚀 What I learned today: How to maximize value by selecting at most two non-overlapping intervals Importance of sorting events by end time to enable efficient lookups Used prefix maximum array to store the best value so far Applied binary search to find the last event that ends before the current one starts Achieved an optimal O(n log n) solution for large constraints 🧠 Key Insight: Instead of checking all pairs, precompute the best past event and combine it smartly using binary search. 💡 Techniques Used: Sorting • Binary Search • Prefix Max • Greedy ⏱ Complexity: Time: O(n log n) Space: O(n) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
Day 6 of #100DaysOfLeetCode 🚀 Today’s challenge was 4Sum — finding all unique quadruplets in an array that add up to a target value. 🔍 Key takeaways: Sorting the array simplifies the problem Using two nested loops + two pointers reduces time complexity Handling duplicates correctly is crucial to avoid repeated results Careful use of data types (like long) prevents overflow issues 💡 Problems like these really reinforce how powerful the two-pointer technique can be when combined with sorting. On to Day 7 — staying consistent and learning one problem at a time 💪 #Day6 #LeetCode #DSA #Java #ProblemSolving #Consistency #CodingJourney
To view or add a comment, sign in
-
-
🔹 Day 91 – LeetCode Practice 📌 Problem: Three Consecutive Odds (LeetCode #1550) 📊 Difficulty: Easy 🧠 Problem Overview: Given an integer array, determine whether there are three consecutive odd numbers appearing next to each other. Return true if such a sequence exists; otherwise, return false. ✅ My Approach: Traversed the array while keeping track of consecutive odd numbers. Increased a counter whenever an odd number appeared and reset it when an even number was found. As soon as the counter reached three, the condition was satisfied. 📈 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) 🚀 Submission Results: Status: Accepted ✅ Runtime: 0 ms (Beats 100%) 🚀 Memory: 44.18 MB (Beats 38.42%) 💡 Reflection: This problem highlights how a simple counter-based logic can efficiently solve pattern-detection tasks. Clean logic and early exits make solutions both fast and readable. #LeetCode #DSA #Java #ProblemSolving #CodingPractice #LearningJourney
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
Good consistency, Keep it going.