Day 49 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Remove All Adjacent Duplicates in String We were given a string s. Task was to remove all adjacent duplicates. If duplicates are removed, new duplicates may form. So we repeat until no duplicates remain. Example: "abbaca" → "ca" 💻 Approach (Using Stack) 🔹️Create an empty stack. 🔹️Traverse each character. 🔹️If stack is not empty and top == current character → pop 🔹️Else → push current character 🔹️At the end, build string from stack Duplicates get removed automatically. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Stack helps in handling adjacent comparisons. ▫️Removing elements can create new patterns. ▫️Single pass solution is possible with stack. ▫️String problems often map to stack operations. Day 49 completed. Almost at 50 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
Remove Adjacent Duplicates in String with Stack
More Relevant Posts
-
Day 48 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Next Greater Element We were given an array. For each element, we had to find the next greater element on the right side. If none exists → return -1. Example: [4, 5, 2, 10] → [5, 10, 10, -1] 💻 Brute Force Approach 🔹️For each element, check all elements on the right. 🔹️Find the first greater element. 🔹️If found → store it. 🔹️Else → store -1. Time Complexity: O(n²) Space Complexity: O(1) Works. But slow. 💻 Optimal Approach (Using Stack) 🔹️Traverse from right to left. 🔹️Use a stack to store elements. 🔹️For each element: ▪️Pop smaller elements from stack ▪️Top of stack = next greater element ▪️If stack empty → answer is -1 🔹️Push current element into stack Efficient. Single pass. 📊 Complexity Analysis Time Complexity: O(n) Space Complexity: O(n) 📚 What I learned today: ▫️Monotonic stack helps in nearest greater problems. ▫️Traversing from right simplifies logic. ▫️Popping smaller elements keeps stack useful. ▫️Stack stores only potential answers. Day 48 completed. Stack patterns getting stronger 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
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
-
-
🚀 Day 78 of #100DaysOfCode Today, I solved LeetCode 154 – Find Minimum in Rotated Sorted Array II, a problem that focuses on binary search and handling edge cases with duplicates. 💡 Problem Overview: Given a rotated sorted array that may contain duplicates, the goal is to find the minimum element efficiently. 🧠 Approach: ✔️ Applied modified binary search ✔️ Compared mid element with the right boundary ✔️ Carefully handled duplicate values to avoid incorrect elimination of search space This approach ensures correctness even when duplicates are present. ⚡ Key Takeaways: Binary search can be adapted for complex scenarios Duplicates introduce edge cases that must be handled carefully Choosing the correct condition is key to narrowing the search space 📊 Complexity Analysis: Time Complexity: O(log n) (average), O(n) (worst case due to duplicates) Space Complexity: O(1) Strengthening problem-solving with optimized approaches 🚀 #LeetCode #100DaysOfCode #DSA #BinarySearch #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
The Day's Particulars: #Day15 of the LeetCode Challenge 💠 Problems Conquered: Palindrome Linked List & Remove Nodes From Linked List 💠 Patterns Explored: Code Reusability, The DRY Principle, Linked List Reversal 💠 Future Notes to Self: A well-written helper method is worth its weight in gold. Writing clean, modular code means you can solve multiple complex problems with the exact same foundational logic. 𝐃𝐞𝐚𝐫𝐞𝐬𝐭 𝐆𝐞𝐧𝐭𝐥𝐞 𝐑𝐞𝐚𝐝𝐞𝐫𝐬, We have officially reached the halfway mark of this 30-day journey! Day 15 was less about learning a brand new algorithm and more about practical software engineering: the power of code reusability. Today's agenda featured two distinct challenges: 𝘗𝘢𝘭𝘪𝘯𝘥𝘳𝘰𝘮𝘦 𝘓𝘪𝘯𝘬𝘦𝘥 𝘓𝘪𝘴𝘵 𝘢𝘯𝘥 𝘙𝘦𝘮𝘰𝘷𝘦 𝘕𝘰𝘥𝘦𝘴 𝘍𝘳𝘰𝘮 𝘓𝘪𝘯𝘬𝘦𝘥 𝘓𝘪𝘴𝘵. For the Palindrome problem, the most optimal O(1) space approach is to find the middle of the list using slow and fast pointers, reverse the second half, and then compare the two halves. For the Remove Nodes problem, where you must delete any node that has a greater value to its right, the logic becomes trivial if you process the list backward. Since we only have forward pointers in a singly linked list, the solution was to reverse the entire list, iterate through to keep track of the maximum value (dropping any smaller nodes), and then reverse it back to its original state. The highlight of my day was not just securing the green "Accepted" checkmarks, but realizing that the exact same reverse() helper method was the MVP for both problems. Instead of rewriting logic, I simply extracted the list-reversal code into its own method and called it whenever needed. It was a great practical reminder of the DRY (Don't Repeat Yourself) principle. Build strong, modular pieces, and you can assemble them to solve almost anything. Halfway there, and the momentum is going strong! Yours in code, Saumya #LeetCode #DailyCoding #LinkedList #CodeReusability #JavaDeveloper #LadyWhistledown #SoftwareEngineering #dsa_stories #30daysOfCode #TechCommunity #DRYPrinciple #DataStructures #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 80 of #100DaysOfCode Today, I solved LeetCode 61 – Rotate List, a problem focused on linked list manipulation and efficient pointer handling. 💡 Problem Overview: Given the head of a linked list, the task is to rotate the list to the right by k places. 🧠 Approach: ✔️ Calculated the length of the linked list ✔️ Connected the tail to the head to form a circular list ✔️ Found the new tail position using k % length ✔️ Broke the cycle to get the rotated list This approach avoids unnecessary rotations and ensures optimal performance. ⚡ Key Takeaways: Linked list problems require strong pointer manipulation Converting problems into circular structures can simplify logic Modulo operation helps handle large values of k efficiently 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) 🎯 Day 80 Insight: Consistency over time builds confidence in solving even complex problems efficiently. On to Day 100 🚀 #LeetCode #100DaysOfCode #DSA #LinkedList #ProblemSolving #CodingJourney #SoftwareDevelopment #Consistency #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 76 of #100DaysOfCode Today, I solved LeetCode 18 – 4Sum, a classic problem that extends the two-pointer technique to higher complexity. 💡 Problem Overview: Given an array, the task is to find all unique quadruplets that sum up to a target value. 🧠 Approach: ✔️ Sorted the array to simplify processing ✔️ Fixed two elements using nested loops ✔️ Applied the two-pointer technique for the remaining two elements ✔️ Carefully handled duplicates to ensure unique quadruplets This approach efficiently reduces unnecessary computations compared to brute force. ⚡ Key Takeaways: Sorting + Two Pointers is a powerful combination Avoiding duplicates is crucial in combination problems Breaking a complex problem into smaller parts simplifies logic 📊 Complexity Analysis: Time Complexity: O(n³) Space Complexity: O(1) (excluding output) Consistently pushing boundaries and solving more complex problems 🚀 #LeetCode #100DaysOfCode #DSA #TwoPointers #ProblemSolving #CodingJourney #SoftwareDevelopment #InterviewPrep
To view or add a comment, sign in
-
-
Day 94 of #365DaysOfLeetCode Challenge Today’s focus: **Mastering Greedy + Stack Patterns** After solving problems like *Remove K Digits*, one thing is becoming clear — a lot of “hard-looking” problems become easier when you recognize the **pattern behind them**. 💡 **Today’s Learning:** Instead of jumping into code, I spent time identifying: * When to use **Greedy** * When a **Stack** can simplify decisions * How to think in terms of **local vs global optimum** 📌 **Key Insight:** Many problems follow this idea: 👉 *“If the current choice is better than the previous one, fix it immediately.”* This applies to: * Removing digits (monotonic stack) * Stock span problems * Next greater/smaller elements * Histogram problems ⚡ **Mindset Upgrade:** Earlier → “Try all possibilities” Now → “What is the best decision I can make right now?” **What I learned today:** Data Structures are not just tools — they are **decision-making frameworks**. Day 94 done The journey is slowly shifting from *solving problems* → to *thinking like an engineer*. #LeetCode #DSA #CodingChallenge #Greedy #Stack #ProblemSolving #TechJourney #Consistency
To view or add a comment, sign in
-
-
Just crossed 100 problems solved on LeetCode. Not impressive by itself—but what matters is consistency. Most of these came from sticking to fundamentals like arrays, two pointers, and basic problem patterns instead of jumping around randomly. Current focus: • Strengthening problem-solving patterns • Reducing time per problem • Moving from Easy → Medium consistently Still a long way to go. Next target: 200 with stronger Medium coverage. If you're grinding LeetCode too, focus less on quantity and more on pattern recognition—it compounds faster. #LeetCode #DSA #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
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