🚀 Day 34 of My DSA Journey – Cracked “Valid Parentheses” on LeetCode! 🔥 Today I solved the classic Valid Parentheses problem, and it turned out to be a great exercise in understanding stack-based logic and order validation. 🧩 Problem Understanding Given a string containing () { } [ ], we need to check: ✔ Every opening bracket has a matching closing bracket ✔ The order of brackets is correct 🐢 Brute Force Thought Initially, you might think of checking counts of brackets… But ❌ this fails for cases like: ([)] → counts match but order is wrong 👉 So, count alone is not enough! ⚡ Optimized Approach (Stack – LIFO) We use a Stack because it follows Last In First Out: Steps: Traverse each character If it's an opening bracket → push to stack If it's a closing bracket: Check if stack is empty → invalid ❌ Pop and compare with expected opening bracket At the end → stack must be empty ✅ 🔍 Example Walkthrough Input: "([{}])" Push ( → [( Push [ → [( [ Push { → [( [ { Match } → pop { Match ] → pop [ Match ) → pop ( 👉 Final stack empty → ✅ Valid ⏱ Complexity Time: O(n) Space: O(n) 💡 Key Learning 👉 Order matters more than count 👉 Always check stack empty before pop 👉 Final validation = stack should be empty 🙏 Gratitude Thanks to my mentors and resources guiding me through DSA 🙌 🔁 Consistency Note Showing up daily and solving even one problem is building my confidence step by step 💪 #DSA #LeetCode #Java #CodingJourney #ProblemSolving #Stack #LearningInPublic #SoftwareEngineering #Consistency
Cracked Valid Parentheses on LeetCode with Stack Logic
More Relevant Posts
-
🚀 Day 20 of My DSA Journey — Cracking “Power of Two” Today I solved the classic problem: Check if a number is a power of 2 on LeetCode. 🔍 Problem Understanding Given an integer n, we need to determine whether it can be represented as: 👉 ( n = 2^x ) where ( x \ge 0 ) 💡 Brute Force Approach Keep multiplying 2 until we reach or exceed n If we hit exactly n, return true ⛔ Not efficient for large values ⚡ Optimized Approach (My Solution) Instead of multiplying, I used a smarter trick: 👉 Keep dividing the number by 2 Steps: If n <= 0 → return false While n > 1 If n % 2 != 0 → not divisible → return false Else divide n by 2 If we reach 1 → return true 🧠 Example Walkthrough Input: n = 8 8 → 4 → 2 → 1 ✅ So, it is a power of 2 Input: n = 10 10 → not divisible cleanly ❌ So, not a power of 2 ⏱ Complexity Analysis Time Complexity: O(log n) Space Complexity: O(1) 🎯 Key Learning Problems that involve repeated division or multiplication often hint toward logarithmic optimization Always think: Can I reduce the number step by step instead of building it? 🙏 Grateful for the consistency and learning every single day 📈 Small steps daily = Big growth over time #DSA #LeetCode #CodingJourney #ProblemSolving #Java #CPP #100DaysOfCode #TechGrowth #Consistency
To view or add a comment, sign in
-
-
Recently wrapped up one of my bigger projects this semester: an Appointment Book Manager in Java. This one pulled together a lot of what I’d been learning in my DSA course all at once: ADTs, iterators, binary search trees, recursion, node removal, and delegation. The timing made it especially meaningful—I was covering recursion and BSTs in both my DSA course (University of Wisconsin-Milwaukee) and CodePath TIP 102, while also attending DSA labs and preparing for technical mock interviews. Writing the code and then walking through my approach out loud forced me to articulate my thinking clearly under pressure and really lock in the concepts. A huge thank you to CodePath and to my DSA professor John Boyland for their continual support and guidance throughout this journey. The combination of both has pushed me further than I expected this semester. What I built: • Implemented a NewApptBook ADT backed by a binary search tree, designing recursive add, remove, and traversal methods from scratch for an efficient sorted collection with O(log n) search performance. • Built a BST iterator with a stack for in-order traversal, a version counter, and a reference to the last returned node, with hasNext(), next(), and remove() implemented with version tracking and a custom invariant checker. The iterator keeps track of position as the tree structure shifts so traversal stays consistent and controlled. • Added version tracking and invariants so any structural modification mid-iteration throws a ConcurrentModificationException instead of silently producing wrong outputs—fail fast, catch it early, fix it quickly. That mindset of building with both the developer and the end user in mind is something I want to carry into everything I build. • Engineered a recursive node removal algorithm that replaces removed nodes with in-order successors, preserving BST order across edge cases including nodes with 0, 1, or 2 children. A lot happening at once that couple of weeks, but it genuinely paid off. I learned a lot and grew as a developer. #Java #DataStructures #BinarySearchTree #Algorithms #CS #CodePath
To view or add a comment, sign in
-
💯 Reached 300 LeetCode Problems — A Step Forward in My DSA JourneyI’m excited to share that I’ve solved 300 problems on LeetCode, building a strong foundation in Data Structures and Algorithms. Throughout this journey, I focused on: • Arrays & Strings • Linked Lists • Stacks & Queues • Recursion & Backtracking This helped me improve: ✅ Problem-solving skills ✅ Logical thinking ✅ Writing optimized code 💡 Advice for Beginners (based on my experience): If you’re just starting DSA, don’t try to learn everything at once. 👉 Start with: • Arrays & Strings (very important basics) • Then move to Linked Lists • Practice Stacks & Queues • Learn Recursion and Backtracking 👉 Important Tips: • Focus on understanding patterns, not just solutions • Solve problems consistently (even 2–3 per day) • Don’t jump into advanced topics like Trees, Graphs, or Dynamic Programming too early • Revisit problems you couldn’t solve Consistency matters more than speed. Small daily progress leads to big results. Still learning, still improving 💪 Let’s keep growing 🚀 #LeetCode #DSA #CodingJourney #ProblemSolving #Java #Beginners #Consistency 👍
To view or add a comment, sign in
-
-
🚀 Day 56 of my DSA Journey Today, I worked on a Hard-level problem from LeetCode: 👉 Problem #4 – Median of Two Sorted Arrays (LeetCode) This problem is well-known for its complexity and is frequently asked in top product-based companies. 💡 What I focused on: Understanding the problem deeply instead of jumping directly to the optimal solution Implementing a merge + sort approach to build a clear foundation Applying the two-pointer technique to efficiently identify the median Handling both odd and even length cases carefully ⚙️ Approach Used: Merged both input arrays into a single array Sorted the combined array Used two pointers (i and j) moving towards the center Determined the median based on whether the length is odd or even 📈 Key Learning: Even though the optimal solution has a time complexity of O(log(min(m, n))), building a correct and intuitive approach first is crucial. It strengthens problem-solving skills and helps in understanding advanced techniques later. 🎯 Takeaway: Consistency and clarity in logic are more important than immediately writing the most optimized code. 🔥 Step by step, moving closer to mastering Data Structures & Algorithms. #DSA #LeetCode #ProblemSolving #Java #CodingJourney #PlacementPreparation #Consistency #Learning
To view or add a comment, sign in
-
-
Day 56 of My DSA Journey Today I solved LeetCode 162 – Find Peak Element on . 📌 Problem Given an array "nums", find a peak element and return its index. 👉 A peak element is one that is greater than its neighbors. You can assume: • "nums[-1] = -∞" and "nums[n] = -∞" --- 🧠 Approach – Binary Search (Optimized) Instead of checking every element (O(n)), I used Binary Search. Key Idea: • Calculate "mid" • Compare "nums[mid]" with "nums[mid + 1]" 👉 If "nums[mid] > nums[mid + 1]" → We are in a descending part, so peak lies on the left side (including mid) 👉 Else → We are in an ascending part, so peak lies on the right side Repeat until "start == end" → that index is a peak. --- ⏱ Time Complexity: "O(log n)" — Efficient binary search 📦 Space Complexity: "O(1)" — No extra space used --- 💡 Key Learnings ✔ Using binary search on unsorted-looking problems ✔ Understanding pattern-based decision making ✔ Learning that a problem can have multiple valid answers (any peak) This problem really strengthens intuition for advanced binary search patterns 🚀 --- Consistency continues — getting better every day 💪🔥 #100DaysOfCode #DSA #BinarySearch #LeetCode #Java #ProblemSolving #CodingJourney #DeveloperJourney #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 55 of 100 Days of LeetCode 💻 Today I solved Longest Consecutive Sequence — and honestly, this one taught me more about coding discipline than algorithms. At first, my approach was correct: Used HashSet for O(1) lookup Applied the “start of sequence” logic But I still got TLE. The reason? A tiny mistake: if(!set.contains(num-1)); That single ; made my condition useless and turned my O(n) solution into O(n²). 💡 Lesson learned: Don’t just think your logic is right → verify what your code actually does Small syntax mistakes can completely break optimal solutions Debugging is just as important as problem-solving Finally fixed it and got Accepted ✅ Slowly improving not just in DSA, but in writing cleaner and more careful code. #100DaysOfLeetCode #DSA #Java #CodingJourney #Learning
To view or add a comment, sign in
-
-
Day 75 of My DSA Journey Today’s problem: Reverse Bits (LeetCode 190) At first glance, it looks simple—but it really tests your understanding of bit manipulation 🔹 What I learned today: • How to extract the last bit using n & 1 • Building a reversed number using left shift • Importance of running exactly 32 iterations (handling leading zeros!) • Thinking in terms of binary, not decimal 🔹 Key Idea: Take bits from right to left and rebuild the number from left to right. 💡 This problem helped me get more comfortable with low-level operations—something that’s super useful for writing efficient code. 📈 Progress Update: 75 days of consistency! Small steps every day are building strong problem-solving skills #DSA #100DaysOfCode #Java #CodingJourney #LeetCode #BitManipulation #Consistency #Learning
To view or add a comment, sign in
-
-
🚀 Day 14 of My LeetCode Journey — Linked List Confidence Growing Today’s problems: 🔹 Add Two Numbers (LeetCode 2) 🔹 Odd Even Linked List (LeetCode 328) 💡 Problem 1: Add Two Numbers This problem simulates addition like we do manually: 👉 Traverse both linked lists 👉 Add corresponding digits + carry 👉 Create new nodes for the result 👉 Handle remaining carry at the end 🔥 A great mix of linked list traversal + math logic 💡 Problem 2: Odd Even Linked List This one is all about rearranging nodes: 👉 Separate nodes into odd index and even index 👉 Maintain two pointers (odd & even) 👉 Finally connect odd list with even list ⚡ No extra space needed — done in-place! 🧠 What I Learned: - Handling carry properly is crucial in problems like addition - Rearranging pointers without losing references is key - Linked List problems are getting more intuitive with practice 🔥 Key Takeaways: - Break problems into smaller steps (traverse, compute, connect) - Always track pointers carefully to avoid losing nodes - Practice is making complex problems feel simpler Grateful for the learning journey with Namaste DSA and Akshay Saini 🚀 Day 15 loading… 💪 --- #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #LinkedList #DSA #NamasteDSA #AkshaySaini
To view or add a comment, sign in
-
Day 101/100 💥 Today wasn’t about starting something new… It was about understanding how things actually work under the hood. 📌 What I learned today: - 🌳 Trees in DSA (deeper clarity): Not just traversal… but why recursion fits perfectly with trees → Every node = smaller subproblem - 🔁 Recursion confidence: Earlier it felt confusing… now it feels like a pattern → Base case + faith in function = problem solved - 🧠 Breaking problems smartly: Instead of jumping to code, I focused on: → Structure → Approach → Then implementation - ⚙️ Backend fundamentals (thinking level): Understanding how requests flow, not just writing code blindly 💡 Biggest realization: Coding is not about knowing everything… It’s about thinking correctly under pressure. 🚀 Day 101 — still learning, still building. #Day101 #DSA #Recursion #BackendDevelopment #Java #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Back to Basics — Revisiting DSA Problems Today wasn’t about solving new problems. It was about revisiting what I’ve already learned. I went back to some familiar LeetCode problems: • Container With Most Water • Move Zeroes • Squares of a Sorted Array These are problems I had solved earlier — but this time, I focused on how quickly and clearly I can think through them. And something interesting happened… The logic was still there. Just a bit slow at the beginning. Within a few minutes, it started flowing again. That reminded me of something important: 👉 You don’t lose your logic. 👉 You just lose your speed when you stop practicing. Revisiting problems is not repetition — It’s refining thinking and improving clarity. Consistency over intensity. Building step by step. #LeetCode #DSA #Java #ProblemSolving #Consistency #LearningInPublic #SoftwareEngineering #IPL #RCB #SuperOver (because consistency matters everywhere 😄)
To view or add a comment, sign in
-
More from this author
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