🚀 Solved: Valid Parentheses (Stack Based Problem) Today I worked on a classic problem that looks simple but tests your core logic 👇 🧠 Problem: Given a string containing only (), {}, [] 👉 Check if the parentheses are valid 💡 Approach I used: Used a stack Push opening brackets For closing brackets: Check top of stack If match → pop Else → invalid ⚙️ Key Insight: 👉 Order matters more than count 👉 Stack helps track the sequence correctly 🔥 What I learned: Importance of stack in real problems Handling edge cases (empty stack, mismatch) Writing clean conditional logic 📌 Time Complexity: O(n) 📌 Space Complexity: O(n) 💬 Have you solved this problem differently? Would love to know your approach! #javascript #cpp #datastructures #algorithms #coding #leetcode #interviewprep
Valid Parentheses Stack Problem Solution
More Relevant Posts
-
Day 07: Cracking the "Non-Divisible Subset" Logic 🧩 Today was a true test of algorithmic thinking. I tackled a problem that looks like a standard array search but is actually a brilliant exercise in Number Theory and Remainder Math. The Challenge: Given a set of numbers, find the maximum size of a subset where the sum of any two numbers is not divisible by K The Strategy (Remainder Frequency): Instead of checking every possible pair (which would be very slow), I focused on remainders . If two numbers sum to a multiple of K, their remainders (r1+r2) must sum to K. const s = [19,10,12,10,24,25,22]; const k = 4; function nonDivisibleSubset(k, s) { let freq = new Array(k).fill(0); // count remainders for (let num of s) { freq[num % k]++; } let count = 0; // remainder 0 case if (freq[0] > 0) count++; // check pairs for (let i = 1; i <= Math.floor(k / 2); i++) { if (i === k - i) { // special case when k is even if (freq[i] > 0) count++; } else { count += Math.max(freq[i], freq[k - i]); } } return count; } console.log(nonDivisibleSubset(k,s)) Key Takeaway: When a problem involves divisibility, don't look at the numbers—look at the remainders. It turns a complex pairing problem into a simple counting one! One full week of coding done. The momentum is real! 🚀 #JavaScript #Algorithms #NumberTheory #100DaysOfCode #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
🚀 Just Uploaded a New LeetCode Solution! Solved LeetCode #26 – Remove Duplicates from Sorted Array using the Two Pointer Technique in JavaScript. This is a must-know pattern for coding interviews — simple idea, but very powerful when applied correctly. 👉 In this video, I’ve covered: Intuition behind the problem Step-by-step dry run Optimal in-place solution (O(n) time, O(1) space) Clean and easy-to-understand JavaScript code 🔗 Watch here: https://lnkd.in/g-HgkGXQ If you're preparing for coding interviews or strengthening your DSA fundamentals, this one is definitely worth your time. Would love to hear your approach to this problem — drop it in the comments 👇 #leetcode #dsa #codinginterview #javascript #twopointer #programming #softwaredevelopment #coding #developers #learning #jdcodebase
Remove Duplicates from Sorted Array | Optimal Two Pointer Approach 🔥 | LeetCode Explained (JS)
https://www.youtube.com/
To view or add a comment, sign in
-
🚀 Mastering a Classic Algorithm: Balanced Parentheses (Stack – LIFO) Today I revisited a fundamental problem that every Software Engineer should understand: validating balanced parentheses using a stack. Why it matters: This pattern appears in compilers, interpreters, and even real-world applications like expression parsing. Here’s the idea: 👉 Use a stack (LIFO) 👉 Push opening brackets 👉 Pop and match when encountering closing brackets 👉 Ensure the stack is empty at the end Clean and efficient JavaScript implementation 👇 This is a great reminder that mastering data structures like stacks is key to solving real algorithmic problems efficiently. I’m currently building and documenting algorithm patterns here: 🔗 https://lnkd.in/ej4fNeZs #SoftwareEngineering #JavaScript #Algorithms #DataStructures #Coding #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
Day 112 of #200DaysOfCode Leveling up Consistency continues, one concept at a time. Today I solved the "Memoize" problem on LeetCode using closures + caching in JavaScript. Key Idea: Avoid recomputing the same function call by storing previously calculated results. Approach: • Use a Map as cache storage • Convert arguments into a unique key using JSON.stringify() • If result already exists return cached value • Otherwise compute, store, and return result Concepts Used: • Closures • Memoization • Map • Higher Order Functions Time Complexity: • First Call → Depends on function • Repeated Calls → O(1) average lookup Space Complexity: O(n) Takeaway: Memoization is a powerful optimization technique that trades space for speed and is heavily used in Dynamic Programming and performance optimization. Learning not just to solve problems — but to make solutions smarter Let’s keep building #Day112 #200DaysOfCode #LeetCode #JavaScript #Memoization #Closures #CodingJourney #ProblemSolving #KeepGoing
To view or add a comment, sign in
-
-
LeetCode Day 14 : Problem 58 (Length of Last Word) Just solved another LeetCode problem. It was "Length of Last Word", sounds trivial, right? But here's what I actually learned: My first solution had an unnecessary loop trimming every word after splitting. Trimming an already clean word does nothing. Always ask yourself, is this step actually doing anything? split(' ') on multiple spaces creates empty strings in between. "fly me to moon".split(' ') gives ["fly", "me", "", "", "to", "", "", "moon"]. A single space in split doesn't mean split on any whitespace, it means split on exactly one space character. The cleaner fix? Use a regex /\s+/ which splits on one or more spaces at once. No empty strings, no extra loop, no trimming needed. Then just pop the last element and return its length. Sixteen problems in. String manipulation problems look easy until whitespace gets involved. Always think about what split actually does to your string before assuming the result is clean. The real lesson? Unnecessary steps don't just add clutter, they hide the actual intent of your code. Write only what you need. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
🚀 Day 7 of My LeetCode Journey — Sorting Fundamentals Today I focused on two classic sorting algorithms: 🔹 Bubble Sort 🔹 Selection Sort 💡 Bubble Sort The idea is simple: 👉 Compare adjacent elements 👉 Swap if they are in the wrong order 👉 Repeat until the array is sorted It’s easy to understand, but not efficient for large datasets. ⏱️ Time Complexity: O(n²) 💡 Selection Sort A slightly different approach: 👉 Find the minimum element 👉 Place it at the correct position 👉 Repeat for the rest of the array Also simple, but still not optimal for big inputs. ⏱️ Time Complexity: O(n²) 🔥 Key Takeaways: These algorithms may not be optimal, but they build strong fundamentals Understanding how sorting works internally is more important than memorizing Optimization comes later — basics come first Big thanks to Namaste DSA and Akshay Saini 🚀 for guiding this journey Consistency is the real win — Day 8 loading 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #Sorting #BubbleSort #SelectionSort #NamasteDSA
To view or add a comment, sign in
-
🚀 Day 24 of My Coding Journey — Power of Two Today’s problem was “Power of Two” — a simple-looking question that really highlights the beauty of bit manipulation. 🔍 What I learned: Instead of using loops or recursion, I explored how binary representation works. A power of two always has only one set bit (1) in its binary form — and that insight leads to a super efficient solution. 💡 Key trick: n & (n - 1) === 0 This removes the lowest set bit, and if the result is zero, the number is a power of two. ⚡ Takeaway: Sometimes the most optimized solutions come from understanding how data is represented internally, not just from writing more code. 📈 Progress: Day by day, I'm getting more comfortable with problem-solving patterns and thinking beyond brute force approaches. #128DaysOfCode #LeetCode #JavaScript #CodingJourney #ProblemSolving #BitManipulation
To view or add a comment, sign in
-
-
🚀 Day 11 of My LeetCode Journey — Deep Dive into Linked Lists Today was all about mastering patterns in Linked Lists: 🔹 Linked List Cycle (LeetCode 141) 🔹 Palindrome Linked List (LeetCode 234) 💡 Problem 1: Linked List Cycle Tried two approaches: ✅ Using Set Store visited nodes If node already exists → cycle detected ⏱️ Time: O(n) | 📦 Space: O(n) ✅ Fast & Slow Pointer (Floyd’s Algorithm) 🔥 Slow → 1 step Fast → 2 steps If they meet → cycle exists ⏱️ Time: O(n) | 📦 Space: O(1) 👉 This approach is elegant and optimal! 💡 Problem 2: Palindrome Linked List Again explored two approaches: ✅ Convert to Array Store values in array Compare from both ends ⏱️ Time: O(n) | 📦 Space: O(n) ✅ Optimal Approach (In-place) 🔥 Find middle node Reverse second half of linked list Compare both halves ⏱️ Time: O(n) | 📦 Space: O(1) 👉 This one really tested pointer manipulation skills! 🧠 What I Learned: One problem can have multiple valid approaches Optimal solutions often reduce space complexity Linked Lists = pointer mastery + careful thinking 🔥 Key Takeaways: Always try brute force first → then optimize Fast & slow pointer is a game-changing technique In-place solutions are highly valued in interviews Big thanks to Namaste DSA and Akshay Saini 🚀 for the guidance Day 12 loading… 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #LinkedList #TwoPointers #DSA #NamasteDSA
To view or add a comment, sign in
-
LeetCode Day 15 : Problem 151 (Reverse Words in a String) Just solved another LeetCode problem. It was "Reverse Words in a String", sounds familiar, right? But here's what I actually learned: Sometimes the best solution is knowing exactly which built-in tools to chain together. trim() removes leading and trailing spaces. split(/\s+/) splits on one or more spaces with no empty strings. reverse() flips the array. join(" ") puts it back with single spaces. Four methods, one line, done. This problem would have taken me much longer at the start of this journey. But after solving whitespace problems before, the /\s+/ regex was already in my toolkit. Every problem you solve teaches you something you use again later. The insight that made it click, strings are just arrays of words waiting to be manipulated. Know your array methods and string problems become much easier. Eighteen problems in. Sometimes the lesson isn't about a new algorithm or pattern. Sometimes it's about recognising that the tools you already have are exactly what you need. The real lesson? Build your toolkit problem by problem. Each solution you learn is a tool you carry into the next one. #DSA #LeetCode #JavaScript #CodingJourney #Programming
To view or add a comment, sign in
-
-
🚀 A Major Update is Coming to CodeAlive (Live in 3–4 Days!) I honestly started CodeAlive as a small platform with a simple goal in mind — to let my code snippets live over the internet with support for custom sharable links. But seeing how far it has come now, evolving into a platform with so many useful and smart features for everyone, has been incredibly exciting. 🌐 CodeAlive – https://lnkd.in/gnthhf_b 👉 Also, you can click "View My Website" on my profile to visit the platform. What’s Coming Next ⏭️ CodeAlive is soon introducing: **Multi-Language Detection & Highlighting in a Single Code File** Problem: Almost every code-sharing platforms and online editors are built around one assumption: 1 File = 1 Language But real-world development is rarely that simple. Developers often share: ✅ Frontend + Backend snippets together ✅ Embedded scripts/styles ✅ Configurations with code ✅ Multi-language examples in one paste And when platforms force a single language highlight, readability suffers. With This New Update, CodeAlive Will Support ✅ Detecting multiple languages within one pasted code file ✅ Highlighting different sections based on actual context/language ✅ Making mixed-language snippets cleaner, smarter, and easier to read This has been one of the most exciting features to work on so far, and I can’t wait to share the full implementation details once it officially goes live. 📅 Expected Release: 3–4 Days Stay tuned 👀 More technical insights coming soon... #CodeAlive #BuildInPublic #Programming #SoftwareDevelopment #DeveloperTools #WebDevelopment #Python #JavaScript #StartupJourney
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