LeetCode Problem Solved | #1209. Remove All Adjacent Duplicates in String II Today I worked on LeetCode 1209, which is a great extension of the classic adjacent-duplicate problem and a perfect example of the stack pattern in DSA. 🧠 Problem Summary Given a string s and an integer k, repeatedly remove k adjacent identical characters until no more removals are possible. Example: Input: s = "deeedbbcccbdaa", k = 3 Output: "aa" 💡 Approach (Using Stack) 1. Traverse the string character by character 2. If the current character matches the stack top -> increment count 3. If count reaches k -> pop from stack 4. Otherwise -> push a new Pair 5 .Finally, rebuild the string from the stack #LeetCode #DSA #Java #Stack #ProblemSolving #CodingPractice
LeetCode 1209: Remove Adjacent Duplicates in String II
More Relevant Posts
-
Day 22 of Daily DSA 🚀 Solved LeetCode 66: Plus One ✅ Approach: Treat the array as a number and simulate addition from the last digit: • If the last digit is not 9, increment and return • Handle carry by setting 9 → 0 and moving left • If all digits are 9, create a new array with leading 1 This avoids converting the array into an integer and handles large numbers safely. ⏱ Complexity: • Time: O(n) • Space: O(1) (extra array only when overflow happens) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.58 MB (Beats 38.49%) A simple problem that tests edge-case thinking 💡 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 Day 80 of #100DaysOfCode Solved LeetCode Problem #1653 – Minimum Deletions to Make String Balanced ✅ A clean greedy + DP-style problem that looks simple but really tests decision-making at each step. The trick is choosing whether to delete a character now or rely on previous counts to minimize total deletions. Key Takeaways: -> Greedy decisions can be optimized with running state -> Tracking counts (bCount) simplifies future choices -> Sometimes the best DP is just two variables -> Elegant logic beats complex data structures Language: Java -> Runtime: 19 ms (Beats 93.09%) ⚡ -> Memory: 47.80 MB Showing up daily, sharpening logic, and trusting the process. 💻🔥 #LeetCode #Java #Greedy #DynamicProgramming #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 117 🚀 | LeetCode Progress Solved 3 problems today and strengthened array manipulation skills 💪 📌 Problem 1: Sort Array By Parity (#905) – 🟢 Easy 👉 Two-pointer / index swapping technique 👉 Place even numbers at the front while iterating 👉 In-place solution with O(1) extra space 👉 Time Complexity: O(n) Efficient way to partition arrays without extra memory ⚡ 📌 Problem 2: Find All Numbers Disappeared in an Array (#448) – 🟢 Easy 👉 Index marking technique using negative values 👉 Mark visited indices by flipping the sign 👉 Positive indices at the end represent missing numbers 👉 Time: O(n) | Space: O(1) (excluding result list) A clever trick to use the array itself as a hash map 🧠 📌 Problem 3: Minimum Changes to Make an Alternating Binary String (#1758) – 🟢 Easy 👉 Compare with two possible patterns: "010101..." and "101010..." 👉 Count mismatches for both patterns 👉 Return the minimum operations needed 👉 Time Complexity: O(n) Simple logic but great practice for pattern-based string problems 🔍 Small improvements every day lead to big progress over time 📈 #Day117 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #GeekStreak #100DaysOfCod
To view or add a comment, sign in
-
Day 9 of Daily DSA 🚀 Solved LeetCode 334: Increasing Triplet Subsequence ✅ 🔍 Approach: Implemented a greedy single-pass solution by tracking the smallest (a) and second smallest (b) and another smallest (c)values seen so far. Update a if a smaller value appears Update b if the value is greater than a but smaller than b If a value greater than both is found → update c → triplet exists No extra arrays, no sorting—just clean logic. ⏱ Complexity: • Time: O(n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 2 ms (Beats 98.96%) ⚡ • Memory: 122.66 MB (Beats 56.98%) Great example of how a simple greedy observation make clean solution. #DSA #LeetCode #Java #GreedyAlgorithm #ProblemSolving #Consistency #DailyCoding
To view or add a comment, sign in
-
-
Day 60/100 – LeetCode Challenge ✅ Problem: #67 Add Binary Difficulty: Easy Language: Java Approach: Reverse Iteration with Carry Time Complexity: O(max(n, m)) Space Complexity: O(max(n, m)) Key Insight: Binary addition follows same rules as decimal: Sum bits + carry Result bit = sum % 2 New carry = sum / 2 Solution Brief: Iterated from rightmost bits of both strings. Tracked carry and built result from right to left using StringBuilder. Reversed final string for correct order. #LeetCode #Day60 #100DaysOfCode #Binary #Java #Algorithm #CodingChallenge #ProblemSolving #AddBinary #EasyProblem #StringManipulation #BitManipulation #DSA
To view or add a comment, sign in
-
-
LeetCode 1752 — Check if Array Is Sorted and Rotated Solved another array logic problem today. At first it looked simple, but the real task was to observe the pattern in order changes, not just compare numbers blindly. Approach I used: - counted how many times the order breaks (nums[i] > nums[i+1]) - if it breaks more than once → not sorted & rotated - if it breaks once → last element must still fit before the first - otherwise → already sorted Result : Accepted Runtime : 0 ms What this problem made clear: - many array problems are really about pattern detection - a small logical observation can replace complex code - edge cases decide whether the solution is correct or not Small step, but clear learning. Continuing the grind. #LeetCode #DSA #Arrays #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 81 of #100DaysOfCode Solved LeetCode Problem #110 – Balanced Binary Tree ✅ A classic tree problem that rewards thinking bottom-up. Instead of recalculating heights repeatedly, combining height computation with balance checking makes the solution both clean and efficient. Key Takeaways: -> Bottom-up recursion simplifies tree problems -> Early termination saves unnecessary computation -> Returning sentinel values (-1) is a powerful pattern -> One DFS can solve both height & balance checks Language: Java -> Runtime: 0 ms (Beats 100%) ⚡ -> Memory: 45.76 MB Staying consistent, one tree at a time. 🌳💻🔥 #LeetCode #Java #BinaryTree #Recursion #DFS #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 36 of #100DaysOfLeetCode ✅ Solved: Plus One (LeetCode 66) Difficulty: Easy Status: Accepted (114/114 Testcases Passed) Runtime: 0 ms 💯 Today’s problem looked simple but reinforced an important concept — handling carry in arrays. 🧠 Problem Summary: We are given a large integer represented as an array of digits. We need to increment the number by one and return the updated array. 🔎 Key Insight: Start from the last digit (right to left): If digit < 9 → increment and return. If digit == 9 → set it to 0 and carry over. If all digits are 9 → create a new array with an extra digit at the beginning. 💡 Example: Input: [9,9,9] Output: [1,0,0,0] 🎯 What I Practiced Today: Reverse traversal of arrays Carry-forward logic Edge case handling (all 9s case) Writing optimized O(n) solution Even easy problems strengthen fundamentals when you focus on edge cases. Consistency > Complexity. 🔥 #Day36 #100DaysOfCode #LeetCode #Java #DataStructures #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 #100DaysOfCode | Day 41 💻 LeetCode – Add to Array-Form of Integer Today I solved a problem focused on array manipulation and digit-by-digit addition. 🔎 Problem: An integer is given in array form, where each element represents a digit. The task is to return the array representation of num + k. 💡 Approach: Instead of converting the array into a number, I simulated manual addition from the last digit, just like we do on paper. ✔ Traverse the array from right to left ✔ Add digits with k and manage the carry ✔ Store the result digits and reverse at the end This approach efficiently handles large inputs and avoids integer overflow. Small problems like this strengthen logic building and problem-solving skills. #LeetCode #DSA #100DaysOfCode #ProblemSolving #Java #CodingJourney #SoftwareDeveloper #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 73/100 of my DSA Journey ✅ Problem solved today: LeetCode 1461 – Check If a String Contains All Binary Codes of Size K 🧠 What I focused on: Using a HashSet to store all substrings of length k Sliding window technique to generate substrings efficiently Understanding why we only need to check if the number of unique substrings equals 2^k Handling edge cases when string length is smaller than k This problem nicely combined strings + sliding window + hashing logic. 📌 Key takeaway: Sometimes the solution is just counting unique patterns efficiently. 📈 Day 73 done. Consistency continues. #LeetCode #DSA #SlidingWindow #Strings #Hashing #Java #ProblemSolving #Consistency #LearningInPublic #100DaysOfCode
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
Why not make this available in a text format? A photograph of code is as useful to a programmer as a menu to a starving person.