🚀 Day 18 of #100DaysOfCode Solved Remove Duplicates from Sorted List II on LeetCode 🔗 🧠 Key insight: When duplicates appear in a sorted linked list, we need to remove all occurrences, not just one. Using a dummy (sentinel) node makes it easier to handle cases where duplicates start at the head. ⚙️ Approach: 🔹Create a dummy node pointing to the head 🔹Traverse the list with two pointers 🔹If a duplicate sequence is found, skip the entire block 🔹Otherwise, move forward normally ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
Remove Duplicates from Sorted List II on LeetCode
More Relevant Posts
-
🚀 Day 19 of #100DaysOfCode Solved 2. Add Two Numbers on LeetCode ➕🔗 (in-place linked list approach) 🧠 Key insight: Instead of creating a new list, we can reuse the longer linked list and perform addition in place, handling carry carefully across nodes. ⚙️ Approach: 🔹Calculate the size of both linked lists 🔹Use the longer list as the result list 🔹Traverse both lists, adding values with carry 🔹Continue processing remaining nodes of the longer list 🔹Append a new node if a carry remains at the end ⏱️ Time Complexity: O(max(n, m)) 📦 Space Complexity: O(1) (no extra list created) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
Solved "Container With Most Water" on LeetCode today using the Two-Pointer Technique. 🚀 The key insight is that the area formed by two lines depends on the shorter height and the distance between them. Starting with pointers at both ends of the array, we compute the area and move the pointer at the smaller height inward to potentially find a taller boundary and maximize the area. This approach efficiently reduces the problem from O(n²) brute force to O(n) time with O(1) space. Problems like this are a great reminder that the right observation can drastically optimize a solution. 💡 #LeetCode #DSA #TwoPointers #Java #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 25 of #100DaysOfCode Solved 24. Swap Nodes in Pairs on LeetCode 🔗🔄 🧠 Key insight: Swapping nodes in a linked list doesn’t require extra memory—careful pointer updates are enough to reverse every adjacent pair. ⚙️ Approach: 🔹Traverse the list two nodes at a time 🔹Reverse links between each adjacent pair 🔹Maintain connections with the previous pair to keep the list intact 🔹Handle edge cases for odd-length lists ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 42 of #100DaysOfCode 🌱 Topic: Linked List / Two Pointers ✅ Problem Solved: LeetCode 82 – Remove Duplicates from Sorted List II 🛠 Approach: Used a dummy node to simplify handling edge cases where the head might be removed. When two consecutive nodes had the same value, stored that value. Skipped all nodes with that duplicate value using a loop. Linked the previous node to the next distinct node. Continued traversal until reaching the end. This ensures that only unique elements remain in the sorted list. #100DaysOfCode #Day42 #DSA #LinkedList #TwoPointers #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfCode 🌱 Topic: Linked List / Recursion ✅ Problem Solved: LeetCode 24 – Swap Nodes in Pairs 🛠 Approach: Used a recursive approach to swap every two adjacent nodes in the linked list. If the list has 0 or 1 node, return it directly (base case). Store the second node (head.next) as a temporary node. Recursively swap the remaining list starting from temp.next. Adjust pointers so the second node becomes the new head of the pair. Connect the swapped pair with the recursively processed list. This swaps nodes without modifying their values, only changing pointers. #100DaysOfCode #Day38 #DSA #LinkedList #Recursion #LeetCode #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 28 of #100DaysOfCode Solved 148. Sort List on LeetCode 🔗📊 🧠 Why this problem is interesting: Arrays are easy to sort, but linked lists don’t allow random access. That’s why Merge Sort becomes the perfect choice here. ⚙️ Approach (Merge Sort on Linked List): 🔹Use slow & fast pointers to find the middle 🔹Split the list into two halves 🔹Recursively sort both halves 🔹Merge two sorted linked lists ⏱️ Time Complexity: O(n log n) 📦 Space Complexity: O(log n) (recursive stack) #100DaysOfCode #LeetCode #DSA #LinkedList #MergeSort #Java #ProblemSolving #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 15/100 – LeetCode Challenge Problem: Reverse Linked List Today’s problem focused on reversing a singly linked list using an iterative approach. Approach: Used three pointers to reverse the links: prev → keeps track of the previous node curr → current node being processed next → stores the next node before changing the link Steps: Store curr.next in next Reverse the link → curr.next = prev Move prev and curr one step forward Continue until the list ends. Finally, prev becomes the new head of the reversed list. Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List pointer manipulation Iterative reversal technique In-place algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 33 of #100DaysOfCode Solved 25. Reverse Nodes in K-Group on LeetCode 🔁 🧠 Key Idea: Reverse nodes of a linked list k at a time, while keeping the remaining nodes unchanged if they are fewer than k. ⚙️ Approach: 🔹Traverse the list to check if k nodes exist. 🔹If fewer than k nodes remain → return the list as it is. 🔹Reverse the current k-group using a helper reverse function. 🔹Recursively apply the same logic to the remaining list. 🔹Connect the reversed group with the result of the recursive call. This approach makes the solution clean and modular by separating the logic of: 🔹Finding k nodes 🔹Reversing a segment 🔹Connecting segments ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n/k) (due to recursion stack) #100DaysOfCode #LeetCode #DSA #LinkedList #Java #ProblemSolving #CodingJourney #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 39 of #100DaysOfCode Solved 80. Remove Duplicates from Sorted Array II on LeetCode 🔢 🧠 Key Insight: The array is already sorted, and we need to ensure that each element appears at most twice, modifying the array in-place. ⚙️ Approach: 🔹Maintain a pointer i representing the position to place the next valid element 🔹Start iterating from index 2 🔹For each element nums[j], compare it with nums[i] 🔹If they are different, place the element at nums[i + 2] and move the pointer forward This ensures that no element appears more than twice while maintaining the sorted order. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #Arrays #TwoPointers #Java #ProblemSolving #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
Day 13/100 – LeetCode Challenge Problem: Linked List Cycle Today’s problem was about detecting whether a cycle exists in a linked list. Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise and Hare). slow pointer moves one step fast pointer moves two steps If a cycle exists, both pointers will eventually meet If fast reaches null, the list has no cycle Complexity: Time: O(n) Space: O(1) Concepts Practiced: Linked List traversal Two-pointer technique Cycle detection algorithm #100DaysOfCode #LeetCode #DSA #Java #LinkedList #ProblemSolving #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