🔗 Day 63 of #100DaysOfCode 🔗 🔹 Problem: Valid Parentheses – LeetCode ✨ Approach: Implemented a stack-based validation to ensure every opening bracket has a matching closing one in correct order. Each character is checked systematically — pushing opens and popping closes — making it both clean and efficient! ⚡ 📊 Complexity Analysis: Time Complexity: O(n) — single traversal of the string Space Complexity: O(n) — stack usage for unmatched brackets ✅ Runtime: 2 ms (Beats 97.47%) ✅ Memory: 41.96 MB 🔑 Key Insight: Stacks are the unsung heroes of structured logic — from parentheses validation to syntax parsing, they keep the balance just right. 🧠 #LeetCode #100DaysOfCode #ProblemSolving #DSA #Stack #AlgorithmDesign #CodeJourney #ProgrammingChallenge #LogicBuilding #Efficiency #CodingDaily
Valid Parentheses Solution with Stack - 100DaysOfCode
More Relevant Posts
-
🔢 “Today was all about turning strings into numbers — one recursive call at a time.” 🚀 Day 54/150 – DSA Challenge ✅ Problem solved: String to Integer (atoi) – LeetCode 8 (Recursion Approach) Converting a string to an integer sounds simple… until you start handling edge cases. Steps I followed: 1. Skip leading spaces. 2. Check for sign (+ / -). 3. Parse digits recursively. 4. Handle overflow by bounding between INT_MIN and INT_MAX. The recursion gave it a clean logical flow — digit by digit, call by call. ⏳ Time: O(n) 📦 Space: O(n) (recursion stack) 💡 “Recursion isn’t just looping — it’s trusting the next call to finish what you started.” 🔥 From text to integers, one call at a time. #Day54 #DSA #150DaysChallenge #LeetCode #StriverSheet #Recursion #ProblemSolving #CodingJourney #Atoi
To view or add a comment, sign in
-
-
Day 22 of #100DaysOfCode Today I solved the “Permutation in String” problem on LeetCode — a tricky one that really sharpens your understanding of sliding window and frequency mapping in strings. 🧩 Problem in short: Given two strings s1 and s2, the task is to check if any permutation of s1 exists as a substring in s2. At first glance, it feels like a brute-force problem — generate all permutations of s1 and check each in s2. But that’s computational suicide for longer strings. So the challenge was to find a smarter, optimized approach. ⚙️ Intuitive Approach: Instead of generating permutations, I focused on character frequencies. Maintain two frequency arrays — one for s1 and one for the current window of s2. Slide the window across s2, adding and removing characters as you move. Whenever both frequency arrays match, it means that substring of s2 is a permutation of s1. This approach reduces the complexity drastically and relies on pattern recognition through frequency matching, not brute force. Every day in this challenge is a reminder that optimization isn’t about doing less work — it’s about doing the right work. #LeetCode #C++ #ProblemSolving #DSA #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🔹 Day 69 of #100DaysOfLeetCodeChallenge 🔹 🚀 Problem: Subsets II 🔑 Topic: Backtracking 🧠 Approach: The task is to find all unique subsets of an array that may contain duplicates. Here’s the step-by-step logic 👇 Sort the array first to bring duplicates together. Use backtracking to explore every possible subset. Skip duplicates by checking if the current element equals the previous one at the same recursion depth. Add every subset (including empty) to the result list. ⏳ Time Complexity: O(2^n) 💾 Space Complexity: O(n) (recursion stack + temp list) 📌 Example: Input: nums = [1,2,2] Output: [[], [1], [1,2], [1,2,2], [2], [2,2]] ✅ 🎯 Takeaway: Sorting and skipping duplicates isn’t just for combinations — it’s the secret weapon for clean subset generation too! ⚡ #LeetCode #DSA #Backtracking #Subsets #ProblemSolving #CodingChallenge #100DaysOfLeetCodeChallenge 🚀
To view or add a comment, sign in
-
-
✨ Day 49 of 50 Days Challenge ✨ Solved LeetCode 115: Distinct Subsequences (Hard) 👉 Problem Statement: Given two strings s and t, return the number of distinct subsequences of s that equal t. A subsequence is formed by deleting some (or none) characters without changing the relative order of the remaining characters. 📌 Examples: Input: s = "rabbbit", t = "rabbit" Output: 3 There are 3 ways to form “rabbit” from “rabbbit”. Input: s = "babgbag", t = "bag" Output: 5 There are 5 ways to form “bag” from “babgbag”. 🔎 Approach Used: ➡️ Dynamic Programming (DP) — Space Optimized 1. Create two arrays (prev and curr) to store the count of subsequences. 2. Initialize base cases — there’s always one way to form an empty string. 3. For each character in s, compare it with each character in t: If characters match → add ways from both including and excluding it. If not → carry over the previous count. 4. Continue iterating and swap arrays to save space. ✅ Complexity Analysis: Time Complexity: O(n × m) Space Complexity: O(m) → Optimized 1D DP #50DaysChallenge #LeetCode #C++ #DynamicProgramming #Strings #Subsequences #DSA #CodingChallenge #Algorithms
To view or add a comment, sign in
-
-
Day 52 of #100DaysOfCode 🧩 Problem: 3321. Find X-Sum of All K-Long Subarrays II Difficulty: Hard This version builds on the easier “Find X-Sum” problem, but the constraints are massive — meaning brute force dies instantly. The goal is to maintain the sum of top x most frequent elements for every subarray of size k, with efficient updates as the window slides. 💡 What I learned: Balancing efficiency and correctness in sliding window problems is tricky. Frequency tracking with ordered structures (like multiset or heap) keeps updates O(log n). Rebalancing the “top x” elements correctly after each update is crucial to avoid stale counts. 🧠 Key takeaway: Optimization isn’t about shaving milliseconds; it’s about understanding how to reuse work instead of starting over every time. Every “Hard” problem eventually boils down to patience, debugging, and a little bit of emotional damage. #LeetCode #C++ #DSA #ProblemSolving #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
🌷Day 75 LeetCode: Min Stack (155) Approach: Designed a stack that supports push, pop, top, and getMin in O(1) time by maintaining an additional stack to track minimum values. ✨ Learned how auxiliary stacks help maintain extra information efficiently — a smart design pattern for constant-time operations! 📈 Improved understanding of stack design, auxiliary data structures, and optimized retrieval in C++. #LeetCode #100DaysOfCode #DSA #Stack #Design #ProblemSolving #CodingJourney #CodeEveryday
To view or add a comment, sign in
-
-
🚀 #Day57 of #100DaysOfLeetCodeHard 📘 Problem: [LeetCode 2547 – Minimum Cost to Split an Array] My Submission:https://lnkd.in/gB2aQ9TS This one was a really interesting DP + preprocessing problem that tested both efficiency and clarity of thought. 💡 Approach: The key idea was to precompute the cost of every possible subarray [i...j], where cost represents the number of elements that appear more than once (the trimmed part). Once precomputed, the problem transforms into a simple Dynamic Programming formulation: dp[i] = min( k + cost[i][j] + dp[j+1] ) for all j ≥ i This way, we can efficiently find the optimal points to split the array, minimizing the total cost. Given the constraints (n ≤ 1000), an O(n²) preprocessing and DP approach works perfectly. 🧮 Complexity: Time: O(n²) Space: O(n²) A neat problem that beautifully combines frequency tracking, preprocessing, and classic DP — a great example of how strong intuition can simplify what initially looks intimidating. #100DaysOfLeetCodeHard #Day57 #LeetCode #DynamicProgramming #ProblemSolving #DSA #CompetitiveProgramming #Precomputation
To view or add a comment, sign in
-
-
Day 25 of #100DaysOfCode Today I tackled the “Find All Anagrams in a String” problem on LeetCode — a great challenge that builds directly on the concept of sliding window and frequency comparison. 🧩 Problem Summary: Given two strings s and p, the task is to find all start indices in s where an anagram of p appears as a substring. At first, it might look similar to the “Permutation in String” problem — and that’s exactly the connection! The difference here is that instead of just checking if such a substring exists, we need to find all of them. ⚙️ Intuitive Approach: 1. Count character frequencies for p. 2. Use a sliding window over s of size equal to p.length(). 3. Maintain a frequency map for the current window and compare it with p’s frequency map. 4. Every time the maps match → we’ve found an anagram’s starting index. This problem reinforced how powerful the sliding window + frequency array technique can be when dealing with substring-based string problems. Each problem I solve reminds me that mastering patterns is far more valuable than memorizing solutions. #LeetCode #C++ #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
✅ Day 4/75 🌟 Today’s Progress 1️⃣ Longest Consecutive Sequence — LeetCode Medium Problem: Given an unsorted array of integers, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. 🔹Approaches: 1️⃣ Sorting Approach (Brute Force) Sorted the array and count the consecutive elements. Time Complexity: O(N log N). 2️⃣ Optimal – HashSet Stored all the numbers in a HashSet. For each number, checked if it’s the start of a sequence (i.e., num - 1 not in set). Then counted how long the consecutive sequence continues. ✅ Time: O(N) | Space: O(N) 2️⃣ Product of Array Except Self — LeetCode Medium Problem: Given an array nums, return an array answer such that answer[i] equals the product of all elements except nums[i], without using division, in O(n) time. 🔹Approaches: 1️⃣ Brute Force: Multiplied all elements except self for each index. ⏱️ Time: O(N²) 2️⃣ Optimal – Prefix & Suffix Product First pass: calculated the prefix products (product of all elements to the left). Second pass: multiplied each element by the suffix product (product of all elements to the right). ✅ Time: O(N) | Space: O(1) (excluding output array) On to Day 5 tomorrow! ✨ #NeetCode #Blind75 #DSA #LeetCode #CodingChallenge #ProblemSolving
To view or add a comment, sign in
-
💻 #2DayOf150 — Remove Duplicates from Sorted Array II (LeetCode #80) Day 2 and still going strong 💪 Today was all about keeping things clean and minimal — both in code and logic. After a solid dry run session, the entire idea just clicked. The two-pointer trick felt like magic once I saw how it limits duplicates perfectly in place ✨ 🧩 Approach Use one pointer to place valid elements Allow only up to 2 occurrences of each number In one pass, the array gets compressed beautifully ✅ Time: O(n) ✅ Space: O(1) ✅ Elegant, minimal, and efficient Dry run tested. Logic locked. Consistency on track 🔥 #DSA #LeetCode #CodingJourney #ProblemSolving #Cplusplus #100DaysOfCode #2DayOf150
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