✳️Day 6 of #100DaysOfCode Mastering Linked Lists: Palindromes and Cycle Detection! 💡 I’ve been diving deep into Linked List patterns lately, and I just wrapped up two classic challenges that really test your understanding of pointer manipulation and memory efficiency. 1️⃣ Palindrome Linked List 🔄 The goal:- Determine if a linked list reads the same forward and backward. Approach:- I used an ArrayList to store the node values, then applied a Two-Pointer technique to compare elements from both ends. Key Takeaway:- While this approach is intuitive with O(n) time complexity, the next challenge is to optimize the space to O(1) by reversing the second half of the list in place! 2️⃣ Length of Loop in Linked List ➰ The goal:- Detect if a cycle exists and find exactly how many nodes are in that loop. Approach:- I implemented Floyd’s Cycle-Finding Algorithm (Slow and Fast pointers). Once the pointers met, I held one steady and moved a temporary pointer around the loop to count the nodes. Key Takeaway:- This "Tortoise and Hare" method is incredibly powerful for detecting cycles without using extra memory. Step by step, the logic is getting sharper! On to the next one. 👨💻 #Coding #Java #DataStructures #Algorithms #LeetCode #GeeksForGeeks #ContinuousLearning #ProblemSolving
Mastering Linked Lists: Palindromes and Cycle Detection
More Relevant Posts
-
Day 21 of my LeetCode consistency journey 🚀 Today I solved the Daily Temperatures problem. The goal was to determine how many days we must wait to experience a warmer temperature for each day in the list. Instead of using a brute-force approach, I implemented an optimal O(n) solution using a Monotonic Stack. This technique efficiently tracks unresolved indices and updates them when a warmer temperature appears. Key takeaway: Using a stack-based approach helps reduce unnecessary comparisons and significantly improves performance compared to the naive O(n²) method. Consistency > intensity. Small progress every day compounds into real skill. #LeetCode #DataStructures #Algorithms #ProblemSolving #Java #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Having a robust logging strategy in place is no longer an option—it's a necessity. But have you ever considered what structured logging really brings to your table? With Timberlogs, structured logging allows you to transform chaotic log piles into a stream of clear, actionable insights. By capturing your data in key-value pairs, you eliminate the overwhelming noise, focusing on what truly matters. This means faster debugging, simpler audits, and real-time insights into your applications' behavior. Our platform supports everything from TypeScript to Python, ensuring that no matter what your tech stack looks like, your logs remain clear and organized. Imagine seeing error patterns instantly and understanding user flows intuitively without pouring over endless log entries. Ready to take your logging game to the next level? Check out Timberlogs at your convenience. Explore our free tier for a hassle-free experience. #StructuredLogging #TypeScript #Observability #DevTools #Timberlogs
To view or add a comment, sign in
-
-
Day 37 of 365 days of code I tried solving a problem that I couldn't solve during the recent leetcode contest. The mistake I made was overthinking about what approach to use while solving the problem that I struggled with. literally I was bruteforcing my brain to find a soln🗿. after the contest i realised it was a simple problem lol, let me explain what the question is Qn 1) Merge adjacent equal elements You must repeatedly apply the following merge operation until no more changes can be made: If any two adjacent elements are equal, choose the leftmost such adjacent pair in the current array and replace them with a single element equal to their sum. After each merge operation, the array size decreases by 1. Repeat the process on the updated array until no more changes can be made. Return the final array after all possible merge operations. Example 1: Input: nums = [3,1,1,2] Output: [3,4] Explanation: The middle two elements are equal and merged into 1 + 1 = 2, resulting in [3, 2, 2]. The last two elements are equal and merged into 2 + 2 = 4, resulting in [3, 4]. No adjacent equal elements remain. Thus, the answer is [3, 4]. #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 76 / 100 Days of LeetCode Challenge 🧠 Today’s problem: Minimum Operations to Transform a Binary String I worked on a problem that required counting the number of 0s in a binary string and determining the minimum operations needed based on a given integer k. 📌 Problem intuition: Count the number of zeros in the string. If there are no zeros → already valid → return 0. If the string length equals k and all characters are zeros → 1 operation needed, otherwise -1. Otherwise, compute hase = len - k and proceed with further logic (though the implementation is still in progress). 🔍 Key takeaway: Sometimes the simplest approach—like counting zeros—can form the foundation of a solution. But edge cases like len == k and zero-count logic must be handled carefully to avoid incorrect results. 💻 Code snippet highlights: Loop through string, using bitwise operation ~s.charAt(i) & 1 to count zeros efficiently. Early returns for edge cases. Still refining the full logic, but proud of the progress! 📈 Runtime: 4 ms (Beats 99.66%) 💾 Memory: 47.68 MB (Beats 87.62%) ✅ 999/999 test cases passed #100DaysOfCode #LeetCode #CodingChallenge #Java #ProblemSolving #Algorithms #DataStructures #DeveloperJourney #TechCommunity #DailyCoding #CodeNewbie #WomenInTech #Programming #DevLife #LearnToCode #CodingLife #SoftwareEngineering #Tech #GrowthMindset
To view or add a comment, sign in
-
-
Day 67 - LeetCode Journey Solved LeetCode 287: Find the Duplicate Number (Medium) today — a fascinating problem that uses Floyd’s Cycle Detection Algorithm (Tortoise and Hare) in a very clever way. At first glance, the problem looks like it requires sorting or using extra memory. But the real trick is recognizing that the array can be treated like a linked list with a cycle. 💡 Core Idea: Each index points to another index using its value. Because one number is duplicated, it creates a cycle in this structure. Using two pointers: • Slow pointer (moves one step) • Fast pointer (moves two steps) They eventually meet inside the cycle. Then resetting one pointer to the start and moving both one step at a time leads us directly to the duplicate number. ⚡ Key Learning Points: • Applying Floyd’s Cycle Detection Algorithm • Treating an array as a linked structure • Solving the problem in O(n) time and O(1) space • Avoiding modification of the original array This problem is a great example of how recognizing patterns can turn a tricky problem into an elegant solution. ✅ Better understanding of cycle detection algorithms ✅ Stronger problem pattern recognition ✅ Improved optimization thinking Each problem like this sharpens algorithmic intuition 🚀 #LeetCode #DSA #Java #FloydCycleDetection #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
🚀 LeetCode Practice: Problem #145 – Binary Tree Postorder Traversal I recently solved LeetCode 145, a classic tree traversal problem that strengthens understanding of Depth-First Search (DFS) and recursion. 📌 Problem Statement Given the root of a binary tree, return the postorder traversal of its nodes’ values. Postorder Traversal Order: 👉 Left → Right → Root 🧠 Technique Used: Depth-First Search (Recursive Approach) Approach Explanation: If the current node is None, return. Recursively traverse the left subtree. Recursively traverse the right subtree. Visit (append) the root node value at the end. This traversal ensures that child nodes are processed before their parent node. Time Complexity: O(n) Space Complexity: O(h) (Where h is the height of the tree due to recursion stack) #LeetCode #Python #DSA #ValidAnagram #ProblemSolving #Algorithms #DataStructures #CodingPractice #100DaysOfCode #InterviewPreparation #SoftwareEngineering #DeveloperJourney #TechCommunity #LearningByDoing
To view or add a comment, sign in
-
-
Day 25 — #GeekStreak60 Today's Problem of the Day: Sum of Subarray Minimums (Medium) 📌 How I solved it: I used a Monotonic Stack to compute the contribution of each element as the minimum across all subarrays — in O(n) time. → For each index i, find the Previous Smaller Element (left boundary) → Find the Next Smaller or Equal Element (right boundary) → Contribution of arr[i] = arr[i] × left[i] × right[i] → Two separate stack passes — one left to right, one right to left The key insight — instead of iterating over every subarray, ask: "how many subarrays is arr[i] the minimum of?" The answer is left[i] × right[i], where left and right are distances to the nearest smaller elements on each side. Why strict on left but non-strict on right? To handle duplicates without double-counting. Asymmetric boundaries ensure each subarray's minimum is counted exactly once. Dry run for [3, 1, 2, 4]: → i=0 (3): left=1, right=1 → contributes 3 → i=1 (1): left=2, right=3 → contributes 6 → i=2 (2): left=1, right=2 → contributes 4 → i=3 (4): left=1, right=1 → contributes 4 → Total = 17 ✅ Time: O(n) | Space: O(n) This "nearest smaller element" pattern is everywhere — stock span, largest rectangle in histogram, trapping rain water. Master the monotonic stack once, and a whole class of problems opens up. Day 25 down. Show up every day, even when it's hard. The streak is the discipline. #GeeksforGeeks #GeekStreak60 #CodingJourney #DSA #Python #MonotonicStack #60DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 4/50 – LeetCode Challenge 🧩 Problem #21 – Merge Two Sorted Lists Today’s problem focused on merging two sorted linked lists — an essential concept for mastering linked list operations. 📌 Problem Summary: Given the heads of two sorted linked lists, merge them into one sorted list and return the merged list. 🔍 Approach Used (Iterative Method) Compared nodes from both lists one by one Attached the smaller node to the merged list Moved the pointer forward Continued until one list was fully traversed Appended remaining nodes at the end This ensures: ✔️ Maintains sorted order ✔️ Efficient traversal ✔️ No unnecessary extra space ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(1) (excluding output list) 💡 Key Learning: ✔️ Understanding linked list traversal ✔️ Pointer manipulation ✔️ Building efficient merge logic ✔️ Foundation of Merge Sort (Linked List version) A simple problem that strengthens core linked list fundamentals. Consistency is key 🔥 🔗 Problem Link: https://lnkd.in/gmsgsaXD #50DaysOfLeetCode #LeetCode #DSA #python #LinkedList #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
Day 61 - LeetCode Journey Solved LeetCode 81: Search in Rotated Sorted Array II (Medium) today — a problem that combines binary search + edge case handling + duplicates. This isn’t just a normal binary search. Here, the array is rotated and may contain duplicates, which makes the decision logic more subtle. 💡 Core Idea: At every step, determine which half is sorted. Then decide whether the target lies in that sorted half. If duplicates block the decision, carefully shrink the search space. ⚡ Key Learning Points: • Applying binary search on a rotated array • Handling duplicate values that break clear ordering • Smart boundary adjustments (low++, high--) • Maintaining efficiency close to O(log n) in most cases The real challenge was not writing the code — It was thinking clearly about all possible scenarios. Problems like this strengthen pattern recognition and deepen understanding of search-based algorithms 💯 ✅ Stronger grip on modified binary search ✅ Better handling of tricky edge cases ✅ Improved logical decision-making Each variation of binary search builds sharper intuition. Still learning. Still improving. Still coding 🚀 #LeetCode #DSA #Java #BinarySearch #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
🚀 Day 41 of #100DaysofCode Challenge! Today’s focus was on recursion and backtracking patterns: 🔹 Generate Parentheses Solved this using a backtracking approach by building valid combinations incrementally while maintaining two constraints: The number of opening brackets used must not exceed n The number of closing brackets must not exceed the number of opening brackets This ensures only valid sequences are generated without checking invalid ones afterward. Core idea: Use recursion to explore all valid states Add '(' if openings < n Add ')' if closings < openings Key takeaways: ✔ Backtracking with constraint pruning ✔ Recursive state-space exploration ✔ Understanding how valid combinations grow systematically Time Complexity: O(4ⁿ / √n) (related to Catalan numbers) Space Complexity: O(n) for recursion stack Building stronger intuition for recursion and combinatorial problems every day 🚀 📸 Screenshots of solution are attached! #Day41 #DynamicProgramming #BinaryTree #TreeDP #Algorithms #ProblemSolving #Python #Java #CodingMindset #SoftwareEngineering #AdityaVerma #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