🚀 Day 49/100 – #100DaysOfDSA Today’s problem was Search a 2D Matrix II, a classic that tests how well you can leverage sorted data for efficient searching. 🔍 Key Idea: The matrix is sorted: Rows → left to right Columns → top to bottom Instead of scanning everything, I used an optimized approach starting from the top-right corner. ⚡ Approach: Start at top-right element If current > target → move left If current < target → move down Repeat until found or out of bounds 🚀 Performance: ⏱️ Time Complexity: O(m + n) 💾 Space Complexity: O(1) ✅ Accepted with strong performance (~97% beats) 💡 What I learned: How sorted properties can eliminate large search spaces The power of directional traversal in matrices Thinking beyond brute force leads to elegant solutions 💭 Reflection: This problem is a great reminder that sometimes the best solution isn’t about doing more—it’s about moving smarter. Consistency continues 💪🔥 #DSA #100DaysOfCode #Matrices #ProblemSolving #CodingJourney
Optimized Search in Sorted 2D Matrix II
More Relevant Posts
-
Day 71 and 72 of Mastering Data Structures and Algorithms 🚀 Over the past 2 days, I focused mainly on revisiting Sliding Window, Two Pointers, and Hashing based problems. 🔹 Two Pointers + Sliding Window 1. Longest Substring Without Repeating Characters 2. Longest Repeating Character Replacement 3. Binary Subarrays With Sum I revisited Longest Repeating Character Replacement because I hadn’t fully understood the intuition earlier, especially around: - Maintaining the window condition - Tracking the maximum frequency character - Understanding why the window can still remain valid even without recalculating frequencies every time. Going through it again helped me better understand how sliding window problems often depend more on maintaining constraints efficiently rather than checking every subarray explicitly. 🔹 Hashing 1. Largest Subarray With Sum 0 2. Subarray Sum Equals K These problems reinforced the importance of: - Prefix sums - HashMap-based frequency tracking - Converting brute-force O(n²) solutions into O(n) One interesting observation was how similar-looking subarray problems can have completely different edge cases depending on whether: elements are positive only, binary,or include negative values. Currently continuing revision of previously solved topics while trying to improve understanding of problem patterns rather than only memorizing approaches. #DSA #Graphs #BinarySearch #ProblemSolving #Algorithms #LearningInPublic #Consistency #SoftwareEngineering #SoftwareDevelopment #Stacks #StriversatoZDSA
To view or add a comment, sign in
-
-
🚀 Blind 75 Journey Update – Phase 3 Completed (Sliding Window) I’ve successfully completed Phase 2: Two Pointers, and now I’ve moved through one of the most important interview patterns in DSA: 🔹 Phase 3 – Sliding Window (Completed) Problems covered: 1️⃣1️⃣ Longest Substring Without Repeating Characters (3) 1️⃣2️⃣ Longest Repeating Character Replacement (424) 1️⃣3️⃣ Minimum Window Substring (76) 💡 What I learned in this phase: This phase strengthened my understanding of one of the most powerful optimization techniques in arrays & strings: • Dynamic window expansion and contraction • Frequency tracking using HashMap / arrays • Maintaining optimal subarray/subsequence constraints • Handling real-time updates efficiently • Converting brute-force O(n²) → optimized O(n) solutions 🧠 Key Insight Sliding Window is not just a pattern — it's a mindset: Instead of recomputing, reuse previous computation while expanding and shrinking intelligently. It’s heavily used in: String processing problems Subarray optimization Streaming / real-time data problems 🎯 My Focus Moving Forward I’m continuing the Blind 75 journey in strict chronological order, focusing on: ✔ Pattern understanding before memorization ✔ Writing approach before coding ✔ Improving time & space optimization intuition ✔ Building strong DSA fundamentals step by step 🚀 Next Phase Coming Up: 🔹 Continuing Blind 75 with next patterns (Stack / Binary Search / Linked List depending on order) Consistency over speed. Depth over shortcuts. #Blind75 #SlidingWindow #DataStructures #Algorithms #LeetCode #CodingJourney #SoftwareEngineering #ProblemSolving #BuildInPublic #InterviewPreparation
To view or add a comment, sign in
-
Day 9 of #100DaysOfCode 🚀 Solved the Mother Vertex problem in a Directed Graph using DFS. Problem Statement 📌 Given a directed graph, find a vertex from which all other vertices can be reached. If multiple mother vertices exist, return the smallest one. Solution Approach 💡 Instead of starting DFS from every vertex (which would be inefficient), we use an optimized approach: 1️⃣ Perform DFS traversal for all unvisited nodes. 2️⃣ The vertex that finishes last in DFS becomes a potential mother vertex. 3️⃣ Run DFS again from this candidate to verify whether all vertices are reachable. 4️⃣ If all nodes are visited, it is a valid mother vertex; otherwise return -1. Why Does This Work? 🤔 In a directed graph, if a mother vertex exists, then the last completed vertex during DFS traversal will always be one possible mother vertex. Complexity ⚡ Time Complexity: O(V + E) Auxiliary Space: O(V) What I Learned 📚 DFS finishing order has powerful applications in graph problems. Verification steps are important even after finding a strong candidate. Efficient graph traversal can significantly reduce brute-force complexity. Consistency + Practice = Improvement 💪 #DSA #Graphs #DFS #Algorithms #Cpp #CodingJourney #ProblemSolving #100DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
Most teams discover this a little late. ⏰ Two weeks before the production pilot, extraction accuracy is stuck at 78%. 📉 The model is fine. The prompts are fine. But, the PDF library is silently destroying signal upstream. 🔇 The fix is not a better model. The fix is a parsing layer that preserves structure. 🏗️ #LLMWhisperer #OCR #DataExtraction #Parser #LayoutPreservingOCR #LLMReadyText #UnstructuredData #PDFParsing #DocumentProcessing #DataPipelines
To view or add a comment, sign in
-
Your RAG grabbed the ten closest chunks and answered from the worst one. The closest vector is not the chunk that actually answers your question. The reason is structural. Vector search embeds the query and every chunk as separate points in space, then returns whatever sits nearest. The query embedding and the document embeddings were produced independently, so nearest is a rough proximity guess, not a relevance judgment. The nearest neighbor can be a confident near-miss. Worked example: a user asks "how do I cancel my plan." The top hit is the signup chunk, because signup and cancel both talk about plans and cluster together in embedding space. A cross-encoder reranker reads the question and one chunk together in a single pass, then scores how well that chunk answers that exact question. The cancel chunk scores eleven, the signup chunk scores three, and they swap. The honest limit: a reranker costs one more model call per query, so you trade a little latency for precision, and it can only reorder what retrieval already surfaced. A chunk that missed the top fifty stays lost. The pattern is two-stage retrieval: pull fifty candidates fast with vector search, rerank the top ten with a cross-encoder before they reach the model. Embeddings for recall, reranker for precision.
To view or add a comment, sign in
-
📌 Solving Tree Boundary Traversal — Strengthening Core DSA Skills Recently, I worked on the Tree Boundary Traversal problem, which requires returning the boundary of a binary tree in a specific order while carefully handling edge cases. At first glance, it looks simple → but maintaining strict traversal order and avoiding duplicate nodes makes it challenging. 🔍 Problem Overview Given the root of a binary tree, return its boundary traversal in this order: → Left Boundary (excluding leaf nodes) → All Leaf Nodes (left to right) → Reverse Right Boundary (excluding leaf nodes) Important constraints: → The root must be included only once → Leaf nodes must be added separately → Right boundary nodes must be added in reverse order 💡 Approach → Add the root to the result (if it is not a leaf) → Traverse the left boundary by preferring the left child; if not available, move to the right child, while excluding leaf nodes → Use DFS to collect all leaf nodes in left-to-right order → Traverse the right boundary, store nodes temporarily, and append them in reverse order while excluding leaf nodes Breaking the problem into separate traversal components ensured correctness and prevented duplication. ⏱ Complexity Analysis → Time Complexity: O(n) → Space Complexity: O(h) Where: → n = number of nodes → h = height of the tree 🚀 Key Takeaways → Structured traversal improves clarity → Separating logic avoids duplication → Edge case handling is critical in tree problems → Modular implementation leads to clean solutions Tree Boundary Traversal reinforces the importance of systematic problem decomposition and precise traversal control. #DSA #BinaryTree #Algorithms #ProblemSolving #CodingJourney #InterviewPreparation
To view or add a comment, sign in
-
Most document parsers see this 👇 on the left. A flat stream of text. Tables collapsed into noise. Charts erased. Images orphaned from their captions. That's what happens when you treat documents as text objects. Parsimmon sees what's on the right. Every document is a multidimensional visual object. Text. Images. Tables. Charts. Page context. Source evidence. Each layer extracted by a specialist model: tables reconstructed cell-by-cell, charts reverse-engineered from pixels back to data, images described with full caption context. The result downstream: → Cleaner chunks → Better embeddings → More accurate indexing → More reliable retrieval If your RAG pipeline is hallucinating numbers or losing the chart that proved the point, the problem probably isn't your model. It's the parser upstream of it. We're building Parsimmon to fix that. Parsimmon Parsimmon.io
To view or add a comment, sign in
-
-
If you think attention is just "weights that tell the model what to focus on," you're in good company. You're also missing the entire point. Here are the three mistakes that kept me debugging transformer implementations for weeks. ⚠️ The usual traps 🚨 Mistake 1: Thinking attention replaces embeddings You're calculating attention over word positions, not the actual semantic content. The query, key, and value matrices are all learned transformations of your embeddings. Without good embeddings feeding in, your attention scores are just fancy noise on garbage. ⚠️ Mistake 2: Ignoring the scaling factor You skip the sqrt(d_k) division because "it's just a constant." Then your softmax saturates, gradients vanish, and your model trains like it's 2015. That scaling isn't optional, it's literally preventing your dot products from exploding as dimensions grow. Use it. 🔧 Mistake 3: Confusing attention scores with what gets output The attention weights are just coefficients. You're still doing a weighted sum of the value vectors. I've seen people try to interpret a 0.8 attention score as "the model understands this token" when really it just means that value vector gets 80% weight in the final representation. 🔑 The one thing to keep Attention is a routing mechanism, not magic. It's matrix multiplication with extra steps and a softmax. Once I stopped treating it like a black box and actually printed out those QK^T matrices at different layers, everything clicked. #AttentionMechanism #TransformerArchitecture #DeepLearning #MachineLearning
To view or add a comment, sign in
-
Days 2 & 3 / 90: Mastering the Pointers. The last 48 hours have been a masterclass in pointer manipulation-specifically, how setting the right boundaries completely eliminates off-by-one errors and edge-case chaos. Here are the two core breakdowns: 1. Controlling Matrix Chaos with 4 Pointers (Day 2) Tackling matrix spiral traversal isn't about complex math; it's about strict spatial boundaries. By tracking 4 simple pointers (top, bottom, left, right), you can cleanly collapse the grid boundaries inward as you traverse: Move left to right along top -> top++ Move top to bottom along right -> right-- Move right to left along bottom -> bottom-- Move bottom to top along left -> left++ The Catch: You must check if your boundaries have crossed after every single direction change, not just at the end of the loop. Missing this breaks the logic instantly on non-square matrices. 2. The Universal Binary Search Template (Day 3) When searching a binary array (all 0s and 1s) for boundary conditions—like the first occurrence of 1-a completely uniform array (e.g., all 0s) usually requires messy internal if/else checks to avoid index errors. The elegant fix? Expand the initial search space to virtual boundaries: left = -1 and right = n By letting the pointers sit just outside the array indices, you can reuse a single, standard binary search template. Once the loop terminates: If left >= 0, you safely have your target. If right >= n, the element doesn't exist, handling the uniform edge case natively. Whether you are traversing inward on a 2D grid or expanding boundaries in a 1D array, clean code always comes down to how you manage your invariants. On to Day 4. #DSA #ComputerScience #SoftwareEngineering #ProblemSolving
To view or add a comment, sign in
-
Days 6/ 90: Structuring the Next Phase Took a quick breath to lock in core tree and graph traversals before shifting into higher gear. The technical breakdown: Evaluate Expression Tree: Straightforward post-order traversal (O(N) time / O(h) space). You evaluate the left and right subtrees recursively, then apply the parent node's operator (+, -, *, /) to the results. Closest Value in BST: Handled this iteratively to keep space complexity at O(1) constant instead of O(h) recursion stack frames. By exploiting the BST property, you eliminate half the remaining tree at each step, making it a clean O(log N) average-time operation. DFS on Graphs: Brushed up on standard adjacency list traversals, reinforcing the necessity of a visited set to prevent infinite cycles. The Self-Correction: I’ve noticed a pattern in my execution: I clear top-down structural problems (like expression trees), but bottom-up depth aggregations (like the Node Depths problem from Day 4) require a lot more mental friction. Identifying these blind spots early is exactly why I started this public log. The Strategy Pivot: The roadmap is changing. I’m going into a high-intensity DSA sprint for the next 4 days to completely clear out these structural blind spots. Once June hits, I’ll be balancing the daily DSA grind side-by-side with something new: building out a full-stack, real-time production project from scratch. Time to crank up the velocity. #DSA #ComputerScience #SoftwareEngineering #WebDevelopment
To view or add a comment, sign in
Keep learning 👍