🚀 Day 24 of my #100DaysOfCode Journey Today, I solved the LeetCode problem Search in 2D Matrix. Problem Insight: Given a sorted 2D matrix, the goal is to efficiently determine whether a target value exists. Approach: Started from the top-right corner of the matrix If the current element equals target → return true If target is smaller → move left (col--) If target is larger → move down (row++) This works because the matrix is sorted row-wise and column-wise, allowing us to eliminate one row or column at each step. Time Complexity: O(m + n) — linear traversal across rows and columns Takeaway: A smart starting point (top-right corner) can significantly optimize search problems in 2D structures. #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #Matrix
LeetCode Solution: Search in 2D Matrix
More Relevant Posts
-
🚀 Day 37 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Transpose Matrix Problem Insight: Given a matrix, the task is to convert its rows into columns. If no transformation is possible in-place (for non-square matrices), we create a new matrix. Approach: • Identify number of rows and columns • Create a new matrix with reversed dimensions (col × row) • Traverse each element of the original matrix • Place elements by swapping indices → (i, j) becomes (j, i) Time Complexity: • O(m × n) — visiting each element once Space Complexity: • O(m × n) — due to new matrix creation Key Learnings: • Transpose = swapping row and column indices • Dimension handling is crucial to avoid errors • In-place transpose is only possible for square matrices Takeaway: A small change in indexing can completely transform how we view and solve a problem. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #Matrix
To view or add a comment, sign in
-
-
🚀 Day 26/100 Days of #CodeChallenge Today’s problem: Isomorphic Strings (Leetcode 205) This problem helped me understand how to map characters between two strings while maintaining consistency and order. 💡 Key Concept: Two strings are isomorphic if characters in one string can be replaced to get the other string — with: ✔️ One-to-one mapping ✔️ No two characters mapping to the same character ✔️ Order preserved 🧠 What I Learned: How to use mapping (arrays/hashmaps) efficiently Importance of bidirectional checking Handling edge cases like unequal lengths ⚡ Approach: Compare lengths first Track character mappings using arrays Ensure consistency in both directions ⏱️ Complexity Analysis: Time Complexity: O(n) → We traverse the strings once Space Complexity: O(1) → Fixed-size arrays (256 characters) ✅ Successfully solved and understood the logic! Every day is a step closer to mastering problem-solving 💪 #Day26 #100DaysOfCode #Java #DSA #LeetCode #CodingJourney #ProblemSolving #TechLearning
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
-
-
📘 DSA Journey — Day 19 Today’s focus: Sliding Window with uniqueness and distance constraints. Problems solved: • Minimum Consecutive Cards to Pick Up (LeetCode 2260) • Substrings of Size Three with Distinct Characters (LeetCode 1876) Concepts used: • Sliding Window / Two-pointer technique • HashMap / Set for tracking duplicates • Window size and distance calculation Key takeaway: In Minimum Consecutive Cards to Pick Up, the goal is to find the smallest subarray containing duplicate elements. A HashMap is used to store the last index of each card. When a duplicate is found, we calculate the distance between indices and update the minimum length. In Substrings of Size Three with Distinct Characters, a fixed-size sliding window (size = 3) is used. We check whether all characters in the window are distinct using a set or frequency array, and count such valid substrings. Both problems highlight how tracking element positions or uniqueness helps efficiently solve problems involving constraints on subarrays or substrings. Continuing to strengthen sliding window patterns and consistency in problem solving. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 33 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Product of Array Except Self Problem Insight: Given an array, return a new array where each element is the product of all other elements except itself, without using division. Approach: • Used prefix (left) product to store multiplication of previous elements • Traversed from right to calculate suffix product • Combined both to get the final answer • Handled cases with zeros without using division Time Complexity: • O(n) Space Complexity: • O(1) (excluding output array) Key Learnings: • Prefix and suffix technique is very useful • Avoiding division helps handle edge cases • Practice improves problem-solving skills Takeaway: Simple patterns like prefix and suffix can solve complex problems easily with practice. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
#Day357 of #1001DaysOfCode LeetCode Daily Challenge Problem: Decode the Slanted Ciphertext (LeetCode 2075) 💡 Approach: The encoded string represents a matrix filled row-wise. I traversed the matrix diagonally (top-left to bottom-right) by converting 2D indices into a 1D string index. Finally, removed trailing spaces to get the correct decoded message. (*you can use inbuilt .stripTrailing() function as well) ⏱ Time Complexity: O(n) 🧠 Space Complexity: O(n) Staying consistent with daily problem solving 🚀 #DSA #Java #LeetCode #ProblemSolving #Coding
To view or add a comment, sign in
-
-
🚀 Day 25 of my #100DaysOfCode Journey Today, I solved the LeetCode problem Valid Perfect Square. Problem Insight: Given a positive integer, the task is to determine whether it is a perfect square without using built-in functions like sqrt(). Approach: Used Binary Search to efficiently find whether a number has an integer square root. Initialized search range from 0 to num Calculated mid and checked mid * mid If equal → return true If square is smaller → move right (low = mid + 1) If square is larger → move left (high = mid - 1) Used long for multiplication to avoid overflow issues. Time Complexity: O(log n) — efficient binary search approach Takeaway: Binary Search is not just for arrays — it can be applied to mathematical problems to optimize performance and avoid brute force. #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #BinarySearch
To view or add a comment, sign in
-
-
🚀 Day 48 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sort Array By Parity Problem Insight: Rearrange the array so that all even numbers come before odd numbers. The order of elements doesn’t matter. Approach: • Used the two-pointer technique (partition logic) • Maintained a pointer j to track the position for even numbers • Traversed the array using i • Whenever an even number is found, swapped it with index j and incremented j • This ensures all even elements move to the front in a single pass Time Complexity: O(n) Space Complexity: O(1) (in-place solution) Key Learnings: • Two-pointer technique is very useful for array partitioning problems • Swapping helps avoid extra space usage • This pattern is similar to problems like moving zeros or segregating positives/negatives Takeaway: Simple logic + optimal approach = clean and efficient solution. Consistency is making these patterns easier to recognize! #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 31 of #LeetCode Challenge 🔍 Problem: Decode the Slanted Ciphertext Today’s problem was all about understanding patterns and matrix traversal in a clever way! 💡 Key Idea: * The encoded string is formed by writing characters in a matrix row-wise * The trick is to read diagonally (↘️ direction) to decode the original message * No need to build a 2D matrix — we can directly calculate indices! 🧠 What I Learned: * How to convert 1D string into virtual 2D matrix * Diagonal traversal techniques * Importance of trimming trailing spaces in string problems ⚡️ Approach: * Calculate number of columns → cols = n / rows * Traverse diagonally from each column * Append characters using index formula i * cols + j * Remove extra spaces at the end 💻 Language: Java 🎯 Time Complexity: O(n) 📦 Space Complexity: O(n) Consistency is the key 🔑 — one problem at a time, getting better every day! #Day31 #LeetCode #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
𝐖𝐡𝐲 𝐝𝐨𝐞𝐬 𝐯𝐚𝐫 𝒂 = "𝒈𝒍𝒐𝒃𝒂𝒍" 𝐬𝐨𝐦𝐞𝐭𝐢𝐦𝐞𝐬 𝐬𝐭𝐚𝐲 𝐠𝐥𝐨𝐛𝐚𝐥? I just finished the "Resolving and Binding" chapter of 𝐂𝐫𝐚𝐟𝐭𝐢𝐧𝐠 𝐈𝐧𝐭𝐞𝐫𝐩𝐫𝐞𝐭𝐞𝐫𝐬, and it completely changed how I look at variable scope. In a basic interpreter, functions can get "confused" if a local variable is declared after the function is defined. To fix this, I implemented a 𝐬𝐞𝐦𝐚𝐧𝐭𝐢𝐜 𝐚𝐧𝐚𝐥𝐲𝐬𝐢𝐬 𝐩𝐚𝐬𝐬 (The Resolver). 𝐓𝐡𝐞 𝐜𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞: Ensuring a function "remembers" exactly where its variables lived at the moment it was born, regardless of what happens in the environment later. 𝐖𝐡𝐚𝐭 𝐈 𝐛𝐮𝐢𝐥𝐭: • A standalone 𝐑𝐞𝐬𝐨𝐥𝐯𝐞𝐫 pass that walks the AST. • Implemented 𝐥𝐞𝐱𝐢𝐜𝐚𝐥 𝐬𝐡𝐚𝐝𝐨𝐰𝐢𝐧𝐠 rules. • Mapped variable access to specific "scope distances" to prevent dynamic lookup bugs. It’s one thing to use a language, but building one from scratch makes you appreciate the invisible logic that keeps our code predictable. #CompSci #CraftingInterpreters #ProgrammingLanguages #SoftwareEngineering #Java #CodingJourney
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