𝗦𝗹𝗼𝘄 𝗽𝗼𝗶𝗻𝘁𝗲𝗿. 𝗙𝗮𝘀𝘁 𝗽𝗼𝗶𝗻𝘁𝗲𝗿. 𝗢𝗻𝗲 𝗲𝗻𝗱𝘀 𝗮𝘁 𝘁𝗵𝗲 𝗺𝗶𝗱𝗱𝗹𝗲. Today's problem: Middle of a Linked List on GFG 🟢 — an easy one, but worth understanding properly. Slow moves 1 step, fast moves 2. When fast hits the end, slow is at the middle — because fast covers exactly 2x the distance. The thing worth noting: while fast and fast.next aren't the same check. fast handles an empty list or fast landing on None mid-traversal. fast.next prevents fast.next.next from crashing when fast is on the last node. Same line, two different failure cases. ✅ 1115/1115 | First attempt | O(n) time, O(1) space Day 14 of #1000DaysOfLearning #DSA #Python #GFG #LearningInPublic
Middle of Linked List on GFG: Fast and Slow Pointer Approach
More Relevant Posts
-
🚀 Day 9 of #100DaysOfCode Today’s problem: Valid Anagram ✅ 🔍 What I learned: How to check if two strings are anagrams Importance of sorting vs frequency counting Strengthened my understanding of strings & hashing concepts 💡 Approach: I used a simple and clean method: Sort both strings Compare them If equal → Anagram ✔️ 📊 Result: ✅ All test cases passed (54/54) ⏱️ Runtime: 19 ms 🔥 Key takeaway: Sometimes a simple solution is enough, but there’s always room to optimize using hash maps for better performance. Consistency > Perfection 💯 Let’s keep going! #LeetCode #DSA #CodingJourney #Day9 #Python #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 10 of #100DaysOfCode Today’s problem: Two Sum 🔢 🔍 What I learned: Brute force approach using nested loops Understanding time complexity (O(n²)) Importance of optimizing using HashMap (next step 🚀) 💡 Approach: Checked every pair of elements If their sum equals the target → return indices 📊 Result: ✅ All test cases passed (63/63) ⏱️ Runtime: 1780 ms 🧠 Learned that brute force works, but it's not efficient 🔥 Key takeaway: There’s always a better way! Next step → solve this using HashMap in O(n) Consistency is building momentum 💯 #LeetCode #DSA #CodingJourney #Day10 #Python #ProblemSolving
To view or add a comment, sign in
-
-
Day 3 / 100 🚀 Solved “Reverse Integer” — a problem that looks simple but actually tests how carefully you handle edge cases. At first, reversing digits feels straightforward. But the real challenge is handling 32-bit overflow without using extra space. 💡 Key learning: Before updating the result, always check if multiplying by 10 will exceed the allowed range. Core idea: rev * 10 + digit must stay within [-2³¹, 2³¹ - 1] Highlights: • Time Complexity: O(log n) • Space Complexity: O(1) • Correctly handles negative numbers and overflow This problem reinforced a critical habit: Don’t just make the logic work — validate boundary conditions. #100DaysOfCode #LeetCode #DSA #Python #ProblemSolving #CodingInterview
To view or add a comment, sign in
-
-
🚀 Day 62 of #100DaysOfCode Solved “Remove Nth Node From End of List” 🔗 💡 Today’s focus: Two Pointer Technique (Fast & Slow pointers) Instead of calculating length, I used an efficient one-pass approach to remove the target node. 🧠 Key Learnings: Dummy node helps handle edge cases (like removing head) Fast pointer moves n steps ahead Then move both pointers until fast reaches the end Slow pointer lands just before the node to delete ⚡ Clean, efficient & optimal solution (O(n) time, O(1) space) Consistency is starting to feel powerful now 💪 #DSA #LeetCode #CodingJourney #LinkedInLearning #100DaysOfCode #Day62 #Python #ProblemSolving
To view or add a comment, sign in
-
-
✅ Day 14 of #DSAPrep >Topic: Time Complexity & Space Complexity > Concept: Big-O Notation Today I focused on understanding how to analyze the efficiency of algorithms. Learned how time complexity represents how the execution time grows with input size, and space complexity shows how much memory an algorithm uses. Covered key complexities: O(1) → Constant Time O(log n) → Logarithmic O(n) → Linear O(n²) → Quadratic Also understood how to compare different approaches and choose the most optimal solution. > Time Complexity: Measures performance > Space Complexity: Measures memory usage #DSAPrep #Algorithms #Python #ProblemSolving #CodingJourney #BigO
To view or add a comment, sign in
-
DSA Tip: Queue If you process tasks in random order… you’ll run into problems. Use a Queue. It follows FIFO (First In, First Out) the first item added is the first to be removed. From print jobs to request handling, queues keep systems organized and fair. Insight: Order isn’t just important, it determines how systems behave. Quick Challenge: If you enqueue A, B, C… which comes out first? Drop your answer, I’ll review the best ones. FOLLOW FOR MORE DSA TIPS & INSIGHTS #DSA #Queue #Python #CodingTips #LearnToCode
To view or add a comment, sign in
-
-
Day 6/100 – #100DaysOfCode Solved the problem “Remove Element”, focusing on in-place array manipulation. Problem Summary: Remove all occurrences of a given value from an array without using extra space, and return the count of remaining elements. Approach: Used a two-pointer technique to efficiently overwrite unwanted elements while iterating through the array. Complexity: • Time: O(n) • Space: O(1) Key Insight: Efficient problem solving is not always about removing data — sometimes it's about rearranging it smartly in-place. Consistent progress > perfection. On to Day 7 #100DaysOfCode #Day6 #DSA #Python #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 105 Backtracking is becoming more structured now. #Day105 🧩 131. Palindrome Partitioning How today went: • Iterated through the string, taking one substring at a time • Used DFS to explore partitions • Checked if each substring is a palindrome before going deeper • Built the result step by step and backtracked when needed What clicked: At each step: → choose a substring → validate (palindrome) → explore further → backtrack This pattern is repeating across problems. Backtracking is slowly becoming more intuitive. #LeetCode #DSA #Python #Backtracking #DFS #Recursion #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
📌 Problem: Increasing Triplet Subsequence 💡 Approach: Traverse the array while maintaining two variables: first and second, representing the smallest and second smallest values found so far. If the current number is smaller than first, update first Else if it’s smaller than second, update second If a number is greater than both, we’ve found an increasing triplet This ensures an optimal single-pass solution. ⚙️ Key Insight: Track only two values instead of checking all triplets Greedy + optimization approach reduces complexity significantly ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 📚 What I learned: Greedy strategy for subsequence problems Reducing brute-force O(n³) to optimal linear solution #LeetCode #DSA #Algorithms #Coding #ProblemSolving #Python #Greedy #InterviewPreparation #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
Keep it up 👍