🌟 Day 39 of #100DaysOfCode 🌟 🔍 Exploring String Simplification — Removing Duplicates with Precision 🔹 What I Solved Today’s challenge was about simplifying strings by repeatedly removing adjacent duplicate characters until no more exist. A great exercise in stack logic and string manipulation efficiency — proving that small, precise steps can clean up even the messiest data. 🧩 Problem: Remove All Adjacent Duplicates in String 💡 Problem Statement Given a string s, repeatedly remove two adjacent equal letters until none remain. Return the final string after all such duplicate removals. 💡 Example 1: Input: "abbaca" → Output: "ca" Explanation: Remove "bb" → "aaca" → remove "aa" → "ca" 💡 Example 2: Input: "azxxzy" → Output: "ay" 🧠 Concepts Used Stack-based String Processing Iteration & Character Comparison Optimized Linear Solution → O(n) Time, O(n) Space ⚙️ Approach 1️⃣ Use a StringBuilder as a stack. 2️⃣ Traverse each character: • If the current char equals the top of the stack → pop it. • Else → push it. 3️⃣ Return the resulting string from the stack. 🚀 What I Learned ✨ Stack patterns shine even in string problems. ✨ Clean, efficient logic leads to readable and reliable solutions. ✨ Removing redundancy — in code or mindset — leads to clarity. 💬 Reflection Today’s lesson reminded me that refining logic is just like refining thoughts — remove the noise, and the solution becomes clear. #100DaysOfCode #Day39 #StringManipulation #RemoveDuplicates #Java #CodingJourney
"Day 39 of #100DaysOfCode: Simplifying Strings with Stack Logic"
More Relevant Posts
-
🔥 Day 35/100 of #100DaysOfCode - Finding Longest Sequence! Today's Problem: Longest Consecutive Sequence Task: Find the length of the longest consecutive elements sequence in an unsorted array. Solution: Used a HashSet for O(1) lookups! First added all elements to the set, then for each number, checked if it's the start of a sequence (no num-1 in set). If yes, counted consecutive numbers ahead. Key Insights: O(n) time complexity by only checking sequence starters HashSet eliminates duplicates and provides fast lookups Avoids O(n log n) sorting approach Smart Optimization: Only begins counting from sequence starting points Each number is processed at most twice (visited in set iteration + sequence counting) Handles duplicates and empty arrays gracefully Elegant solution that transforms an O(n²) brute force into O(n) using smart data structure choice! 💡 #100DaysOfCode #LeetCode #Java #Algorithms #HashSet #Arrays #CodingInterview
To view or add a comment, sign in
-
-
🚀 Day 46 of #100DaysOfCode – Striver’s DSA Sheet 🚀 ✅ Topic Covered Today: Implement Queue Using Linked List 💡 Lesson of the Day (Approach-Focused): 🔹 Understanding the Core Idea A queue follows FIFO (First In, First Out) order. Using a Linked List, we maintain dynamic memory and perform operations efficiently with two pointers: front → points to the first node rear → points to the last node This avoids the limitations of fixed-size arrays. 🔹 1️⃣ Enqueue (Insert at Rear) Approach: Create a new node If queue is empty → front = rear = newNode Else → attach newNode at rear.next and move rear forward 🧮 Time Complexity: O(1) 💾 Space Complexity: O(1) extra 🔹 2️⃣ Dequeue (Remove from Front) Approach: If empty → nothing to remove Return node at front Move front = front.next If queue becomes empty → rear = null 🧮 Time Complexity: O(1) 🔹 3️⃣ Peek Return front.data without removing it. 🧮 Time Complexity: O(1) 🔹 4️⃣ isEmpty Check: front == null 🧮 Time Complexity: O(1) ✨ Key Idea: A linked-list-based queue never overflows (unless memory is full) and supports constant-time insertions and deletions — perfect for dynamic data scenarios. 💭 Learning: Today’s implementation strengthened my understanding of pointers and dynamic memory. Building a queue with linked nodes is a great way to visualize how real queue structures work behind the scenes. #100DaysOfCode #DSA #StriversSheet #Java #LinkedList #Queue #ProblemSolving #CodingJourney #LogicBuilding #Consistency
To view or add a comment, sign in
-
-
🚀 Day 45 of #100DaysOfCode – Striver’s DSA Sheet 🚀 ✅ Topic Covered Today: Implement Queue Using Array 💡 Lesson of the Day (Approach-Focused): 🔹 Understanding the Core Idea A queue follows FIFO (First In, First Out) order. Using an array, we simulate this behavior by maintaining: front pointer (f) → points to the first element rear pointer (r) → points to the last inserted element size / capacity → fixed array length 🔹 1️⃣ Enqueue (Insert) Check if queue is full → rear == size - 1 Increment rear Insert element at arr[rear] 🧮 Time Complexity: O(1) 💾 Space Complexity: O(1) extra 🔹 2️⃣ Dequeue (Remove) Check if queue is empty → front == -1 Return element at arr[front] Move front forward If queue becomes empty again → reset front = rear = -1 🧮 Time Complexity: O(1) 🔹 3️⃣ Peek Return arr[front] without removing it. 🧮 Time Complexity: O(1) 🔹 4️⃣ isEmpty / isFull isEmpty: front == -1 isFull: rear == size - 1 ✨ Key Idea: Implementing a queue using an array helps understand pointer movement, memory management, and why sometimes a circular queue is needed when fixed arrays cause unused space. 💭 Learning: Today strengthened my understanding of how queues work under the hood and how core operations actually use pointer updates — a great foundation before moving to circular queues and deque structures. #100DaysOfCode #DSA #StriversSheet #Java #Queue #Arrays #ProblemSolving #CodingJourney #LogicBuilding #Consistency
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 66 String Manipulation & Primitive Decomposition 🧩 Task: Given a valid parentheses string, decompose it into its primitive components and then remove the outermost parentheses from each component. Example: Input: s = "(()())(())" Primitive Decomposition: "(()())" + "(())" After removing outermost parentheses: "()()" + "()" Output: "()()()" My Approach: I iterated through the string while keeping a counter to track the balance of open parentheses. When an opening parenthesis ( was found, I incremented the counter. If the count was greater than 1, it meant this parenthesis was not an outermost one, so I appended it to the result. When a closing parenthesis ) was found, I only appended it if the counter was greater than 1 before decrementing. This ensures the final closing parenthesis of a primitive part is excluded. This simple counter-based approach effectively identifies and removes the correct parentheses without needing a more complex data structure like a stack. Time Complexity: O(N) Space Complexity: O(N) Sometimes, a simple counter is all you need to elegantly handle nested structures. It can be a clean and efficient alternative to more complex data structures for certain problems. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #DataStructures #Algorithms #StringManipulation #CodeNewbie
To view or add a comment, sign in
-
-
🚀 Day 62 – In-Place Array Filtering with Clean Two-Pointer Logic 🧩 Problem: 27. Remove Element The task is to remove all occurrences of a given value from the array in-place and return the new valid length. Only the first k elements matter after removal, and we must avoid using extra space making this a good test of controlled index manipulation. 🧠 Approach To solve this efficiently, I used an insertion-based two-pointer strategy, which ensures both clarity and optimal performance. I maintained an insertPos pointer that always marks the next position where a valid element should be placed. As I iterated through the array, every element that wasn’t equal to the given value was copied to this position, and the pointer moved forward. This approach ensures: 👉 A single linear pass through the array 👉 Strict in-place modification 👉 Clean separation of valid and removed elements Full control over the final valid length The resulting length is simply the total size minus the number of removed elements, giving a direct and efficient solution. This method clearly shows structured thinking, control over memory usage, and the ability to simplify a problem into predictable pointer movements — exactly what strong algorithmic reasoning looks like. 🔗 Problem Link: https://lnkd.in/gAakjJqC 🔗 GitHub Link: https://lnkd.in/gCe-A-Ev 💡 Reflection: Working on this problem reminded me how powerful a simple pointer and a clear goal can be. Not every challenge needs complex logic sometimes the cleanest solutions come from knowing exactly how you want the data to look and moving toward it step by step. This problem reinforced the value of in-place changes, memory efficiency, and how clean thinking leads to clean code. #LeetCode #Arrays #TwoPointers #InPlaceAlgorithm #Java #Day62 #CodingJourney #100DaysChallenge #ProblemSolving #LearningEveryday #CleanCode
To view or add a comment, sign in
-
-
🚀 Day 416 of #500DaysOfCode Problem: 1513. Number of Substrings With Only 1s Platform: LeetCode – Medium Today’s challenge was a classic binary-string problem that focuses on counting substrings composed only of '1' characters. Sounds simple—but with constraints up to 100,000 characters, brute force is impossible. 🔍 What I Learned The key insight is: Whenever you find a continuous streak of 1s of length k, it contributes: k⋅(k+1)2\frac{k \cdot (k+1)}{2}2k⋅(k+1)substrings made only of 1s. Example: 111 → • "1" (3 times) • "11" (2 times) • "111" (1 time) Total = 6 So instead of checking all substrings, we just: ➡️ Count lengths of 1-streaks ➡️ Use the formula ➡️ Keep sum modulo 1e9+7 🧠 Why This Problem Is Useful Builds intuition for pattern-counting in strings Reinforces how mathematical optimization replaces brute-force loops Helps in understanding frequency-based substring logic 📌 Output Examples Input: "0110111" → Output: 9 Input: "101" → Output: 2 Input: "111111" → Output: 21 💡 Reflection Simple logic + clever math = powerful optimization. This problem reminded me how often the pattern matters more than the individual characters. #500DaysOfCode #Day416 #LeetCode #Java #CodingJourney
To view or add a comment, sign in
-
-
🌟 Day 31 of #100DaysOfCode 🌟 🔍 Backspace String Compare — Stack Logic & Two-Pointer Optimization 🔹 What I Solved Today, I solved the “Backspace String Compare” problem — an elegant challenge that simulates typing behavior in text editors. The twist? The # symbol acts as a backspace, and we must determine if two strings are equal after applying all backspaces. 📝 Problem Statement Given two strings s and t, return true if they are equal when both are typed into empty text editors. # means a backspace character. Example 1: Input: s = "ab#c", t = "ad#c" Output: true Explanation: Both become "ac". Example 2: Input: s = "ab##", t = "c#d#" Output: true Explanation: Both become "". Example 3: Input: s = "a#c", t = "b" Output: false Explanation: s = "c", t = "b". 🧠 Concepts Used Stack / StringBuilder for backspace simulation Character traversal from left to right Two-pointer optimization (O(1) space approach) String manipulation & comparison ⚙️ Approach 1️⃣ Traverse each string and simulate typing: • If the character isn’t #, add it. • If it’s #, remove the last character (if present). 2️⃣ Compare the final processed versions of both strings. 3️⃣ Alternatively, use a two-pointer approach from the end for constant space optimization. 🚀 What I Learned Small-looking problems can teach efficient simulation techniques. Understanding string traversal logic is crucial for interview-ready problem solving. #100DaysOfCode #Java #ProblemSolving #CodingJourney #LeetCode #Algorithms #Strings #Stack #TwoPointers #CodingChallenge #KeepBuilding
To view or add a comment, sign in
-
-
🚀 Day 28 of #100DaysOfCode Today’s challenge was all about understanding frequency patterns in arrays — a simple yet powerful concept in hashing 🔍 LeetCode 1207 – Unique Number of Occurrences 🔢 📌 Problem Summary: Given an integer array, determine whether each value appears a unique number of times. In other words, 👉 No two numbers should share the same frequency. 💡 Example: Input: [1,2,2,1,1,3] Output: true Because frequencies are: 1 → 3 times 2 → 2 times 3 → 1 time All unique ✔️ 🧠 My Approach: I solved it using a combination of HashMap + HashSet: 1️⃣ Count the occurrences of each number using a HashMap. 2️⃣ Insert all frequency values into a HashSet. 3️⃣ If the size of the HashSet equals the size of the map → all frequencies are unique ✔️ 4️⃣ Otherwise → duplicates exist ❌ A clean and efficient hashing technique. ⚙️ Complexity: Time: O(n) ⏱️ Space: O(n) 💾 (storing frequencies) 💡 Key Learning: HashMaps aren’t just for storing counts—they can reveal patterns, validations, and uniqueness constraints when combined with sets. This problem reinforced how frequency-based logic solves many real-world scenarios like: ✔ Detecting duplicates ✔ Comparing patterns ✔ Character/string analysis ✔ Data validation 🔥 Result: Code ran successfully with 0 ms Runtime, accepted on the first attempt! Small challenge, clean logic, satisfying finish 💪 On to the next one! 🚀 #100DaysOfCode #LeetCode #HashTable #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 121 of My DSA Challenge – Remove Duplicates from Sorted List 🔷 Problem : 83. Remove Duplicates from Sorted List 🔷 Goal : Given the head of a sorted linked list, remove all duplicate nodes so that each element appears only once, while maintaining the sorted order. 🔷 Key Insight : This problem is a great example of linked list traversal and pointer management. Because the list is already sorted, all duplicates appear consecutively — which makes it easy to detect and skip them in one pass. The challenge is to handle links carefully so that only unique nodes remain connected. 🔷 Approach : 1️⃣ Initialize a dummy node (with a distinct value) to simplify linking. 2️⃣ Use a tail pointer to build a new list containing only unique elements. 3️⃣ Traverse the list using head: If head.val is not equal to the last added node (tail.val), link it. Otherwise, skip the duplicate. 4️⃣ Update tail.next = null at the end to avoid leftover links. 5️⃣ Return dummy.next as the new head. Time Complexity: O(n) Space Complexity: O(1) This problem strengthens concepts of : ✅ Duplicate handling in linked lists ✅ Pointer-based traversal ✅ Clean in-place modification Sometimes, cleaning a data structure is just about connecting only what truly matters. ⚡ Every small pattern makes a big difference in problem-solving clarity. One more concept locked in 💻 #Day121 #DSA #100DaysOfCode #LeetCode #Java #LinkedList #ProblemSolving #Algorithms #DataStructures #CodingChallenge #DeveloperJourney #EngineerMindset #GrowEveryday
To view or add a comment, sign in
-
-
🔥 Day 36/100 of #100DaysOfCode - Matrix Zero Transformation! Today's Problem: Set Matrix Zeroes Task: Given an m x n matrix, if an element is 0, set its entire row and column to 0s. Must be done in-place. Solution: Used the optimal O(1) space approach! Leveraged the first row and first column as markers to track which rows/columns need to be zeroed, with a separate variable for column 0. Key Steps: Mark zeros in first row/column while preserving original state Process inner matrix using the markers Zero rows/columns based on markers Smart Optimizations: Uses matrix itself for storage instead of extra O(m+n) space Handles edge case for first column separately Single pass for marking + two passes for execution Advanced matrix manipulation that demonstrates deep understanding of in-place algorithms! Perfect example of trading complexity for optimal space usage. 🧩 #100DaysOfCode #LeetCode #Java #Algorithms #Matrix #InPlace #CodingInterview
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