💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
Dhanush Rajkumar’s Post
More Relevant Posts
-
💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
💻 Day 52 of #100DaysOfCodeChallenge Today’s problem: LeetCode 203 – Remove Linked List Elements 🧩 I worked on a Linked List manipulation problem where the goal is to remove all nodes that match a given value. This problem helped strengthen my understanding of pointer handling and dummy node usage in linked lists. 🧠 What I Learned: Handling edge cases where the head itself might need to be removed. Using a dummy node before the head to simplify pointer operations. How current and next pointers work together to modify a linked list safely. 🧩 Java Solution: class Solution { public ListNode removeElements(ListNode head, int val) { ListNode dummy = new ListNode(0); dummy.next = head; ListNode current = dummy; while (current.next != null) { if (current.next.val == val) current.next = current.next.next; else current = current.next; } return dummy.next; } } ⏱️ Complexity: Time: O(n) Space: O(1) Every day, I’m getting more confident with data structures and linked list traversal logic. On to the next challenge 🚀 #Day52 #LeetCode #Java #100DaysOfCode #CodingChallenge #LinkedList #ProblemSolving
To view or add a comment, sign in
-
-
✨ Day 52 of 100: Copy List with Random Pointer ✨ Today’s challenge was LeetCode 138 – Copy List with Random Pointer 🧠 The task: Given a linked list where each node has two pointers — 🔹 next: points to the next node 🔹 random: points to any node in the list (or null) we need to create a deep copy of this list. 💡 Key Takeaways: 🔹 Learned how to handle complex data structures where nodes reference each other in non-linear ways. 🔹 Practiced creating a deep copy using HashMap to maintain the mapping between original and copied nodes. 🔹 Explored an optimized in-place approach — interleaving original and copied nodes to avoid extra space. 🔹 Strengthened understanding of pointer manipulation and object references in Java. 🚀 This problem deepened my appreciation for how data structure cloning works — not just duplicating values, but preserving relationships! #LeetCode #100DaysOfCode #Day52 #Java #LinkedList #DeepCopy #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 2 of my #50DaysOfCode challenge Today, I tackled a problem that focuses on careful string parsing and numeric conversions String to Integer (atoi).It’s a great exercise that deepens understanding of data types, character operations, and overflow handling in Java. Problem: String to Integer (atoi) Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for myAtoi(string s) is as follows: Ignore any leading whitespace (" "),Determine the sign by checking if the next character is '-' or '+', assuming positivity if neither present. Read the integer by skipping leading zeros until a non-digit character is encountered or the end of the string is reached. If no digits were read, then the result is 0. Solution: O(N) The solution iterates through each character of the string once. It first skips leading spaces, then checks for a sign, and builds the number digit by digit. At each step, it performs an overflow check to ensure the value stays within the 32-bit signed integer range. Finally, it multiplies the result by the sign and returns it as an integer. This efficient linear-time approach ensures both accuracy and robustness for different input formats.
To view or add a comment, sign in
-
-
🚀 Just Solved LeetCode #1367 — Linked List in Binary Tree 📘 Problem: Given the head of a linked list and the root of a binary tree, determine whether all the elements of the linked list appear as a downward path in the binary tree. Downward means starting from any node and moving only to child nodes. Example: Input → head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3] Output → true Explanation → Nodes in blue form a subpath in the binary tree. 🧠 My Approach: I used recursion to check whether the linked list sequence can be found starting from any node in the binary tree. 1️⃣ For each node in the tree, check if the list starting from `head` matches the downward path from that node. 2️⃣ If not, recursively check the left and right subtrees. 3️⃣ Used a helper function `checkPath()` to verify if a valid path continues as the recursion goes deeper. 💡 What I Learned: ✅ How to combine linked list and binary tree traversal logic ✅ How recursion can efficiently check multiple starting points ✅ Improved my understanding of tree path traversal and backtracking logic #LeetCode #Java #DSA #BinaryTree #LinkedList #CodingUpdate #LearningByDoing
To view or add a comment, sign in
-
-
🚀 Day 116 of 120 – #DSAwithJava Challenge Hey LinkedIn fam! 👋 Today’s problem focused on Linked List manipulation — a classic and essential concept for every developer to master! ⚡ ✅ Problem : Remove Nth Node From End of List (LeetCode #19 – Medium) 🎯 Objective: Given the head of a linked list, remove the nth node from the end and return the updated list. 🧠 Key Insight: By using the two-pointer (fast & slow) technique, we can remove the Nth node in a single pass. Move fast pointer n steps ahead. Then move both pointers together until fast reaches the end. The slow pointer will now be just before the node to delete. This elegant trick eliminates the need to calculate the list’s length first! 💡 Example: Input: [1,2,3,4,5], n = 2 Output: [1,2,3,5] 🕒 Time Complexity: O(L) 📦 Space Complexity: O(1) 🔥 Takeaway: Sometimes, optimizing your approach isn’t about new data structures—it’s about smart pointer movement. The two-pointer method shines again in making linked list problems clean and efficient! ✨ #120DaysOfCode #DSAwithJava #LeetCode #CodingChallenge #Java #LinkedList #ProblemSolving #TechJourney
To view or add a comment, sign in
-
-
📌 Day 27/100 - Generate Parentheses (LeetCode 22) 🔹 Problem: Given n pairs of parentheses, generate all combinations of well-formed (balanced) parentheses. 🔹 Approach: Use backtracking to build strings character-by-character. Keep two counters: open = number of '(' used, close = number of ')' used. You may add '(' while open < n. You may add ')' while close < open (to maintain balance). When the current string length reaches 2*n, add it to the result list. 🔹 Complexity: Time: proportional to the number of valid combinations (Catalan number) — roughly O(4ⁿ / n^(3/2)). Space: output-sensitive — O(n * Cn) for storing results, and O(n) extra for recursion depth. 🔹 Key Learning: Backtracking is ideal when you need to enumerate valid combinations subject to constraints. Always enforce constraints early (here: close < open) to prune invalid branches. Think in terms of state (open/close counts) rather than raw string manipulation. #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA
To view or add a comment, sign in
-
-
🚀 Day 96 of #100DaysOfCode Today’s challenge was all about implementing an LRU (Least Recently Used) Cache in Java — a problem that truly tests your understanding of data structures and memory optimization. 💡 🧩 Problem Statement: Design a data structure that supports: get(key) → Returns value if key exists, else -1 put(key, value) → Inserts or updates value Both should work in O(1) time complexity. It should automatically remove the least recently used entry when the cache exceeds its capacity. ⚙️ What I Implemented: ✅ Used LinkedHashMap with access order enabled. ✅ Overrode removeEldestEntry() to maintain fixed capacity. ✅ Ensured get() and put() operations are constant time. ✅ Tested the cache with sample inputs to confirm LRU behavior. 📘 Sample Output: When I executed the program, I got: {3=30, 1=10, 4=40} This confirmed that the oldest (least recently used) entry was correctly removed when the cache was full. 🧠 Concepts Strengthened: Understanding LinkedHashMap internals Efficient memory management O(1) data retrieval and replacement logic Practical use of overriding and encapsulation 🔥 Each day of this challenge pushes me closer to mastering clean, efficient, and optimized Java code. This one made me appreciate how real-world caching systems like browsers and databases manage performance. 💬 Next Goal: To explore advanced multithreading problems and optimize concurrent data structures. ✨ Almost at the finish line — Day 96/100! Every line of code is another step toward growth. 💪 #100DaysOfCode #Java #DataStructures #CodingChallenge #ProblemSolving #LinkedHashMap #SoftwareEngineering #LearningJourney #DeveloperCommunity
To view or add a comment, sign in
-
-
🔥 Day 31/100 of #100DaysOfCode - Linked List Cleanup! Today's Problem: Remove Duplicates from Sorted List Task: Delete all duplicates from a sorted linked list so each element appears only once. Solution: Used a straightforward iterative approach with a single pointer! Traversed the list and whenever the current node's value matched the next node's value, I "skipped" the duplicate by pointing current.next to current.next.next. Key Insights: Since the list is pre-sorted, duplicates are guaranteed to be adjacent Only need one pointer to traverse and remove duplicates in place O(n) time complexity with O(1) space - very efficient! Edge Cases Handled: Empty list (head == null) Single node lists Multiple consecutive duplicates Simple but elegant linked list manipulation! Each problem builds better intuition for pointer operations. 🎯 #100DaysOfCode #LeetCode #Java #DataStructures #LinkedList #Algorithm #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