Day 26 of DSA Journey: Stack, String Compression, and Prefix Matching

🚀 Day 26 of my DSA Journey (LeetCode + Java) Today’s practice covered Stack, Two-Pointer string processing, and Prefix matching. Each problem had a different pattern, so it was a great mixed-learning day! ✅ Problems Solved Today: LC 20 – Valid Parentheses LC 443 – String Compression LC 14 – Longest Common Prefix 🧠 My Experience Solving These: 🔸 20. Valid Parentheses This is a classic stack-based validation problem. My steps: Push opening brackets into stack When closing bracket appears, check top of stack If matching pair → pop Else → return false Finally, if stack is empty → parentheses are valid. A very clean and logical stack problem. 🔸 443. String Compression This problem was interesting because it relies on two-pointer string traversal. Here’s how I solved it: Use one pointer to scan the string Count how many times a character repeats Write the character + its count into the main array Maintain a separate write index It’s an optimized in-place solution, and understanding the pointer movement is the key. 🔸 14. Longest Common Prefix A very popular string problem. My approach: Take the first string as the initial prefix Compare it with every next string Trim the prefix whenever mismatch occurs Continue until the shortest valid prefix remains Simple logic but very important technique for prefix-matching problems. 📌 Key Takeaway Today: Working on mixed patterns like Stack, String Compression, and Prefix Matching helps build versatility. ✔ Stack is perfect for matching pairs ✔ Two-pointer technique makes string processing efficient ✔ Prefix trimming is a powerful string strategy Every day I’m building stronger intuition toward string and stack problems. On to Day 27! 🚀 #DSA #LeetCode #Java #SlidingWindow #ProblemSolving #CodingJourney #Consistency #LearningDaily

To view or add a comment, sign in

Explore content categories