Day 18 / 100 Days of Code Challenge 💻🔥 Solved LeetCode 155 — Min Stack 📊 🔍 Problem • Design a stack that supports standard operations: push, pop, top • Additionally, implement getMin() to return the minimum element • All operations must run in O(1) time ⚙️ Approach (Two Stack Technique) • Use one stack to store all elements • Use another stack to keep track of minimum values • While pushing, store the current minimum • While popping, update the minimum accordingly 💡 Key Learning • Maintaining extra information in data structures • Efficient tracking of minimum without traversal • Understanding how to achieve constant time operations ⏱ Complexity • Time: O(1) for all operations ⚡ • Space: O(n) 📦 Consistency continues 🚀 #100DaysOfCode #LeetCode #DSA #Stack #ProblemSolving #Consistency
Designing a Min Stack with O(1) Time Complexity
More Relevant Posts
-
Day 4/100 of my LeetCode Journey Back on track after a short break, and today’s problem was “Kth Smallest Element in a Sorted Matrix.” At first, I didn’t approach it correctly. I was thinking in terms of simple indexing, but this problem required a different perspective. I learned how a min heap can be used to efficiently track the smallest elements across multiple rows. Instead of checking the entire matrix, the idea is to always pick the smallest available element and move forward from there. What I noticed today is that my logic is improving, but I still need to be careful with implementation. Small syntax and indexing mistakes can break the whole solution even when the approach is right. Takeaway: Understanding the approach is important, but writing clean and correct code is equally important. Making steady progress, one problem at a time. Question: Do you also find implementation harder than understanding the logic? #Day4 #LeetCode #DSA #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
🚀 Day 17/100 — LeetCode Challenge Solved Reverse Linked List At first, it feels tricky because we need to change the direction of links without losing the list. 💡 Approach (Iterative): 1) Use three pointers: prev, curr, next 2) Store the next node 3) Reverse the link (curr → prev) 4) Move all pointers forward 👉 Repeat until the list is fully reversed 💡 Key Insight: We’re not just moving through the list, we’re rebuilding it in reverse order. 🧠 Time Complexity: O(n) 💾 Space Complexity: O(1) 💡 What I learned: Linked List problems are less about logic, and more about careful pointer handling. One small mistake = broken list. #LeetCode #DSA #100DaysOfCode #Cpp #LinkedList #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 14/100 — LeetCode Challenge Solved Delete Node in a Linked List The twist? 👉 You are not given the head of the list At first, I thought deletion wouldn’t be possible without the previous node. But the trick is: 1) Copy the value of the next node 2) Point current node to next->next 3) Effectively “delete” the next node instead 💡 Key Insight: Instead of deleting the given node directly, we shift values and bypass the next node. 🧠 Time Complexity: O(1) 💾 Space Complexity: O(1) 💡 What I learned: Sometimes problems are not about applying a pattern, but about thinking differently with given constraints. Switching from patterns to concepts now. #LeetCode #DSA #100DaysOfCode #Cpp #LinkedList #CodingJourney
To view or add a comment, sign in
-
-
LeetCode Progress 37/50 — Remove Duplicates from Sorted List Today I worked on a problem focused on linked list traversal and in-place modifications 🧩 💡 The challenge was to remove duplicate nodes from a sorted linked list while preserving only one occurrence of each value. 🧠 Approach: Used pointer-based traversal to compare adjacent nodes and remove duplicates by updating links in-place whenever repeated values were found. ⏱ Time Complexity: O(n) 💡 What I learned: This problem reinforced how efficient pointer manipulation can simplify linked list operations without requiring extra space. 📈 Strengthening understanding of linked list fundamentals and improving confidence in pointer-based problem-solving. #LeetCode #DSA #LinkedList #ProblemSolving #Cpp #CodingJourney #Consistency 🚀
To view or add a comment, sign in
-
-
Day 4 🚀 Solved: Task Scheduler (LeetCode 621) This problem is about scheduling tasks with a cooldown period between identical tasks. 💡 Key idea: Always execute the task with the highest remaining frequency, while respecting the cooldown constraint. 🔹 Approach: Use a max heap to pick the most frequent task Use a queue to manage cooldown periods Simulate execution step by step ⏱️ Time Complexity: O(n log k) 🔗 GitHub: https://lnkd.in/gz_47bBz #DSA #LeetCode #Coding
To view or add a comment, sign in
-
🧠 Day 32/75: Solving for the "End" from the "Beginning" Linked Lists can be tricky because you can't access elements by index. So, how do you remove the Nth element from the back without knowing the total length? Today’s LeetCode session was a deep dive into Pointer Logic. By maintaining a specific distance between two pointers, I was able to identify and delete the target node in a single traversal. Current Progress: 📅 32 Days Consecutive 🎯 Focus: Advanced Linked List Patterns ⚡ Result: 100% Beats Runtime Another day, another problem solved. The second month is off to a strong start! 💻🔥 #Consistency #100DaysOfCode #DSA #CodingJourney #JavaDeveloper #TechGrowth #LeetCodeChallenge #LinkedInLearning
To view or add a comment, sign in
-
-
🚀 Day 45/100 – LeetCode Challenge 🔗 Problem: Linked List Components (LeetCode 817) 💡 Difficulty: Medium Today’s problem was all about understanding connected components in a linked list using a smart approach. 🧠 Key Insight: Instead of checking every possible combination, I used a HashSet for quick lookups. A component is counted only when a sequence ends, i.e., when the current node is in nums but the next node is not. ⚡ Approach: Convert nums into a set for O(1) lookup Traverse the linked list Count only when a component ends 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) ✨ What I learned: Sometimes, solving problems efficiently is about identifying where something ends rather than where it starts. Consistency is key 🔥 Halfway through the journey — staying committed! #Day45 #100DaysOfCode #LeetCode #DataStructures #LinkedList #CodingJourney #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
leetcode thoughts Learn to make proper recall while revisiting your solution Creating comment # when you got compilation error while running your code # when you do optimization # when you got Submission error (edge case error, time and space complexity issues) Create solid understanding while revisiting the code #ThoughtsFromExperience #leetcode #pattern_understanding #EffectiveLearning
To view or add a comment, sign in
-
Most people understand cycle detection… but get stuck when asked to find where the cycle starts. 🚀 Day 19/100 — LeetCode Challenge Solved Linked List Cycle II 💡 Step 1: Detect cycle -Use slow & fast pointers -If they meet → cycle exists 💡 Step 2: Find starting node -Move fast back to head -Move both one step at a time -Where they meet again → start of cycle 👉 This part is pure intuition + math 🧠 Time Complexity: O(n) 💾 Space Complexity: O(1) 💡 What I learned: Detecting a cycle is easy. Finding its starting point is where real understanding begins. This is one of those problems where you either memorize… or truly understand. Have you ever understood why this works? #LeetCode #DSA #100DaysOfCode #Cpp #LinkedList #TwoPointers #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