🚀 Day 3/100 – #100DaysOfDSA Another day, more learning, and deeper understanding of in-place algorithms! 🔹 Problems Solved: Move Zeroes Merge Sorted Array 💡 Key Learnings: 👉 Problem 1: Move Zeroes Applied Two Pointer Technique One pointer tracks position for next non-zero element Another pointer iterates through the array Swap only when needed to maintain order ✅ Maintains relative order ✅ In-place (O(1) space) ✅ O(n) Time Complexity 👉 Problem 2: Merge Sorted Array Solved using reverse two-pointer approach Start filling from the end of nums1 (to avoid overwriting elements) Compare elements from nums1 and nums2, and place the larger one at the end ✅ Efficient merge without extra array ✅ O(m + n) Time ✅ In-place solution 🔥 What I learned today: Sometimes solving from the end instead of the beginning makes the problem much simpler and avoids unnecessary complexity. Consistency is building momentum. Day 3 done ✅ #100DaysOfCode #DSA #LeetCode #ProblemSolving #CodingJourney #SoftwareEngineer #JavaScript #TechGrowth #LearningInPublic #Developers
In-Place Algorithms for Move Zeroes and Merge Sorted Array
More Relevant Posts
-
🚀 Day 13 of My LeetCode Journey — Refining Linked List Skills Today’s problems: 🔹 Remove Duplicates from Sorted List (LeetCode 83) 🔹 Remove Nth Node From End of List (LeetCode 19) 💡 Problem 1: Remove Duplicates from Sorted List Since the list is already sorted: 👉 Just compare current node with next node 👉 If curr.val === curr.next.val → skip the duplicate 👉 Else → move forward Simple logic, but very effective due to the sorted property! 💡 Problem 2: Remove Nth Node From End of List Solved using two approaches: ✅ Two-Pass Approach First pass → calculate length Second pass → remove (length - n) node ⏱️ Time: O(n) ✅ One-Pass Approach (Optimized) 🔥 Use two pointers (fast & slow) Move fast ahead by n steps Move both together → when fast reaches end, slow is at target 👉 This approach is cleaner and more efficient! 🧠 What I Learned: Sorted data can simplify problems significantly Two-pointer technique continues to be super useful There’s always a way to reduce passes in linked list problems 🔥 Key Takeaways: Look for patterns (sorted, reversed, etc.) Optimize from two-pass → one-pass when possible Linked Lists are all about pointer precision Big thanks to Namaste DSA and Akshay Saini 🚀 for the guidance Day 14 loading… 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #LinkedList #TwoPointers #DSA #NamasteDSA #AkshaySaini
To view or add a comment, sign in
-
🚀 Day 23 of #60DaysOfDSA Today I implemented Quick Sort, a powerful Divide & Conquer algorithm used for sorting. 🔍 What I learned: Quick Sort works by selecting a pivot element It partitions the array into: Elements smaller than pivot Elements greater than pivot Then recursively sorts both parts ⚡ Key Insight: “Partitioning is the heart of Quick Sort.” Even a small mistake in index handling or swapping can completely break the logic. 💻 Key Concepts Covered: ✔️ Pivot selection (last element) ✔️ Partition logic (Lomuto method) ✔️ Recursion ✔️ In-place sorting 🧠 Takeaway: Quick Sort is not just about writing code, it’s about understanding how elements move and how recursion divides the problem. Consistency > Perfection 🚀 One step closer to becoming better every day! #DSA #QuickSort #CodingJourney #JavaScript #ProblemSolving
To view or add a comment, sign in
-
-
Solved one of the most interesting stack-based problems recently: Maximum Subarray Min-Product. At first glance, it looks like a variation of subarray problems, but the real challenge lies in combining multiple concepts efficiently: Monotonic Stack to determine the next smaller element boundaries Prefix Sum to compute subarray sums in constant time BigInt handling in JavaScript to safely manage large intermediate values The key insight was realizing that for every element, we can treat it as the minimum of a subarray and expand left and right until a smaller element blocks it. Using a monotonic increasing stack allows us to compute this in linear time. What made this problem particularly valuable: Reinforced how stack patterns extend beyond classic histogram problems Highlighted the importance of boundary management in array problems Demonstrated practical use of BigInt in algorithmic challenges Time Complexity: O(n) Space Complexity: O(n) Problems like this are a great reminder that mastering patterns, not just problems, is what builds real problem-solving ability. If you're working on Data Structures and Algorithms, this is definitely a problem worth understanding deeply. #DataStructures #Algorithms #DSA #Coding #Programming #SoftwareEngineering #JavaScript #ProblemSolving #CompetitiveProgramming #LeetCode #TechLearning #DeveloperJourney #CodeNewbie #LearnToCode #InterviewPrep #CodingInterview #ComputerScience #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 7 of My LeetCode Journey — Sorting Fundamentals Today I focused on two classic sorting algorithms: 🔹 Bubble Sort 🔹 Selection Sort 💡 Bubble Sort The idea is simple: 👉 Compare adjacent elements 👉 Swap if they are in the wrong order 👉 Repeat until the array is sorted It’s easy to understand, but not efficient for large datasets. ⏱️ Time Complexity: O(n²) 💡 Selection Sort A slightly different approach: 👉 Find the minimum element 👉 Place it at the correct position 👉 Repeat for the rest of the array Also simple, but still not optimal for big inputs. ⏱️ Time Complexity: O(n²) 🔥 Key Takeaways: These algorithms may not be optimal, but they build strong fundamentals Understanding how sorting works internally is more important than memorizing Optimization comes later — basics come first Big thanks to Namaste DSA and Akshay Saini 🚀 for guiding this journey Consistency is the real win — Day 8 loading 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #Sorting #BubbleSort #SelectionSort #NamasteDSA
To view or add a comment, sign in
-
🚀 Day 12 of My LeetCode Journey — Linked List Patterns Getting Stronger Today’s problems: 🔹 Intersection of Two Linked Lists (LeetCode 160) 🔹 Remove Linked List Elements (LeetCode 203) 💡 Problem 1: Intersection of Two Linked Lists Explored two approaches: ✅ Brute Force Traverse headA and check every node in headB ⏱️ Time: O(m × n) ✅ Using Set Store all nodes of headB in a Set Traverse headA and check for intersection ⏱️ Time: O(m + n) | 📦 Space: O(n) 👉 Helped me understand how hashing can optimize comparisons. 💡 Problem 2: Remove Linked List Elements Solved using a Sentinel (Dummy) Node 🔥 👉 Create a dummy node before head 👉 Use prev pointer to skip unwanted nodes: prev.next = prev.next.next This approach simplifies edge cases like: Removing head node Multiple consecutive deletions 🧠 What I Learned: Sentinel nodes make linked list problems cleaner Hashing can reduce time complexity significantly Thinking in terms of nodes (not values) is key 🔥 Key Takeaways: Always look for ways to reduce nested loops Dummy nodes = lifesaver in linked list problems Practice is making pointer manipulation more intuitive Grateful for the guidance from Namaste DSA and Akshay Saini 🚀 Day 13 loading… 💪 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #LinkedList #DSA #NamasteDSA #AkshaySaini
To view or add a comment, sign in
-
🚀 Mastering a Classic Algorithm: Balanced Parentheses (Stack – LIFO) Today I revisited a fundamental problem that every Software Engineer should understand: validating balanced parentheses using a stack. Why it matters: This pattern appears in compilers, interpreters, and even real-world applications like expression parsing. Here’s the idea: 👉 Use a stack (LIFO) 👉 Push opening brackets 👉 Pop and match when encountering closing brackets 👉 Ensure the stack is empty at the end Clean and efficient JavaScript implementation 👇 This is a great reminder that mastering data structures like stacks is key to solving real algorithmic problems efficiently. I’m currently building and documenting algorithm patterns here: 🔗 https://lnkd.in/ej4fNeZs #SoftwareEngineering #JavaScript #Algorithms #DataStructures #Coding #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
🚀𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝: 𝐌𝐞𝐫𝐠𝐞 𝐍𝐨𝐝𝐞𝐬 𝐢𝐧 𝐁𝐞𝐭𝐰𝐞𝐞𝐧 𝐙𝐞𝐫𝐨𝐬 Solved a very interesting Linked List problem that focuses on pointer manipulation and in-place modification 🔍 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭: Given a linked list where: • The list starts and ends with 0 • Between every pair of 0s, there are some positive integers 👉 Merge all nodes between two 0s into a single node whose value is the sum of those nodes. 💡𝐊𝐞𝐲 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Instead of creating a new list, we can: 👉 Use the existing nodes and modify them in-place This makes the solution more efficient in terms of space. ⚙️ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐈 𝐔𝐬𝐞𝐝: 1. Use Two Pointers: • slow → points to position where result will be stored • fast → traverses the list 2. Traverse the List: • Keep adding values to sum until we hit a 0 3. When Encountering 0: • Assign sum to slow->val • Move slow forward • Reset sum to 0 4. Track Last Valid Node: • Keep pointer newLastNode to end the final list properly 5. Terminate the List: • Set newLastNode->next = NULL 🧠 𝐖𝐡𝐲 𝐓𝐡𝐢𝐬 𝐖𝐨𝐫𝐤𝐬: We reuse the original list nodes instead of allocating new memory. Each segment between zeros is compressed into a single node efficiently. 🧾 𝐂𝐨𝐫𝐞 𝐋𝐨𝐠𝐢𝐜: if(fast->val != 0){ sum += fast->val; } else{ slow->val = sum; slow = slow->next; sum = 0; } 📈𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: • Time Complexity: O(n) • Space Complexity: O(1) ✨ 𝐖𝐡𝐚𝐭 𝐈 𝐋𝐞𝐚𝐫𝐧𝐞𝐝: • In-place modification can optimize space • Two-pointer technique is very powerful • Always track the end of the new list carefully 🔥 Practicing more Linked List problems to strengthen fundamentals! #LeetCode #DSA #LinkedList #Coding #CPP #ProblemSolving #Algorithms
To view or add a comment, sign in
-
-
🚀 Day 7 of my DSA journey Making real progress! Today was all about moving beyond the 'for' loop and diving deep into the fundamentals of Recursion. 💻 Recursion is a technique where a function calls itself to solve a problem by breaking it down into smaller, identical sub-problems. ✅ The Anatomy of Recursion: 🔹 Base Case: Your exit strategy. The mandatory condition that stops the cycle once the goal is reached. 🔹 Recursive Step: The logic where the function calls itself with a modified input, moving closer to the base case. 🔹 The Call Stack: The memory’s "waiting room." Every call sits on top of the previous one until the base case is hit and the stack "unwinds." ⚠️ Where It Goes Wrong: Stack Overflow: When the "waiting room" gets too full; too many calls without an exit will crash the memory. Infinite Loops: The result of a missing or unreachable base case, causing the program to hang. Excited to start solving recursion problems from tomorrow! 🚀 The goal has evolved: From simple loops to recursive logic, keeping the complexity low. On to Day 8! ➡️ #Day7 #JavaScript #DSA #LeetCode #Recursion #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
🚀 DSA Day 17: From Theory to Code – Building the Foundation 🏗️ Today was a busy one, but I made sure to squeeze in some growth time. I focused on the "blueprint" of a Singly Linked List: ✅ The Node Factory: Created a constructor to give every piece of data its own value and a next pointer. ✅ The Structure: Initialized my MyLinkedList class with a head, tail, and a length tracker to keep things organized. It’s a simple start, but it’s the skeleton that makes everything else possible. 🔜 Coming up next: The "heavy lifting" begins! I’ll be tackling: 🔹 Get: How to find a value at a specific index (the "walk"). 🔹 Insert: Adding new nodes without breaking the chain. 🔹 Delete: Removing nodes and re-linking the pointers. The goal isn't just to write the code, but to visualize how those pointers shift in memory. 🧠✨ #Day17 #JavaScript #DSA #CodingJourney #LinkedList #LearningInPublic #WebDev #DataStructures #Consistency
To view or add a comment, sign in
-
🚀 Day 8/100 – #100DaysOfDSA Today’s challenge pushed me to go beyond basic sorting and think about efficient algorithms with optimal time complexity. 🔹 Problem Solved: Sort an Array(Merge sort) (without using built-in functions) 💡 Key Learning: 👉 To achieve O(n log n) time complexity, we need to use advanced sorting algorithms like: Merge Sort (Divide & Conquer) Quick Sort (Partition-based approach) 👉 Approach I focused on: Merge Sort Divide the array into halves Recursively sort each half Merge the sorted halves ✅ Time Complexity: O(n log n) ✅ Stable sorting algorithm ⚠️ Space Complexity: O(n) (extra space required) 🔥 Alternative: Quick Sort Faster in practice (on average) Works in-place ⚠️ Worst case: O(n²) ✅ Average: O(n log n) 🔥 What I learned today: Not all sorting algorithms are equal — choosing the right one depends on constraints like time, space, and input size. Moving from basic → advanced concepts step by step 🚀 #100DaysOfCode #DSA #Sorting #MergeSort #QuickSort #ProblemSolving #CodingJourney #JavaScript #TechGrowth #SoftwareEngineer #LearningInPublic
To view or add a comment, sign in
Explore related topics
- Leetcode Problem Solving Strategies
- LeetCode Array Problem Solving Techniques
- Problem Solving Techniques for Developers
- Approaches to Array Problem Solving for Coding Interviews
- Solving Sorted Array Coding Challenges
- Build Problem-Solving Skills With Daily Coding
- Tips for Finding Simple Solutions to Complex Problems
- How to Use Arrays in Software Development
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
I’m learning it too. Solved merge sorted arrays today. Keep going✨