💻 Day 35 of #LeetCode Journey 🔥 Solved: 19. Remove Nth Node From End of List Today’s problem was all about mastering Linked Lists and understanding the power of the Two Pointer technique. 🔍 Key Idea: Instead of calculating the length, I used a smart approach with fast and slow pointers. Move the fast pointer n steps ahead Then move both pointers together This helps locate the node to remove in a single pass ⚡ Why this approach? Efficient: O(n) time complexity No extra space required Clean and optimal solution 🧠 What I learned: Using a dummy node simplifies edge cases (like removing the head) Two-pointer technique is very powerful in linked list problems 📌 Problem Link: https://lnkd.in/gxXDR-YV #Java #DataStructures #LinkedList #CodingJourney #100DaysOfCode #LeetCode #ProblemSolving
Remove Nth Node From End of List with Two Pointer Technique
More Relevant Posts
-
Day 56 : Crushing Binary Trees on LeetCode 💡 Today’s live practical session in Alpha Plus 7.0 We focused on some of the most challenging Binary Tree questions on LeetCode, breaking down the logic behind them. What I practiced today: ✅ Tree Diameter: understand the logic to calculate the absolute longest path between any two nodes in the entire tree. ✅ Maximum Path Sum: Tackled a famous "Hard" level problem! Figured out how to find the path with the highest possible sum, even if it doesn't pass through the root. ✅ Target Deletion: Wrote the recursive code to systematically find and delete leaf nodes that match a specific target value. #BinaryTree #LeetCode #ProblemSolving #DSA #Java #SoftwareEngineering #100DaysOfCode #ApnaCollege
To view or add a comment, sign in
-
-
🚀 Day 67 of #LeetCode Challenge ✅ Problem Solved: Check If Two String Arrays are Equivalent 💡 What I learned today: • Learned how to compare two string arrays without joining them • Understood how to traverse multiple strings using pointers • Improved handling of indices across arrays and strings • Realized the importance of edge cases to avoid runtime errors 🧠 Approach: • Used four pointers to track positions in both arrays and strings • Compared characters one by one • Moved to the next string when current string ends • Ensured both arrays are fully traversed at the end 📊 Key Takeaway: Efficient solutions avoid extra space — comparing character by character is better than building new strings 🔥 Consistency + small improvements every day = big progress #Day67 #LeetCode #CodingJourney #DSA #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 14 of LeetCode — Longest Common Prefix Today I solved the classic problem: finding the longest common prefix among a list of strings. Approach I used: Start with the first string as the prefix Compare it with each string in the array Shrink the prefix until it matches the start of every string If it becomes empty → no common prefix Time Complexity: O(n * m) (n = number of strings, m = length of prefix) This problem reinforced string manipulation and edge case handling (empty arrays, no matches). #Java #DSA #CodingJourney #LeetCode #ProblemSolving #TechGrowth
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 3/50 💡 Approach: Two Pointer (In-Place) The straightforward way uses an extra array — but the problem specifically says no copying! So I used the Two Pointer technique to solve it in-place with a single pass. 🔍 Key Insight: → Use a 'left' pointer to track where the next non-zero element belongs → Traverse with 'right' pointer — place non-zeros at left, then increment → Fill remaining positions with 0s at the end 📈 Complexity: ✅ Time: O(n) — single pass ✅ Space: O(1) — no extra array, truly in-place Sometimes the constraint IS the optimization. Working within limits pushes us to think smarter! 🧠 #LeetCode #DSA #TwoPointer #Java #ADA #PBL2 #LeetCodeChallenge #Day3of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #MoveZeroes
To view or add a comment, sign in
-
-
🚀 Day 48 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sort Array By Parity Problem Insight: Rearrange the array so that all even numbers come before odd numbers. The order of elements doesn’t matter. Approach: • Used the two-pointer technique (partition logic) • Maintained a pointer j to track the position for even numbers • Traversed the array using i • Whenever an even number is found, swapped it with index j and incremented j • This ensures all even elements move to the front in a single pass Time Complexity: O(n) Space Complexity: O(1) (in-place solution) Key Learnings: • Two-pointer technique is very useful for array partitioning problems • Swapping helps avoid extra space usage • This pattern is similar to problems like moving zeros or segregating positives/negatives Takeaway: Simple logic + optimal approach = clean and efficient solution. Consistency is making these patterns easier to recognize! #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
The Two-Pointer streak continues! Today’s LeetCode Problem: Is Subsequence. After using multiple pointers to sort arrays and move zeroes, I applied the exact same pattern to string manipulation today. The challenge was figuring out if a shorter string (s) is a valid subsequence of a longer string (t) without disturbing the relative order of the characters. Instead of generating all possible subsequences (which would be a massive O(2ⁿ) performance drain), the Two-Pointer approach solves this beautifully in a single pass. Knocking this out in O(n) time and O(1) space is another great reminder of how incredibly versatile this algorithmic pattern is for both arrays and strings. #DSA #Java #LeetCode #IsSebsequenceProblem
To view or add a comment, sign in
-
-
🚀 Day 54 of my #100DaysOfCode Journey Today, I solved LeetCode – Sort Array By Parity II Problem Insight: Rearrange the array such that even-indexed positions have even numbers and odd-indexed positions have odd numbers. Approach: • Created a new result array of same size • Used two pointers: evenplace = 0 and oddplace = 1 • Traversed the array once • Placed even numbers at even indices and odd numbers at odd indices • Incremented pointers by 2 to maintain correct positions Time Complexity: O(n) | Space Complexity: O(n) Key Takeaway: Using two pointers for index placement makes the solution clean, efficient, and avoids unnecessary swaps. #DSA #Java #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Taking the Two-Pointer technique to LeetCode! Today's challenge: Remove Duplicates from a Sorted Array. After practicing the Two-Pointer pattern for reversing arrays and swapping 0s and 1s, I applied it to a classic LeetCode problem. The challenge? Remove duplicates from an array in-place with O(1) extra memory. Because the array is already sorted, all duplicates are grouped together. • The Slow Pointer (The Writer): Keeps track of where the next unique element should be placed. • The Fast Pointer (The Reader): Scans ahead through the array to find new, unique numbers. • The Logic: If the Reader finds a duplicate, it just skips it. But the moment the Reader finds a new number, the Writer records it at the front of the array and steps forward. #DSA #Java #LeetCode #RemoveDuplicate
To view or add a comment, sign in
-
-
🚀 Day 58 of #100DaysOfCode Solved 165. Compare Version Numbers on LeetCode 🔗 🧠 Key Insight: Version strings are split by "." into multiple revisions. We compare each revision numerically (not lexicographically). Example: "1.01" = "1.1" (leading zeros don’t matter) ⚙️ Approach (Split + Compare): 1️⃣ Split both versions using "." 🔹 version1 → s1[] 🔹 version2 → s2[] 2️⃣ Traverse till max length of both arrays 3️⃣ For each index i: 🔹 num1 = i < s1.length ? parseInt(s1[i]) : 0 🔹 num2 = i < s2.length ? parseInt(s2[i]) : 0 4️⃣ Compare: 🔹 if num1 < num2 → return -1 🔹 if num1 > num2 → return 1 5️⃣ If all equal → return 0 ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(n + m) (for split arrays) #100DaysOfCode #LeetCode #DSA #Strings #TwoPointers #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 71/100 – LeetCode Challenge Solved: Remove Duplicates from Sorted List II (Medium) Today’s problem was a great test of Linked List manipulation and handling edge cases efficiently. 🔍 Key Insight: Since the list is sorted, duplicates appear consecutively. Instead of keeping one copy, the challenge is to remove all nodes with duplicate values, leaving only distinct elements. 💡 Approach: Used a dummy node to handle edge cases Applied two-pointer technique (prev & current) Skipped entire duplicate sequences in one pass ⚡ Result: Runtime: 0 ms (Beats 100%) Space Complexity: O(1) 🎯 Key Learning: Handling duplicates in linked lists requires careful pointer updates — especially when the head itself is part of duplicates. Consistency is key 🔥 #Day71 #LeetCode #100DaysOfCode #Java #DataStructures #LinkedList #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
Explore related topics
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