🌷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
"Designed a Min Stack with auxiliary stack for O(1) operations in C++"
More Relevant Posts
-
🚀 #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 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
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
-
-
🔥 HyperRevision with Structure – Day 93 🔥 🧩 Problem solved today: 1️⃣ Network Delay Time (LeetCode 743) 💭 Thoughts: Understanding Dijkstra’s method is essential before trying to write the code. ⏱️ Time Complexity: O(E log V) 💾 Space Complexity: O(V + E) 📌 GitHub link in comments #HyperRevision #NeetCode150 #GraphTraversal
To view or add a comment, sign in
-
-
🎯 LeetCode Daily – Combination Sum IV (Day 125) Today’s problem was a powerful exploration of Dynamic Programming with sequence-based combinations - Combination Sum IV. ✅ My Approach: 🔹 Problem – Combination Sum IV: • The goal was to find the number of possible ordered combinations that sum up to a given target using elements from an array. • Implemented Memoization (Top-Down DP) to recursively explore all ways to reach the target, caching results to prevent recomputation. • Then optimized with Tabulation (Bottom-Up DP), where each state dp[i] represents the number of combinations that sum to i. • For every value from 0 to target, iterated through all numbers and accumulated valid combinations. 🧠 Key Insight: Unlike the traditional Subset Sum or Coin Change problems, this problem treats order as significant, making it a classic case of permutation-based DP. The key is understanding how smaller sub-targets build up to form the total - a perfect demonstration of the power of recursive relationships. 📊 Time Complexity: O(N × Target) 📦 Space Complexity: O(Target) #LeetCode #DSA #DynamicProgramming #Combinatorics #ProblemSolving #DailyCoding #LearningInPublic #Day125
To view or add a comment, sign in
-
-
Day 8: LeetCode 1611 — Minimum One Bit Operations to Make Integers Zero. "Explored how bit manipulation connects with Gray Code logic!" 💡 Learned that each i-th set bit follows the relation F[i] = 2*F[i-1] + 1, and for multiple 1’s, we alternate signs while moving left to right to avoid disturbing previous bits. 🧠 Time Complexity: O(30) ≈ O(1) 💾 Space Complexity: O(30) ≈ O(1)
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
-
-
💡 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐃𝐚𝐢𝐥𝐲 𝐂𝐡𝐚𝐥𝐥𝐞𝐧𝐠𝐞 -𝟑𝟐𝟏𝟕. 𝐃𝐞𝐥𝐞𝐭𝐞 𝐍𝐨𝐝𝐞𝐬 𝐅𝐫𝐨𝐦 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭 𝐏𝐫𝐞𝐬𝐞𝐧𝐭 𝐢𝐧 𝐀𝐫𝐫𝐚𝐲 🧩 Problem Summary: We are given a linked list and an array nums. The goal is to remove all nodes from the linked list whose values appear in nums, and then return the modified linked list. 🧠 Approach : • Store all elements from nums in an 𝐮𝐧𝐨𝐫𝐝𝐞𝐫𝐞𝐝_𝐬𝐞𝐭 for O(1) lookup. • Handle deletions from the beginning of the list (in case the head node’s value exists in nums). • Traverse the linked list and skip nodes whose values are present in the set. • Return the modified head of the list. 💨 Time Complexity: O(N + M) (where N = number of nodes in list, M = size of nums) 💾 Space Complexity: O(M) 🧩 Key Learning: • Efficient node deletion from a linked list becomes simpler when combined with hashing. • Using an unordered_set helps in quick membership checking and clean logic. #LeetCode #CodingChallenge #Leetcode #DataStructures #LinkedList #DSA #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🎯 LeetCode Daily – Triangle (Day 113) Today’s problem deepened my understanding of Dynamic Programming on Triangular Grids, focusing on minimizing path sums efficiently. ✅ My Approach: 🔹 Problem – Triangle: • The goal was to find the minimum path sum from the top to the bottom of a triangle array. • Used Memoization (Top-Down DP) to recursively explore all paths while storing intermediate results to avoid redundant computations. • Implemented Tabulation (Bottom-Up DP) to build the solution iteratively starting from the last row and moving upward, computing the minimum path for each position using values from the row below. 🧠 Key Insight: This problem beautifully demonstrates the power of Dynamic Programming in optimizing recursive solutions. By transitioning from memoization to tabulation, the problem transforms from exponential recursion to an elegant linear-time solution. Recognizing overlapping subproblems and optimal substructure patterns is key to mastering DP on grids and triangles. 📊 Time Complexity: O(N²) 📦 Space Complexity: O(N²) #LeetCode #DSA #DynamicProgramming #ProblemSolving #DailyCoding #LearningInPublic #Day113
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
-
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