#100DaysOfCode – Day 85 Delete the Middle Node of a Linked List Problem Statement: Given the head of a singly linked list, delete the middle node and return the modified list. My Approach: Used two-pointer technique (slow & fast) to identify the middle node in a single traversal. Maintained a prev pointer to skip the middle node without extra space. Carefully handled the edge case when the list has only one node. Complexity: Time: O(N) Space: O(1) Linked lists are all about pointers and precision a small mistake (like an extra semicolon ";") can make a huge difference. Understanding how slow and fast pointers move gives deep insight into efficient traversal patterns. #LeetCode #100DaysOfCode #Java #LinkedList #ProblemSolving #takeUforward #CodingJourney #DataStructures #CodeNewbie
Deleting Middle Node in a Linked List with Java
More Relevant Posts
-
🎯 LeetCode 394 – Decode String Today I solved a really interesting Stack + String based problem! 💡 Problem Summary: We are given an encoded string containing patterns like 3[a2[c]] where: Numbers represent how many times the substring should repeat. Nested patterns are allowed. The goal is to decode the string correctly. 🧠 Approach: I used two stacks: One to store counts (how many times to repeat) One to store previously formed strings We iterate through the string: Build numbers when digits appear When [ appears, push state to stacks When ] appears, pop and reconstruct substring Else, just append characters normally ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(n) #LeetCode #Java #DSA #Stack #StringManipulation #CodingJourney #LearnEveryday #100DaysOfCode 🚀
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 67 Reverse Words in a String Problem: – Reverse Words in a String Task: – Given a string, reverse the order of the words and remove extra spaces. Example: Input: s = " the sky is blue " → Output: "blue is sky the" My Approach: Used trim() to remove leading and trailing spaces. Split the string using split("\\s+") to handle multiple spaces. Reversed the array and joined the words with a single space. Time Complexity: O(N) | Space Complexity: O(N) Even simple string problems can teach the importance of clean code and efficient use of built-in methods. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #GeeksForGeeks #CodeNewbie #StringManipulation
To view or add a comment, sign in
-
-
Day 29/100 – #100DaysOfCode 🚀 | #Java #LeetCode #BinaryTree ✅ Problem Solved: Verify Preorder Serialization of a Binary Tree 🌲 🧩 Problem Summary: Given a string representing a preorder serialization of a binary tree, determine if it’s valid. Example: "9,3,4,#,#,1,#,#,2,#,6,#,#" → ✅ valid "1,#" → ❌ invalid 💡 Approach Used: Used the slot-counting method 🧠 Each node uses one slot and non-null nodes create two new slots. Process the preorder string, ensuring slots never go negative and exactly zero remain at the end. ⚙️ Time Complexity: O(n) 📦 Space Complexity: O(1) ✨ Takeaway: This problem teaches how binary tree structure can be validated with simple counting logic — no need to rebuild the tree! 🌱 #Java #LeetCode #BinaryTree #100DaysOfCode #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 80 Reverse Linked List Problem: Given the head of a singly linked list, reverse the list and return the reversed version. Example: Input: [1, 2, 3, 4, 5] Output: [5, 4, 3, 2, 1] My Approach: Used an iterative method to reverse the list efficiently by manipulating pointers. Initialized three pointers prev, temp, and front. Iteratively reversed each node’s direction until the end of the list was reached. Returned prev as the new head of the reversed list. Time Complexity: O(N) Space Complexity: O(1) Reversing a linked list might look tricky at first, but once you understand pointer manipulation it’s pure logic and flow. #takeUforward #100DaysOfCode #DSA #Java #ProblemSolving #LeetCode #LinkedList #Pointers #CodeNewbie
To view or add a comment, sign in
-
-
💡 LeetCode #344 — Reverse String Today I solved LeetCode Problem 344: Reverse String 🔁 Problem Summary: Write a function that reverses a string. The input string is given as a character array s, and you must reverse it in-place (without using extra space). Key Idea: Use the two-pointer technique 👈👉 Initialize one pointer at the start (left) and another at the end (right). Swap the characters at both pointers and move them toward the center. #LeetCode #Java #DSA #TwoPointers #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🎯 Day 62 of #100DaysOfLeetCode Today I solved the “Merge Two Sorted Lists” problem using Java This problem is a great exercise in understanding how to work with Linked Lists and pointer manipulation. The goal is to merge two sorted linked lists into one sorted list — without using extra space for another list. Key Concepts Practiced: Linked List traversal Dummy node technique Efficient merging using pointers Handling null edge cases Approach Summary: Create a dummy node to simplify edge cases. Use two pointers to traverse both lists. Compare values and link nodes in sorted order. Attach any remaining nodes at the end. #100DaysOfCode #LeetCode #Java #CodingChallenge #DataStructures #LinkedList #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🔹 Day 46: Is Subsequence (LeetCode #392) 📌 Problem Statement: Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence is formed by deleting some (possibly none) characters from the original string without disturbing the relative order of the remaining characters. ✅ My Approach: I used a two-pointer technique — one pointer iterates through string t, and the other tracks progress through string s. Each time a matching character is found, the pointer for s moves forward. If we reach the end of s, it means all its characters appeared in sequence within t. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Stats: Runtime: 2 ms (Beats 68.53%) Memory: 41.32 MB (Beats 87.28%) 💡 Reflection: A simple yet elegant problem that highlights how pointer movement can efficiently handle string comparisons without extra memory usage. ✨ #LeetCode #Java #Strings #TwoPointers #100DaysOfCode #Day46
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 71 String Rotation Task: Given two strings s and goal, determine if s can become goal after some number of rotations (moving the first character to the end each time). Example: Input: s = "abcde", goal = "cdeab" Output: true My Approach First, check if both strings have the same length otherwise, rotation is impossible. Then, observe that any valid rotation of s will always appear as a substring in s + s. Simply check: return (s + s).contains(goal); Time Complexity: O(N²) Space Complexity: O(N) Sometimes, elegant insights lead to minimal code doubling a string can reveal every possible rotation effortlessly! #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #StringManipulation #takeUforward #GeeksForGeeks #CodeNewbie #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 7️⃣7️⃣ of #100DaysOfCode Solved LeetCode Problem #1437 — Check If All 1’s Are at Least K Places Away 🔍✨ 🔧 Concept: Given a binary array, ensure that every 1 is separated by at least K zeros. The solution simply tracks the previous index of 1 and checks the distance. 🧠 Key Idea: Scan the array once When a 1 is found, verify: 👉 currentIndex - previousIndex > k If any pair violates this, return false ⚡ Efficient: Time Complexity: O(n) Space Complexity: O(1) Another clean and efficient logical problem solved. #LeetCode #Java #Arrays #ProblemSolving #DSA #CodingJourney #100DaysOfCode #DeveloperLife #Motivation
To view or add a comment, sign in
-
-
💻 Day 45 of #LeetCode Journey 🚀 ✅ Problem: Count and Say 📘 Language: Java 🔹 Status: Accepted (30/30 test cases passed) 🔹 Runtime: 4 ms | Beats 55.38% 🔹 Memory: 41.86 MB 🧠 Concept: This problem is about generating the n-th term in the “count and say” sequence. Each term is built by describing the previous term — count the number of digits and say them in order. 🧩 Approach: Start with "1". For each iteration, use a StringBuilder to construct the next sequence. Track consecutive digits using a counter. Append the count and digit when the sequence changes. 💡 Efficient string manipulation and iteration give optimal performance. 🔥 Every solved problem builds confidence. One step closer to mastering patterns in strings! #Day45 #LeetCode #Java #CodingChallenge #ProblemSolving #CountAndSay #50DaysOfCode
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