Continuing my 100 Days of DSA journey. Day 71 — LeetCode (Valid Parentheses) Valid Parentheses – Given a string containing just '(', ')', '{', '}', '[' and ']', determine if the input string is valid. A string is valid if open brackets are closed by the same type and in the correct order. Approach (Stack): a) Use a stack to keep track of opening brackets b) Traverse the string character by character c) If an opening bracket is encountered, push it onto the stack d) If a closing bracket is found: Check if the stack is empty → if yes, return false Otherwise, compare with the top of the stack If it matches the corresponding opening bracket, pop it Else, return false e) At the end, if the stack is empty → valid, otherwise invalid Time Complexity: O(n) Space Complexity: O(n) Key takeaway: Learned how stack helps in handling nested and ordered structures efficiently, especially in problems involving matching pairs. On to Day 72... #100DaysOfCode #DSA #LeetCode #Cpp #CyclicSort #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #Stack #Strings #Parentheses #DataStructures
Valid Parentheses LeetCode Solution with Stack
More Relevant Posts
-
Continuing my 100 Days of DSA journey. Day 70 — LeetCode (Longest Repeating Character Replacement) 1) Longest Repeating Character Replacement – Given a string s and an integer k, return the length of the longest substring that can be obtained by replacing at most k characters so that all characters in the substring are the same. Approach (Sliding Window + Frequency Tracking): a) Use a sliding window with two pointers to maintain a valid substring b) Keep a frequency array to track count of characters in the current window c) Track the count of the most frequent character in the window d) If (window size - max frequency) > k, shrink the window from the left e) This ensures we replace at most k characters f) Update the maximum window length at each step Time Complexity: O(n) Space Complexity: O(1) On to Day 71... #100DaysOfCode #DSA #LeetCode #Cpp #CyclicSort #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #SlidingWindow #Strings #Optimization
To view or add a comment, sign in
-
Continuing my 100 Days of DSA journey. Day 69 — LeetCode (Balanced Binary Tree) Balanced Binary Tree – Given a binary tree, determine if it is height-balanced (i.e., the heights of left and right subtrees of every node differ by no more than 1). Approach (DFS + Height Optimization): a) Use a recursive function to calculate the height of each subtree b) For each node, recursively get the height of left and right subtrees c) If any subtree returns -1, propagate -1 upwards (indicating imbalance) d) Check if the absolute difference between left and right heights is greater than 1 e) If unbalanced, return -1 immediately f) Otherwise, return 1 + max(leftHeight, rightHeight) Time Complexity: O(n) Space Complexity: O(h) (recursion stack) On to Day 70... #100DaysOfCode #DSA #LeetCode #Cpp #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #Greedy #Strings #Optimization
To view or add a comment, sign in
-
-
Continuing my 100 Days of DSA journey. Day 76 — LeetCode (Minimum Window Substring) - Hard Minimum Window Substring – Given two strings s and t, return the minimum window in s which will contain all the characters in t. If there is no such window, return an empty string. Approach (Sliding Window + Hashing): a) Use two hash maps to track required characters and current window frequency b) Maintain two pointers to represent the window (left and right) c) Expand the window by moving the right pointer and update frequency d) Keep track of how many required characters are satisfied e) When all characters are matched, try to shrink the window from the left f) Update the minimum window length whenever a valid window is found g) Continue the process until the entire string is traversed Time Complexity: O(n) Space Complexity: O(1) Key takeaway: Learned how combining sliding window with frequency tracking helps efficiently solve complex substring problems with multiple constraints. On to Day 77... #100DaysOfCode #DSA #LeetCode #Cpp #CyclicSort #Algorithms #CodingJourney #ProblemSolving #SoftwareEngineering #InterviewPrep #LearningInPublic #geeksforgeeks #Microsoft #SlidingWindow #Hashing #Strings #TwoPointers
To view or add a comment, sign in
-
-
🚀 𝗬𝗼𝘂 𝗰𝗼𝗺𝗽𝗿𝗲𝘀𝘀 𝟭𝟬 𝗚𝗕, 𝗴𝗲𝘁 𝟯 𝗚𝗕. 𝗬𝗼𝘂 𝗲𝘅𝘁𝗿𝗮𝗰𝘁, 𝗴𝗲𝘁 𝟭𝟬 𝗚𝗕 𝗯𝗮𝗰𝗸. 𝗪𝗵𝗲𝗿𝗲 𝗱𝗶𝗱 𝘁𝗵𝗼𝘀𝗲 𝟳 𝗚𝗕 𝗲𝘃𝗲𝗻 𝗴𝗼? Your file is full of repetition. Way more than you think. A video? Thousands of frames where the background doesn't change. A text file? The word "the" showing up hundreds of times. Code? Same patterns everywhere. The first algorithm, 𝗟𝗭𝟳𝟳, catches this. Instead of storing "the" for the 300th time, it leaves a tiny note - "copy what I wrote 200 bytes ago." That note is 3 bytes. The original was 50. Gone. Then 𝗛𝘂𝗳𝗳𝗺𝗮𝗻 steps in and looks at what's left. It notices some symbols appear constantly, others barely show up. So it gives short codes to the popular ones, longer codes to the rare ones. Like VIP lanes, frequent flyers board faster. Boom. 10 GB becomes 3 GB. Now extraction, The ZIP file secretly carries a codebook inside it. When you extract, it reads that map and works backwards. Huffman restores every symbol. LZ77 follows every pointer and pastes everything back. Byte by byte. Frame by frame. Pixel by pixel. Your original 10 GB, fully restored. Math didn't compress your file. Math just found a smarter way to tell the same story. #SoftwareEngineering #ComputerScience #Programming #TechForEveryone #LearningInPublic #Algorithms #Developer #CodingLife
To view or add a comment, sign in
-
Day 32 of DSA Practice ✅ Worked on: • Intersection of Two Linked Lists (LeetCode 160) [Easy] • Add Two Numbers (LeetCode 2) [Medium] • Delete the Middle Node of a Linked List (LeetCode 2095) [Medium] Today was a really interesting day with multiple Linked List patterns. For Intersection of Linked Lists, I first thought of calculating sizes and aligning both lists. But then I learned a better approach using two pointers — switching heads when reaching null. It felt tricky at first, but after understanding how both pointers travel equal distance, the logic clicked. In Add Two Numbers, I used a dummy node and handled carry while traversing both lists. The loop continues until both lists and carry are finished, which made sure no value is missed. This problem was all about careful handling of values and carry at each step. For deleting the middle node, I initially thought of using size and removing the (n/2)th node, but that required two passes. Then switched to slow and fast pointers, and tracked the previous node to remove the middle in a single pass. Also paid attention to edge cases like: • Lists of different lengths • Carry remaining after traversal • Single node list (becomes empty after deletion) • No intersection case Felt like a strong learning day where multiple approaches clicked together. #DSA #LinkedList #ProblemSolving #CodingJourney #LearningInPublic #100DaysOfCode #Consistency #DataStructures
To view or add a comment, sign in
-
🚀 Day 21/100 – DSA Journey Today’s problems were all about string comparison and pattern matching 🔤 At first they looked straightforward… but handling all cases cleanly was the real challenge 👀 🔹 Problems Solved: 1. Valid Anagram 2. Longest Common Prefix 💡 Key Learnings: 👉 Problem 1: Valid Anagram Compare character frequencies of both strings If every character count matches → strings are anagrams 👉 Key Insight: Frequency counting using Map/Object makes comparison efficient ✅ O(n) Time ✅ O(1) Space (fixed alphabet size) 👉 Problem 2: Longest Common Prefix Start with the first word as prefix Compare it with remaining strings Reduce prefix until all strings match 👉 Key Insight: Gradually shrinking the prefix is simpler than generating all prefixes ✅ O(n * m) Time (m = prefix length) ✅ O(1) Extra Space 🔥 What I learned today: String problems are less about complicated algorithms and more about: choosing the right approach handling edge cases carefully writing clean logic Small optimizations and cleaner thinking are becoming more natural now ⚡ Day 21 done ✅ Still showing up every day! 💬 Quick question: Which do you prefer solving more: 🔹 String problems 🔹 Linked List problems 🔹 Array problems #100DaysOfDSA #buildinpublic #developersoflinkedin #codinginpublic #leetcodejourney #softwareengineerlife #frontenddeveloper #dailylearning #codingpractice #devcommunity #programminglife #techcareers #jobready #growthmindset
To view or add a comment, sign in
-
Day 17. Sorting Logic & System Internals. Today’s progress: ✅ DSA — Implemented Selection Sort and Insertion Sort. Building functions to return sorted arrays from scratch is the best way to understand how different algorithms handle data movement and time complexity. CODE : https://lnkd.in/dTMCJdkq ✅ Operating Systems — Deep dive into Processes vs. Threads. Understanding execution units and memory sharing is a game-changer for writing efficient code. ✅ System Clean-up — Learned about Zombie and Orphan processes. It’s fascinating (and vital) to see how the OS manages "lost" processes and keeps the system from leaking resources. 17 days down. The fundamentals are stacking up. See you at Day 18. 🚀 #DSA #100DaysOfCode #BuildInPublic #OperatingSystems #ComputerScience #WebDev #DevJourney #SoftwareEngineering
To view or add a comment, sign in
-
📌 Day 2/100 – #100DaysOfDSA Continuing the journey 🚀 🔍 Problem Solved: Best Time to Buy and Sell Stock (LeetCode 121) 🧠 What I learned: How to track the minimum price so far while iterating Calculating maximum profit in a single pass Optimizing from brute force O(n²) → O(n) ✅ Solution Approach: Traverse the array once 👣 Update the minimum price Calculate profit at each step and track the maximum 📈 💡 Key Insight: Instead of checking all pairs, track the lowest price before the current day 💻 Code (JavaScript): var maxProfit = function (prices) { let min = prices[0]; let maxProfit = 0; for (let i = 0; i < prices.length; i++) { if (min > prices[i]) { min = prices[i]; } if (prices[i] - min > maxProfit) { maxProfit = prices[i] - min; } } return maxProfit; }; ⚡ Takeaway: A simple observation can drastically reduce complexity — that’s the power of DSA Consistency is the goal — Day 2 done ✅ If you're also solving daily, let’s connect and grow together 🤝 #100DaysOfDSA #DataStructures #Algorithms #LeetCode #Programming #DeveloperJourney #ProblemSolving
To view or add a comment, sign in
-
Logic + Building: Day 13/180!🚀 Today was about more than just writing code—it was about how the computer executes it. I started with Functions and the fascinating Function Call Stack. The Deep Dive: Understanding Stack Frames Every function call creates a 'Stack Frame' in memory—a dedicated workspace containing: 1️⃣ Local Variables: The workspace's own tools (Variables declared inside). 2️⃣ Function Parameters: The instructions/data passed to the workspace. 3️⃣ Return Address: The "GPS" that tells the CPU exactly where to go back once the function finishes its job. Why this matters? Understanding the Call Stack is the secret to mastering Recursion and debugging complex logic. If you know how the stack grows and shrinks, you control the program! Status: ✅ Function Basics: Done. ✅ Stack Memory Visualization: Clear. 🚀 Ready to build modular and optimized code. (Resource: #CodeHelp — Love Babbar Bhaiya) #180DaysChallenge #100DaysOfCode #CProgramming #Functions #CallStack #SoftwareEngineering #LogicBuilding #DSA #BuildInPublic #CodeHelp #LoveBabbar #ComputerScience #MemoryManagement
To view or add a comment, sign in
-
Explore related topics
- Leetcode Problem Solving Strategies
- LeetCode Array Problem Solving Techniques
- DSA Preparation Tips for First Interview Round
- How to Approach Full-Stack Code Reviews
- Why Use Coding Platforms Like LeetCode for Job Prep
- Common Data Structure Questions
- How to Develop Structured Problem Solving Skills
- Google SWE-II Data Structures Interview Preparation
- How to Validate Problems Before Solutions
- Key DSA Patterns for Google and Twitter Interviews
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