🚀 Day 11/100 – #100DaysOfDSA Today was all about applying smart pointer techniques on Linked Lists 🔗 🔹 Problems Solved: 1. Linked List Cycle 2. Palindrome Linked List 💡 Key Learnings: 👉 Problem 1: Linked List Cycle Solved using Floyd’s Cycle Detection Algorithm (Slow & Fast pointers) Slow moves 1 step, Fast moves 2 steps If they ever meet → cycle exists ✅ O(n) Time ✅ O(1) Space (no extra memory) 👉 Problem 2: Palindrome Linked List Find middle using slow & fast pointers Reverse second half of the list Compare both halves 👉 Key Insight: Convert problem into comparison of two halves ✅ O(n) Time ✅ O(1) Space 🔥 What I learned today: The slow & fast pointer technique is extremely powerful — from finding cycles to solving palindrome problems efficiently. Patterns are starting to repeat, and that’s where real understanding builds 👀 Day 11 done ✅ Let’s keep pushing 💪 #100DaysOfCode #DSA #LinkedList #ProblemSolving #CodingJourney #JavaScript #TechGrowth #SoftwareEngineer #LearningInPublic #Developers
Linked List Cycle and Palindrome Solutions with Smart Pointers
More Relevant Posts
-
🚀 Day 12/100 – #100DaysOfDSA Today was all about handling edge cases and smart traversal in Linked Lists 🔗 🔹 Problems Solved: 1. Intersection of Two Linked Lists 2. Remove Linked List Elements 💡 Key Learnings: 👉 Problem 1: Intersection of Two Linked Lists Used a HashSet approach Store nodes of one list and check in the other ✅ O(n + m) Time ❌ O(n) Space 💡 Optimization Insight: Can be solved using Two Pointer Technique with O(1) space Traverse both lists → switch heads → they meet at intersection 👉 Problem 2: Remove Linked List Elements Traverse the list and remove nodes matching given value Use a dummy node to handle edge cases (like removing head) 👉 Key Idea: Always keep track of previous node while deleting ✅ O(n) Time ✅ O(1) Space 🔥 What I learned today: Handling edge cases (like deleting head nodes or null cases) is just as important as solving the problem itself. Also learned that there’s always a more optimal solution worth exploring 👀 Day 12 done ✅ Let’s keep going strong 💪 #100DaysOfCode #DSA #LinkedList #ProblemSolving #CodingJourney #JavaScript #TechGrowth #SoftwareEngineer #LearningInPublic #Developers
To view or add a comment, sign in
-
Problem: Valid Palindrome II ✔️ All test cases passed ✔️ Runtime: 6 ms (Beats 72.07% 🚀) My Approach (Two Pointers): The goal is to check if a string can become a palindrome after removing at most one character Step-by-step 👇 👉 Use two pointers (left, right) 👉 Compare characters from both ends 👉 If they match → move inward 👉 If they don’t match → try skipping either left OR right character return isPalindrome(s, left + 1, right) || isPalindrome(s, left, right - 1); If any one of them works → it's valid ✅ Why this works? Because we are allowed to remove only one character, so we check both possibilities Helper Function: Checks if a substring is a palindrome using two pointers Complexity: Time: O(n) Space: O(1) Learning takeaway: 👉 Two-pointer technique is extremely powerful for strings 👉 Always think of “what if we skip something?” in edge cases 👉 Breaking problem into helper functions makes code cleaner #LeetCode #DSA #Algorithms #TwoPointers #JavaScript #ProblemSolving #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
-
Day 24. Linked lists, health checks, and system calls. Here's what got done: ✅ DSA — Tackled the Palindrome Linked List problem. Combining linked list traversal with palindrome logic in one problem is where things start getting interesting. Code: https://lnkd.in/dTMCJdkq ✅ React — Shipped Challenge 9 of the daily React series — a BMI Calculator. Clean inputs, instant output, practical use case. Nine challenges in and the React muscle memory is building fast. Code: https://lnkd.in/ghE74SZ2 ✅ Operating Systems — Learned about the core components of an OS and how system calls work — the bridge between user programs and the kernel. Every time your code reads a file or opens a socket, a system call is happening under the hood. 24 days in. Still learning, still shipping, still showing up. See you at Day 25. 🚀 #DSA #100DaysOfCode #BuildInPublic #LeetCode #ReactJS #OperatingSystems #WebDev #DevJourney
To view or add a comment, sign in
-
🔤 The “Most Frequent Character” Sliding Window Trick ⚡🪟 Solved LeetCode 424 using sliding window + frequency array. 🔍 Problem Find the length of the longest substring that can become all the same character after at most k replacements. 🧠 Initial thought Check every substring and count replacements needed. Works, but becomes O(n²). 🚀 Better approach Use a dynamic sliding window: • Track character frequencies inside window • Keep maxFreq = highest frequency char in current window • If (windowSize - maxFreq) > k, shrink from left • Track best valid length 🧩 Mental model The window is valid if the minority characters can be replaced within k. Formula: windowSize - mostFrequentChar <= k So the real question becomes: “How many chars are NOT the dominant one?” 🎯 Interview takeaway For replacement / flip problems, think: window size - dominant frequency = operations needed 💡 Practical insight Your maxFreq trick avoids recalculating the most frequent char every time, which keeps the solution linear and makes this pattern extremely reusable. #DSA #LeetCode #Algorithms #SlidingWindow #Strings #JavaScript #CodingInterview
To view or add a comment, sign in
-
-
🚀 Day 13/100 – #100DaysOfDSA Today was all about efficient deletion in Linked Lists and handling edge cases in a single pass 🔗 🔹 Problems Solved: 1. Remove Nth Node From End of List 2. Remove Duplicates from Sorted List 💡 Key Learnings: 👉 Problem 1: Remove Nth Node From End Used Two Pointer Technique (Fast & Slow) Move fast pointer n steps ahead Then move both pointers until fast reaches the end Slow will be just before the node to delete 👉 Key Trick: Use a dummy node to handle edge cases (like removing head) ✅ One-pass solution ✅ O(n) Time ✅ O(1) Space 👉 Problem 2: Remove Duplicates from Sorted List Since list is sorted → duplicates are adjacent Traverse and compare current node with next Skip duplicate nodes ✅ O(n) Time ✅ O(1) Space 🔥 What I learned today: Using dummy nodes + two pointers makes Linked List problems much cleaner and avoids edge-case bugs. Patterns are repeating, confidence is growing 📈 Day 13 done ✅ Let’s keep pushing 💪 #100DaysOfCode #DSA #LinkedList #ProblemSolving #CodingJourney #JavaScript #TechGrowth #SoftwareEngineer #LearningInPublic #Developers
To view or add a comment, sign in
-
🚀 Day 7/100 – #100DaysOfDSA One week in! 🎯 Today I focused on understanding basic sorting algorithms and how they work internally. 🔹 Problems Covered: 1. Selection Sort 2. Insertion Sort 💡 Key Learnings: 👉 Selection Sort Repeatedly find the minimum element from the unsorted part Place it at the correct position ✅ Time Complexity: O(n²) ✅ Space Complexity: O(1) (In-place) 👉 Insertion Sort Build the sorted array one element at a time Insert each element into its correct position ✅ Time Complexity: Best: O(n) (already sorted) Average/Worst: O(n²) ✅ Space Complexity: O(1) 🔥 What I learned today: Both algorithms are simple and useful for learning, but Insertion Sort performs better for partially sorted arrays, while Selection Sort always takes the same time. Understanding these basics helps in mastering advanced sorting algorithms later 🚀 Week 1 complete ✅ Consistency continues! #100DaysOfCode #DSA #Sorting #SelectionSort #InsertionSort #CodingJourney #ProblemSolving #JavaScript #TechGrowth #SoftwareEngineer #LearningInPublic
To view or add a comment, sign in
-
🚀 LeetCode Daily Challenge 🔗 Problem: https://lnkd.in/gdWsKciF This solution finds the maximum distance between two houses of different colors based on a key observation: the maximum distance will always involve either the first house or the last house. Instead of checking all possible pairs, which would take O(n²), the code improves the method by making a single pass through the array. It starts with an answer of 0 and goes through each index `i`. For each house, it does two checks. First, it compares the current color with the color of the first house (index 0). If they are different, the distance between them is simply `i`, and we update the maximum distance. This identifies the farthest house from the start that has a different color. Next, it compares the current color with the color of the last house (index n-1). If they are different, the distance is `(n - 1 - i)`, and we update the maximum if necessary. This identifies the farthest house from the end that has a different color. By doing this, the algorithm effectively captures the maximum possible distance without checking every pair. Since it requires only one loop through the array, the time complexity is O(n) and the space complexity is O(1). 👉 My Solution: https://lnkd.in/gg_5J_DF If you found this breakdown helpful, feel free to ⭐ the repo or connect with me on LinkedIn 🙂🚀 #️⃣ #leetcode #cpp #dsa #coding #problemsolving #engineering #BDRM #BackendDevWithRahulMaheswari
To view or add a comment, sign in
-
-
Solved a classic sliding window problem today — and it finally clicked for me. The problem: given a binary array, you can flip at most k zeros. Find the longest subarray of 1s. At first glance it looks like a brute force problem. Try every subarray. But that's O(n²). The insight? Think of it like a bouncer at a club with a strict rule: at most k troublemakers (zeros) allowed inside at any time. → right pointer = front door, letting new people in → left pointer = back door, kicking people out when the rule is violated → zeros counter = troublemaker count The window only ever grows when things are clean. When zeros > k, we shrink from the left until we're back in bounds. We never shrink smaller than our best size — that's the key. Result: O(n) time, O(1) space. function maxConsecutiveOnes(nums, k) { let left = 0, zeros = 0, maxLen = 0 for (let right = 0; right < nums.length; right++) { if (nums[right] === 0) zeros++ while (zeros > k) { if (nums[left] === 0) zeros-- left++ } maxLen = Math.max(maxLen, right - left + 1) } return maxLen } // Input: [1,1,1,0,0,0,1,1,1,1,0], k=2 // Output: 6 Sliding window is one of those patterns that once you see it, you see it everywhere — longest substring, max sum subarray, minimum window substring. What DSA pattern took the longest for you to truly internalize? #DSA #JavaScript #SlidingWindow #LeetCode #CodingInterview #ProblemSolving #WebDevelopment #Programming #100DaysOfCode #FrontendDeveloper
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