𝗗𝗮𝘆 𝟯𝟮/𝟭𝟬𝟬 | 𝗥𝗲𝗺𝗼𝘃𝗲 𝗡𝘁𝗵 𝗡𝗼𝗱𝗲 𝗙𝗿𝗼𝗺 𝗘𝗻𝗱 𝗼𝗳 𝗟𝗶𝘀𝘁 Day 32 ✅ — Three linked list problems in a row. The pattern is clear. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟭𝟵: Remove Nth Node From End of List (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Remove the nth node from the end of a linked list in one pass... or two. The tricky part? We don't know the size upfront. My approach: first calculate the size, then find the exact node to remove. Key edge case that almost caught me: removing the head node itself (when n equals the list size). Had to handle that separately. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 First pass: calculate the total size of the linked list 👉 If n equals size, remove head directly 👉 Traverse to the node just before the target 👉 Skip the target node: curr.next = curr.next.next Time complexity: O(n), Space complexity: O(1) 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: This is a two-pass solution. There's also a one-pass two-pointer technique using fast and slow pointers—something I want to explore next. But here's what matters: my solution works, is clean, and handles all edge cases. Understanding multiple approaches to the same problem is what separates good developers from great ones in technical interviews. Three linked list problems back-to-back (Day 30, 31, 32) and the pointer manipulation is becoming second nature. 𝗖𝗼𝗱𝗲: https://lnkd.in/g5EEbZKW 𝟯𝟮 𝗱𝗮𝘆𝘀. 𝗟𝗶𝗻𝗸𝗲𝗱 𝗹𝗶𝘀𝘁 𝗺𝗮𝘀𝘁𝗲𝗿𝘆 𝘂𝗻𝗹𝗼𝗰𝗸𝗲𝗱. 𝗗𝗮𝘆 𝟯𝟮/𝟭𝟬𝟬 ✅ | 𝟲𝟴 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #PointerManipulation #TwoPointer #DataStructures #CodingInterview #TechnicalInterview #FAANG #SoftwareEngineer #Java #Algorithms #EdgeCases #ComputerScience #Programming #TechCareers #Consistency
More Relevant Posts
-
🚀 Today’s LeetCode Problem — Sort Integers by Number of 1 Bits Let’s solve today’s LC in story mode 🎭 Imagine numbers are contestants in a Binary Costume Contest. Today’s contestants: 👉 [5, 3, 7] But this contest has a twist 👇 👨⚖️ The judge doesn’t care about the number itself first. He cares about… 🎈 How many 1s are in their binary costume 🎭 What Are They Wearing? 🔹 5 → 101 → 🎈🎈 (2 ones) 🔹 3 → 011 → 🎈🎈 (2 ones) 🔹 7 → 111 → 🎈🎈🎈 (3 ones) 🏆 Judge’s Rules 1️⃣ Fewer 1s → Higher priority 2️⃣ Same number of 1s → Smaller number wins 👉 Step 1: 3 & 5 → 2 ones 7 → 3 ones So 7 goes last. 👉 Step 2: Tie between 3 and 5 Smaller number first → 3 before 5 ✅ Final Answer: [3, 5, 7] 💡 How I Solved It I implemented this using: 🔹 Brian Kernighan’s Algorithm for efficient bit counting 🔹 TreeMap to maintain sorted order by bit count + value 🔹 Also compared with built-in bitCount() + custom comparator sorting This ensures: ✔ Efficient bit counting ✔ Clean tie-breaking ✔ Optimal sorting logic If you’re interested, I’ve pushed the complete solution (Kernighan + TreeMap + built-in approach) : https://lnkd.in/gV9HZ9w4 👨💻 Would love feedback from fellow developers 🙌 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #100DaysOfCode #Tech #SoftwareEngineering
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟯𝟰/𝟭𝟬𝟬 | 𝗠𝗶𝗱𝗱𝗹𝗲 𝗼𝗳 𝘁𝗵𝗲 𝗟𝗶𝗻𝗸𝗲𝗱 𝗟𝗶𝘀𝘁 Day 34 ✅ — Reinforcing yesterday's pattern. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟴𝟳𝟲: Middle of the Linked List (Easy) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Find the middle node of a linked list. Yesterday I deleted it, today I returned it. Same fast and slow pointer technique. Fast moves 2 steps, slow moves 1. When fast hits the end, slow is at the middle. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 slow = head, fast = head 👉 Move fast by 2, slow by 1 👉 Return slow when fast reaches end Time: O(n), Space: O(1) 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Repetition builds mastery. Same pattern, different problem. This is how you internalize techniques for coding interviews. Five linked list problems in a row. The two-pointer pattern is now muscle memory. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gCd-B7Um 𝗗𝗮𝘆 𝟯𝟰/𝟭𝟬𝟬 ✅ | 𝟲𝟲 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #TwoPointer #FastAndSlowPointer #DataStructures #CodingInterview #FAANG #SoftwareEngineer #Java #Algorithms #Programming #PatternRecognition
To view or add a comment, sign in
-
𝐃𝐚𝐲 𝟔 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problems were all about 𝐛𝐢𝐧𝐚𝐫𝐲 𝐬𝐞𝐚𝐫𝐜𝐡 𝐰𝐢𝐭𝐡 𝐜𝐨𝐧𝐝𝐢𝐭𝐢𝐨𝐧𝐬 — not just finding an element, but deciding where to search. ✅ 𝐏𝐫𝐨𝐛𝐥𝐞𝐦𝐬 𝐒𝐨𝐥𝐯𝐞𝐝 📌 Search in Rotated Sorted Array 📌 Find First and Last Position of Element in Sorted Array 🔹 𝐒𝐞𝐚𝐫𝐜𝐡 𝐢𝐧 𝐑𝐨𝐭𝐚𝐭𝐞𝐝 𝐒𝐨𝐫𝐭𝐞𝐝 𝐀𝐫𝐫𝐚𝐲 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Used 𝐦𝐨𝐝𝐢𝐟𝐢𝐞𝐝 𝐛𝐢𝐧𝐚𝐫𝐲 𝐬𝐞𝐚𝐫𝐜𝐡 At each step, identified which half of the array was sorted Narrowed the search space based on where the target could lie 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: ✅ Binary search is about decisions, not comparisons ✅ Understanding sorted halves simplifies rotated arrays 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: ⏱ Time: O(log n) 📦 Space: O(1) 🔹 𝐅𝐢𝐧𝐝 𝐅𝐢𝐫𝐬𝐭 𝐚𝐧𝐝 𝐋𝐚𝐬𝐭 𝐏𝐨𝐬𝐢𝐭𝐢𝐨𝐧 𝐨𝐟 𝐄𝐥𝐞𝐦𝐞𝐧𝐭 𝐢𝐧 𝐒𝐨𝐫𝐭𝐞𝐝 𝐀𝐫𝐫𝐚𝐲 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Performed 𝐭𝐰𝐨 𝐛𝐢𝐧𝐚𝐫𝐲 𝐬𝐞𝐚𝐫𝐜𝐡𝐞𝐬 One to find the leftmost occurrence One to find the rightmost occurrence Adjusted boundaries after finding the target 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: ✅ One problem can require multiple binary searches ✅ Direction control helps find boundaries efficiently 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: ⏱ Time: O(log n) 📦 Space: O(1) 🧠 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Binary search isn’t just a technique — it’s a 𝐰𝐚𝐲 𝐨𝐟 𝐭𝐡𝐢𝐧𝐤𝐢𝐧𝐠. On to 𝐃𝐚𝐲 𝟕 🔁🚀 #DSA #Arrays #BinarySearch #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟱𝟭/𝟭𝟬𝟬 | 𝗜𝗻𝘀𝗲𝗿𝘁𝗶𝗼𝗻 𝗦𝗼𝗿𝘁 𝗟𝗶𝘀𝘁 Day 51 ✅ — Second half begins. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟭𝟰𝟳: Insertion Sort List (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Sort a linked list using insertion sort. The algorithm everyone learns with arrays—now applied to pointers. For each unsorted node, find its correct position in the sorted portion and insert it there. The dummy node pattern made this clean—find the insertion point, adjust pointers, move forward. Day 51. The second half of the journey starts here. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Dummy node for sorted list head 👉 Keep sorted and unsorted portions 👉 For each unsorted node, find insertion position 👉 Adjust pointers to insert node 👉 Continue until entire list is sorted Time: O(n²), Space: O(1) 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Twenty-two linked list problems. Insertion sort on arrays is basic. On linked lists? It tests if you truly understand pointer manipulation. Yesterday was celebration. Today is execution.𝟰𝟵 𝗺𝗼𝗿𝗲 𝗱𝗮𝘆𝘀. 𝗟𝗲𝘁'𝘀 𝗴𝗼. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gR6h_43V 𝗗𝗮𝘆 𝟱𝟭/𝟭𝟬𝟬 ✅ | 𝟰𝟵 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #InsertionSort #SortingAlgorithms #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #Programming #SecondHalf
To view or add a comment, sign in
-
Stop complaining about if err != nil. It’s saving your career. 🛑 Developers love to hate on Go’s error handling. "It's too verbose." "My code looks like a pyramid of doom." "I miss the elegance of try-catch!" I used to feel the same way. Coming from Java and Python, the endless if err != nil checks felt like a step backward into the Stone Age of programming. I just wanted to write "clean" business logic without constantly checking for failure. But after years of debugging production incidents at 3 AM, my perspective shifted completely. Here is the hard truth: Exceptions are an invisible GOTO. When you use try-catch, you assume someone upstream is paying attention. But often, they aren't. Exceptions bubble up silently, crashing the app or hiding in logs, leaving you with zero context on how you got there. Go flips the script. It treats errors as values, not special events. This forces a fundamental shift in how you think about code. Why this verbosity is actually a superpower: 1. Forced Discipline: You cannot ignore the unhappy path. The syntax compels you to make a decision: Handle it? Wrap it? Or return it? You are constantly aware that the world is imperfect. 2. Readable Control Flow: With proper "guard clauses" (returning early on error), your main logic stays flat and readable. No deep nesting, no guessing where the jump goes. 3. Context is King: In modern Go, you don't just return an error; you wrap it (fmt.Errorf("failed to connect to DB: %w", err)). You build a breadcrumb trail of exactly what happened and where. It turns a generic "NullPointerException" into a clear story: "Failed to load user -> Failed to query DB -> Connection timeout." It’s not just about handling errors; it’s about designing resilient systems. Verbose? Maybe. But in a distributed system, verbosity is a small price to pay for reliability. Which side are you on? The "Explicit" team (Go/Rust) or the "Exception" team (Java/Python)? Let's debate in the comments. #softwareengineering #golang #backenddevelopment #systemdesign #coding
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟰𝟬/𝟭𝟬𝟬 | 𝗗𝗼𝘂𝗯𝗹𝗲 𝗮 𝗡𝘂𝗺𝗯𝗲𝗿 𝗥𝗲𝗽𝗿𝗲𝘀𝗲𝗻𝘁𝗲𝗱 𝗮𝘀 𝗮 𝗟𝗶𝗻𝗸𝗲𝗱 𝗟𝗶𝘀𝘁 🎉 Day 40 ✅ — 𝟰𝟬% 𝗰𝗼𝗺𝗽𝗹𝗲𝘁𝗲. 𝗘𝗹𝗲𝘃𝗲𝗻 𝗹𝗶𝗻𝗸𝗲𝗱 𝗹𝗶𝘀𝘁 𝗽𝗿𝗼𝗯𝗹𝗲𝗺𝘀 𝘀𝘁𝗿𝗮𝗶𝗴𝗵𝘁. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟴𝟭𝟲: Double a Number Represented as a Linked List (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Double a number stored in a linked list (digits in order). Handle carry propagation like manual multiplication. My approach combined patterns from the past 11 days: Reverse the list (Day 31, 39) Process digit by digit with carry Reverse back to original order Three operations, one solution. The linked list fundamentals are locked in. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Reverse the linked list 👉 Multiply each digit by 2, handle carry 👉 If final carry exists, add new node 👉 Reverse back to original order Time: O(n), Space: O(1) 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Eleven consecutive linked list problems (Day 30-40). What started as practice became mastery. 40 days. 40 problems. 40% complete. The consistency compounds. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gbmeVK36 𝟰𝟬 𝗱𝗮𝘆𝘀. 𝗧𝘄𝗼-𝗳𝗶𝗳𝘁𝗵𝘀 𝗱𝗼𝗻𝗲. 🎯 To everyone on their journey: small daily actions → massive results. Keep going. 𝗗𝗮𝘆 𝟰𝟬/𝟭𝟬𝟬 ✅ | 𝟲𝟬 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #MathematicalAlgorithms #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #MediumLevel #Programming #40DayMilestone #Consistency #TechCareers
To view or add a comment, sign in
-
🚀 Day 15 – LeetCode 209 | Minimum Size Subarray Sum | Sliding Window Mastery Most people brute-force this problem with O(n²) nested loops and call it a day. That’s lazy thinking. If your first instinct isn’t O(n) with sliding window, you’re not thinking like a serious engineer yet. Problem: Given positive integers, find the smallest length subarray whose sum ≥ target. Naive: Check every subarray → slow → useless for large inputs. Correct mindset: Two pointers + running sum. Move right → expand window When sum ≥ target → move left → shrink window Track minimum length Time: O(n) Space: O(1) This is not just a problem — it trains: • Window optimization • Two-pointer thinking • Real interview patterns • How to kill brute force early If you still default to nested loops, fix that habit now. Top engineers think in patterns, not force. Consistency check: 15 days straight of DSA. No skips. No excuses. Code + explanation done. On to Day 16. #LeetCode #Day15 #DSA #Java #SlidingWindow #Algorithms #CodingInterview #SoftwareEngineer #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
🚀 Day 1/30: Kicking off my DSA Journey! Today’s focus: LeetCode 283 – Move Zeroes. 📝 The Challenge Given an integer array nums, the goal is to shift all the 0s to the end while keeping the non-zero elements strictly in their original order. ⚠️ The Catch: This must be done in-place (no extra memory allowed). 📌 Example Input: nums = [0, 1, 0, 3, 12] Output: [1, 3, 12, 0, 0] Explanation: The zeros are pushed to the back, while 1, 3, 12 stay in their exact original sequence. 💡 First Thoughts The brute-force way out? Just create a secondary array, dump the non-zero numbers in first, and pad the rest with zeros. But that directly violates the $O(1)$ space constraint. The real puzzle was figuring out how to achieve this by only modifying the original array. ⚙️ The Solution: Two-Pointer Technique To optimize the solution, I utilized the Two-Pointer method: Pointer i acts as the explorer, traversing the array. Pointer j acts as an anchor, tracking where the next non-zero element belongs. The Steps: Start j at index 0. Loop through the array with i. Whenever i finds a non-zero number, swap it with nums[j] and bump j up by 1. 🧠 Why It Works Because j only steps forward when a non-zero element is securely locked into place, the original relative order is perfectly preserved. As the non-zeroes move to the front, the zeros naturally get pushed to the back. Zero extra data structures, just a single pass! 📊 Complexity Time Complexity: $O(n)$ — We only traverse the array once. Space Complexity: $O(1)$ — Everything is modified completely in-place. 🔑 Takeaways The Two-Pointer strategy is an absolute lifesaver for tricky array manipulations. "In-place modification" and "preserving relative order" are incredibly common technical interview constraints. Small problems are the best way to test and solidify your core fundamentals. Consistency beats motivation! 💪 Let's build these skills one problem at a time. ##30DaysOfCode #DSA #LeetCode #Java #ProblemSolving #InterviewPreparation #CodingJourney
To view or add a comment, sign in
-
-
Day 36 :- Binary Search & Range Finding: Find First and Last Position of Element ✅ Today’s DSA session was a great exercise in extending the classic Binary Search to handle multiple occurrences of a target value. I tackled LeetCode 34. Find First and Last Position of Element in Sorted Array, focusing on how to efficiently pinpoint a range within a sorted dataset. The Technical Breakdown: Hybrid Search Strategy: I started with a standard Binary Search to find any instance of the target. This immediately gives us an O(log n) starting point. Linear Expansion: Once the target was found, I used two pointers to expand outward from the meeting point. This identifies the exact boundaries where the target values start and end. Edge Case Handling: The logic naturally handles cases where the target isn't present by returning [-1, -1], and it manages single-element arrays or cases where the target spans the entire array. The Trade-off: While this approach is very intuitive, it can reach O(n) in the worst case (e.g., an array of all identical numbers). It’s a great stepping stone before diving into the pure O(log n) approach of finding the "leftmost" and "rightmost" indices independently! It's a solid reminder that Binary Search isn't just for finding a single value—it's the foundation for navigating any sorted range! 🚀 A huge thanks to my mentor, Anchal Sharma and Ikshit .. for the incredible support and for helping me stay consistent on this journey. Having that accountability makes all the difference! #DSA #Java #100DaysOfCode #BinarySearch #TwoPointers #ProblemSolving #Mentorship #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
Day - 75 Next Greater Element I The problem - Given two arrays nums1 and nums2 where nums1 is a subset of nums2, for each element in nums1, find the next greater element in nums2. The next greater element is the first greater element to the right. If it doesn't exist, return -1. Brute Force - For each element in nums1, find its position in nums2, then scan right to find the first greater element. This gives O(n × m) time complexity where n = length of nums1 and m = length of nums2. Approach Used - •) Create array nextGreater[10001] to store next greater element for each number and a Stack<Integer> for tracking elements. •) Traverse nums2 from right to left (i = length-1 to 0), 1 - While stack is not empty && stack.peek() ≤ nums2[i], pop from stack. 2 - If stack is empty, nextGreater[nums2[i]] = -1, else nextGreater[nums2[i]] = stack.peek(). 3 - Push nums2[i] onto stack. •) For each element in nums1, replace it with nextGreater[nums1[i]], return nums1. Complexity - Time - O(n + m) where n = nums1.length, m = nums2.length. Space - O(m), for stack and nextGreater array. Note - Using a monotonic decreasing stack while traversing right to left allows us to efficiently find the next greater element. Elements smaller than current are popped (they can't be next greater for anyone), and the remaining top element is the answer. The array acts as a lookup table for O(1) retrieval. #DSA #Java #SoftwareEngineering #InterviewPrep #LearnToCode #CodeDaily #ProblemSolving
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