🔥 Day 120 of My DSA Challenge – Remove Linked List Elements 🔷 Problem : 203. Remove Linked List Elements 🔷 Goal : Remove all nodes from a linked list whose value equals a given val, and return the updated head. 🔷 Key Insight : This problem focuses on Linked List traversal and pointer manipulation, one of the most fundamental concepts in data structures. Directly removing nodes from a linked list can get tricky, especially when dealing with the head node itself. To simplify this, we use a dummy node technique — a smart approach to handle head removals gracefully. 🔷 Approach : 1️⃣ Create a dummy node (dummy) that points to the start of the list. 2️⃣ Use a pointer (tail) to build a new filtered list. 3️⃣ Traverse the original list using head: If head.val != val, link it to the new list. Otherwise, skip the node. 4️⃣ After traversal, ensure tail.next = null to avoid cycles. 5️⃣ Return dummy.next (new head). Time Complexity: O(n) Space Complexity: O(1) This problem reinforces : ✅ Pointer management ✅ Dummy node usage ✅ Clean and safe linked list manipulation When handling linked lists, think in pointers — not positions. Efficient traversal and clean linking make all the difference. ⚡ 120 days strong. One more concept mastered, one step closer to mastery. 🚀 #Day120 #DSA #100DaysOfCode #LeetCode #Java #LinkedList #Pointers #ProblemSolving #Algorithms #DataStructures #CodingChallenge #DeveloperJourney #EngineerMindset #LogicBuilding
"Day 120 of DSA Challenge: Removing Linked List Elements"
More Relevant Posts
-
🔥 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 122 of My DSA Challenge – Delete Node in a Linked List 🔷 Problem : 237. Delete Node in a Linked List 🔷 Goal : Delete a given node from a singly linked list — but without having access to the head of the list. 🔷 Key Insight : This is one of those classic Linked List interview questions that tests conceptual understanding over coding complexity. Normally, to delete a node, we need access to its previous node (to change the next pointer). But here, we’re not given the head — only the node that must be deleted. So how do we “delete” it? By using a clever trick — 👉 Copy the value of the next node into the current node. 👉 Then skip the next node (effectively deleting it). 🔷 Approach : 1️⃣ Overwrite the current node’s value with the value of its next node. 2️⃣ Link the current node’s next pointer to node.next.next. 3️⃣ This effectively removes the “next” node from the chain, achieving deletion without needing the head reference. Time Complexity: O(1) Space Complexity: O(1) This problem beautifully demonstrates data overwriting and pointer manipulation in linked lists. Sometimes, deleting isn’t about removing — it’s about replacing smartly. ⚡ Concepts reinforced : ✅ In-place modification ✅ Node manipulation ✅ Understanding memory links in Linked Lists Every concept — from arrays to linked lists — builds a deeper sense of logic and problem-solving clarity. #Day122 #DSA #100DaysOfCode #LeetCode #Java #LinkedList #ProblemSolving #Algorithms #DataStructures #CodingChallenge #DeveloperJourney #EngineerMindset #GrowEveryday #Learning
To view or add a comment, sign in
-
-
🔥 Day 117 of My DSA Challenge – Partition Array According to Given Pivot 🔷 Problem : 2161. Partition Array According to Given Pivot 🔷 Level : Medium 🔷 Goal : Rearrange an array so that — 1️⃣ Elements less than the pivot come first 2️⃣ Elements equal to the pivot come next 3️⃣ Elements greater than the pivot come last …and maintain relative order for smaller and larger elements. 🔷 Key Idea : The problem is a great test of array manipulation and partitioning logic — similar to what we see in the partition step of quicksort, but here the order must be stable (unchanged for equal categories). We can solve it cleanly using extra space and multiple passes: First collect elements < pivot Then elements == pivot Finally elements > pivot 🔷 Approach : 1️⃣ Initialize a result array res of same size. 2️⃣ Keep two pointers — left starts from the beginning for smaller elements. right starts from the end for larger elements. 3️⃣ Fill smaller elements from the start. 4️⃣ Fill larger elements from the end (in reverse order). 5️⃣ Fill the middle portion with the pivot. Time Complexity: O(n) Space Complexity: O(n) This problem strengthens your understanding of partitioning logic, stable ordering, and array construction — all fundamental to sorting algorithms and data arrangement. Small rearrangements. Big insights. Every element has its right place — in arrays and in life. ⚡ #Day117 #DSA #100DaysOfCode #LeetCode #Java #Arrays #ProblemSolving #CodingChallenge #Algorithms #DataStructures #LearningJourney #CodeEveryday #DeveloperMindset #EngineerInProgress
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 125 of My DSA Challenge – Remove Nth Node From End of List 🔷 Problem : 19. Remove Nth Node From End of List 🔷 Goal : Remove the nth node from the end of a singly linked list and return the updated head. 🔷 Key Insight : This is one of the most famous linked list problems — and a backbone of many interview questions. The trick is to use the two-pointer approach: Move fast pointer n steps ahead Then move both slow and fast together When fast reaches the end, slow will be at the node to delete Use prev pointer to relink the list safely This avoids counting the length and solves it in one pass. 🔷 Approach : 1️⃣ Edge case: If the list has only one node → return null 2️⃣ Move fast pointer n-1 steps ahead 3️⃣ Move slow + fast together until fast reaches the last node 4️⃣ Track the node before slow using prev 5️⃣ If prev == null, it means we need to delete the head 6️⃣ Else, connect prev.next = slow.next 7️⃣ Return the updated head Time Complexity: O(n) Space Complexity: O(1) This problem strengthens your understanding of : ✅ Slow–fast pointer technique ✅ Handling edge cases in linked lists ✅ Deleting nodes efficiently in a single traversal When solving linked list problems, smart pointer movement often beats brute force. ⚡ Keep going — your foundation is becoming stronger every day. 🚀💻 #Day125 #DSA #100DaysOfCode #LinkedList #Java #LeetCode #ProblemSolving #Algorithms #DataStructures #DeveloperJourney #EngineerMindset #CodingLife
To view or add a comment, sign in
-
-
Data Structure and Algorithms Merge Two Sorted Lists For my lab assignment, I solved the LeetCode problem “Merge Two Sorted Lists” using C++ linked lists and pointer manipulation. 🔹 Approach I Used: I compared the starting nodes of both lists, picked the smaller one as the head, and then iteratively attached the next smallest nodes using a pointer (curr). When one list ended, I simply linked the remaining nodes of the other list to complete the merge efficiently. 🔹 Key Concepts: Linked Lists Pointer updates Iterative merging Time Complexity: O(n + m) This assignment really helped me improve my understanding of linked list traversal and handling edge cases. 🎥 Video Explanation: [https://lnkd.in/df6nZs3w] Note: At first I thought merging lists would merge me instead but thankfully only the code struggled, not me! #DSA #LabAssignment #LeetCode #C++ #CodingPractice #ProblemSolving #MergeTwoSortedLists
To view or add a comment, sign in
-
Data Structure and Algorithms Merge Two Sorted Lists. For my lab assignment, I solved the LeetCode problem “Merge Two Sorted Lists” using C++ linked lists and pointer manipulation. 🔹 Approach I Used: I compared the starting nodes of both lists, picked the smaller one as the head, and then iteratively attached the next smallest nodes using a pointer (curr). When one list ended, I simply linked the remaining nodes of the other list to complete the merge efficiently. 🔹 Key Concepts: Linked Lists Pointer updates Iterative merging Time Complexity: O(n + m) This assignment really helped me improve my understanding of linked list traversal and handling edge cases. 🎥 Video Explanation: [https://lnkd.in/df6nZs3w] Note: At first I thought merging lists would merge me instead—but thankfully only the code struggled, not me! #DSA #LabAssignment #LeetCode #C++ #CodingPractice #ProblemSolving #MergeTwoSortedLists
To view or add a comment, sign in
-
🔥 Day 116 of My DSA Challenge – Move Zeroes 🔷 Problem : 283. Move Zeroes 🔷 Goal : Move all 0s to the end of the array while maintaining the relative order of non-zero elements. Must be done in-place without using extra space. 🔷 Key Insight : This problem focuses on in-place array manipulation and pointer logic. We need to keep all non-zero elements in front and shift all zeros toward the end — but without disturbing their relative order. A simple and efficient solution is to use the two-pointer approach: One pointer (idx) scans through the array. Another pointer (k) keeps track of where the next non-zero should be placed. 🔷 Approach : 1️⃣ Initialize pointer k = 0 2️⃣ Traverse the array with index idx 3️⃣ If nums[idx] != 0, assign nums[k] = nums[idx] If k != idx, set nums[idx] = 0 to push zero backward Increment k 4️⃣ The array is now rearranged in-place Time Complexity: O(n) Space Complexity: O(1) This problem strengthens array manipulation and in-place optimization skills. Use pointers wisely — move only what’s needed, keep it clean, keep it fast. This logic is useful for : ✅ Partitioning problems ✅ Rearranging arrays ✅ In-place sorting optimizations Another small but meaningful win — one step closer to mastering the art of clean, efficient code 🚀 #Day116 #DSA #100DaysOfCode #LeetCode #TwoPointers #Arrays #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #EngineerMindset #LogicBuilding #GrowEveryday
To view or add a comment, sign in
-
-
🌟 Day 118 of 150 – Search in Rotated Sorted Array [LeetCode 33] 🌟 🔧 Problem Brief: You are given a sorted integer array nums[] that has been rotated at an unknown pivot index. Your task → Find the index of a target element in nums using O(log n) runtime. If the target does not exist, return -1. 🎯 Goal: Efficiently locate the target element in a rotated sorted array using Modified Binary Search. 🧠 How We Solve It? → Binary Search with Rotation Logic At any point, one half of the array is always sorted. We can use this property to decide which side to continue searching on. 1️⃣ Initialize pointers: left = 0, right = nums.length - 1 2️⃣ While left <= right: Find middle → mid = left + (right - left) / 2 If nums[mid] == target → return mid ✅ If left half is sorted (nums[left] <= nums[mid]): If target is in this half → move right = mid - 1 Else → move left = mid + 1 Else (right half is sorted): If target is in this half → move left = mid + 1 Else → move right = mid - 1 3️⃣ If the loop ends → return -1 (target not found) 🧩 Example Walkthrough 📥 Input: nums = [4,5,6,7,0,1,2], target = 0 📘 Steps: mid = 3 → nums[mid] = 7 → left sorted → 0 not in [4,7] → move right mid = 5 → nums[mid] = 1 → left sorted → 0 in [0,1] → move left mid = 4 → nums[mid] = 0 → ✅ Found target at index 4 ✅ Output: 4 🧮 Complexity Analysis ⏱ Time Complexity: O(log n) 💾 Space Complexity: O(1) 📎 GitHub Link: https://lnkd.in/eqvwqs8N #Day118 #LeetCode #SearchInRotatedArray #BinarySearch #JavaDSA #ProblemSolving #CodingChallenge #InterviewPrep #TechWithSaravana #150DaysOfCode #DSA #LearningJourney #CodeEveryday #Algorithm
To view or add a comment, sign in
-
🔥 Day 115 of My DSA Challenge – Intersection of Two Arrays II 🔷 Problem : 350. Intersection of Two Arrays II 🔷 Goal : Return the intersection of two arrays, where each element in the result must appear as many times as it shows in both arrays. Order doesn’t matter. 🔷 Key Insight : This is an extension of the previous problem (Intersection of Two Arrays). The twist? Here we need to consider duplicate occurrences too. For example : nums1 = [1,2,2,1], nums2 = [2,2] → result should be [2,2] (because 2 appears twice in both). 🔷 Approach : 1️⃣ Use a HashMap to count occurrences of each element in nums1. 2️⃣ Traverse nums2 and check if an element exists in the map. 3️⃣ If yes → add it to the result and decrease its count in the map. 4️⃣ When the count becomes 0, remove it from the map to keep things clean. Time Complexity: O(n + m) Space Complexity: O(n) This problem strengthens hash-based frequency counting and element tracking. Use a map to record frequency — then match, decrease, and clean up. This logic is key for : ✅ Counting duplicates ✅ Array frequency comparison ✅ Inventory & matching systems Every small concept compounds into bigger problem-solving clarity. Step by step, I’m becoming stronger at thinking like a coder 💪💻 #Day115 #DSA #100DaysOfCode #HashMap #LeetCode #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #LogicBuilding #EngineerMindset #GrowEveryday
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