🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
Solving LeetCode #160 with Two Pointer Approach
More Relevant Posts
-
🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
To view or add a comment, sign in
-
-
🚀 Day 43 of #100DaysOfLeetCode Today's problem: LeetCode #160 – Intersection of Two Linked Lists 💡 Concept: Find the node where two singly linked lists intersect. Used the Two Pointer Approach — a smart and efficient way to solve this without using extra memory. 🧠 Logic: Move both pointers through the lists. When one pointer reaches the end, switch it to the other list’s head. They’ll either meet at the intersection node or end up as null together. ✅ Complexity: Time – O(n + m) Space – O(1) 💬 Takeaway: Sometimes, the best solutions come from balancing the path — literally! Understanding how pointers sync up teaches a lot about memory references and linked list behavior. #LeetCode #CodingChallenge #Java #DataStructures #TwoPointerTechnique #ProblemSolving #LinkedLists
To view or add a comment, sign in
-
-
🚀 Day 42 of #100DaysOfLeetCode Today's challenge: Binary Tree Preorder Traversal (LeetCode #144) 🌳 📘 Concept: Preorder traversal follows the order — Root → Left → Right. It’s one of the fundamental ways to explore a binary tree, and it helps build a strong base for understanding recursion and tree-based algorithms. 🧠 Approach Used: Used a simple recursive solution to visit the root first, then the left subtree, and finally the right subtree. 💡 Key Takeaway: Recursion becomes easy once you visualize how the function calls go deep into left and right subtrees. Trees are all about patterns! #LeetCode #100DaysChallenge #Day42 #CodingJourney #BinaryTree #Recursion #Java
To view or add a comment, sign in
-
-
Day 44 of #50DaysOfLeetCodeChallenge Problem: Add Two Numbers -Approach: Since the digits are stored in reverse, I started adding from the head nodes, just like manual addition from the least significant digit. Maintained a carry for sums ≥ 10. Traversed both lists simultaneously, creating new nodes for each sum digit. If a carry remained at the end, added it as a new node. -Key Takeaways: Linked lists can represent numbers in creative ways. Starting from the least significant digit simplifies addition. Carry handling is crucial for correctness. #LinkedInLearning #CodingJourney #Java #DataStructures #ProblemSolving #Algorithms #LeetCode #50Days
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 81 Linked List Cycle Problem Given the head of a linked list, determine whether the list contains a cycle meaning a node’s next pointer refers back to a previous node. My Approach Used Floyd’s Cycle Detection Algorithm (Tortoise & Hare Method): Initialized two pointers slow and fast. Moved slow one step and fast two steps in each iteration. If they ever meet → cycle detected. If fast or fast.next becomes null → no cycle exists. Complexity Time: O(n) Space: O(1) Even in problems involving dynamic structures like linked lists, a simple pointer-based approach can lead to an elegant and optimal solution. #100DaysOfCode #LeetCode #Java #ProblemSolving #DataStructures #LinkedList #TortoiseAndHare #takeUforward #CodeNewbie #CodingJourney
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 3/100 - Remove Duplicates from Sorted Array (LeetCode 26) 🔹 Problem: Given a sorted array, remove the duplicates in-place so that each element appears only once and return the new length. You must modify the array without using extra space for another array. 🔹 Approach: I used a simple counting-based approach: Iterate through the array using a single loop. If the current element is the same as the next, skip it. Otherwise, place it at the current count index and increment count. Finally, return count as the number of unique elements. 🔹 Key Learning: Practiced in-place array modification efficiently without extra space. Improved understanding of loop-based filtering logic. Realized that sometimes the simplest linear approach works best! Consistency compounds — each problem adds a new layer of confidence! 🚀#100DaysOfCode #LeetCode #Java #ProblemSolving #Array #DSA #TwoPointers
To view or add a comment, sign in
-
-
🚀 Day 390 of #500DaysOfCode 🔹 LeetCode Problem 278: First Bad Version Today’s problem was about efficiently finding the first defective version in a product release sequence using minimal API calls. Once a version turns bad, all versions after it are bad — a perfect use case for binary search optimization! ⚙️ 🧠 Concepts Used: Binary Search 🔍 Optimization of API calls Problem-solving with boundary conditions ⚡ Time Complexity: O(log n) ⚡ Space Complexity: O(1) Each step halves the search range, making it super-efficient! 🚀 #LeetCode #Java #CodingChallenge #BinarySearch #ProblemSolving #100DaysOfCode #500DaysOfCode #CodeNewbie #LearnToCode #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Day 31: LeetCode 167 — Two Sum II (Two Pointer Approach) 🔹 Concept Covered: Two Pointer Technique on a Sorted Array 🔹 Problem Goal: Find two numbers such that they add up to a specific target. 🔹 Approach: Use two pointers (low at start, high at end). Calculate the sum of both pointers. If sum == target → return indices. If sum > target → move high-- (reduce sum). If sum < target → move low++ (increase sum). 💡 Time Complexity: O(n) 💡 Space Complexity: O(1) 🎯 Learning: The two-pointer approach is extremely efficient for sorted arrays — no need for nested loops or hash maps. It’s all about moving intelligently in one pass! #LeetCode #Day31 #TwoPointer #Java #CodingJourney #YeswanthCodes
To view or add a comment, sign in
-
-
🌳 Day 21 of #100DaysOfLeetCode – Unique Binary Search Trees 🌳 Today’s challenge was all about counting how many structurally unique BSTs can be formed using n distinct numbers. 🧮 This problem beautifully blends dynamic programming and combinatorial logic — where the number of unique trees for each n depends on the possible root positions and their left/right subtree combinations. ⚙️ 💡 Key takeaway: Dynamic programming helps in reusing subproblem results efficiently — making even complex recursive patterns simpler and faster! 🚀 #LeetCode #100DaysChallenge #BinarySearchTree #DynamicProgramming #ProblemSolving #CodingJourney #Java #DataStructures
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