🚀 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
100 Days of DSA: Merge Sort and Quick Sort
More Relevant Posts
-
🚀 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
-
🚀 DSA Day 16: Diving into Linked Lists! 🔗🧠 After mastering sorting algorithms, it’s time to shift gears from how we organize data to how we store it. Today, I started with Linked Lists! ✅ What is a Linked List? It is a linear data structure where elements aren't stored at fixed memory locations. Instead, each "Node" contains: 1️⃣ Data: The value you want to store. 2️⃣ Next: A pointer (link) to the next node in the line. ⛓️ Types I Explored: 🔹 Singly Linked List: One-way traffic—each node points only to the next. 🔹 Doubly Linked List: Two-way street—nodes point to both the next and the previous ones. 🔹 Circular Linked List: No dead ends—the last node loops back to the start! ⚖️ Array vs. Linked List – The Showdown: Memory: Arrays need a single block of space; Linked Lists can be scattered anywhere in memory. 🧩 Insertion/Deletion: Linked Lists win! You just change a pointer (O(1)) instead of shifting every single element like in an array (O(n)). ⚡ Access: Arrays win here. You can jump to any index instantly (O(1)), whereas in a Linked List, you have to "walk" from the head (O(n)). 🚶♂️ 🎯 The Lesson: Use Arrays for fast lookups; use Linked Lists for frequent adding and removing! 🛠️ On to Day 17! ➡️ #Day16 #JavaScript #DSA #LinkedList #DataStructures #CodingJourney #LearningInPublic #WebDevelopment #Programming #TechBasics
To view or add a comment, sign in
-
-
🚀 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
To view or add a comment, sign in
-
📌 Day 2/100 – #100DaysOfDSA Continuing the journey 🚀 🔍 Problem Solved: Best Time to Buy and Sell Stock (LeetCode 121) 🧠 What I learned: How to track the minimum price so far while iterating Calculating maximum profit in a single pass Optimizing from brute force O(n²) → O(n) ✅ Solution Approach: Traverse the array once 👣 Update the minimum price Calculate profit at each step and track the maximum 📈 💡 Key Insight: Instead of checking all pairs, track the lowest price before the current day 💻 Code (JavaScript): var maxProfit = function (prices) { let min = prices[0]; let maxProfit = 0; for (let i = 0; i < prices.length; i++) { if (min > prices[i]) { min = prices[i]; } if (prices[i] - min > maxProfit) { maxProfit = prices[i] - min; } } return maxProfit; }; ⚡ Takeaway: A simple observation can drastically reduce complexity — that’s the power of DSA Consistency is the goal — Day 2 done ✅ If you're also solving daily, let’s connect and grow together 🤝 #100DaysOfDSA #DataStructures #Algorithms #LeetCode #Programming #DeveloperJourney #ProblemSolving
To view or add a comment, sign in
-
🚀 Today’s LeetCode Solve: 3Sum (Problem #15) Today I solved LeetCode 15 – 3Sum, a classic problem that strengthens two-pointer and sorting concepts. 🔍 Problem summary: Given an array, find all unique triplets such that: nums[i] + nums[j] + nums[k] = 0 💡 Approach used: --> First, sort the array --> Fix one element and use two pointers (left, right) for the remaining part --> Skip duplicates to ensure only unique triplets --> Move pointers based on the sum: --> If sum < 0 → move left pointer --> If sum > 0 → move right pointer -->If sum == 0 → store result and move both ⚡ Efficiency: --> Time Complexity: O(n²) --> Space Complexity: O(1) (excluding result list) 📌 Key takeaway: Combining sorting + two-pointer technique is a powerful pattern for many array problems. Challenging problem, but great learning experience 💪 #LeetCode #DSA #3Sum #TwoPointers #ProblemSolving #Algorithms #CodingPractice #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 28/50 – LeetCode Challenge 🧩 Problem: String Compression Today’s problem focused on modifying an array in-place while compressing repeated characters — a great exercise in two pointers and string manipulation. 📌 Problem Summary: Given an array of characters, compress it by replacing consecutive repeating characters with the character followed by its count. Example: Input: ["a","a","b","b","c","c","c"] Output: ["a","2","b","2","c","3"] The compression must be done in-place without using extra space. 🔍 Approach Used ✔ Used two pointers: one for reading characters one for writing compressed result ✔ Counted consecutive repeating characters ✔ Wrote the character and its count (if > 1) ✔ Continued until the end of the array ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) 💡 Key Learning ✔ In-place array manipulation ✔ Efficient use of two pointer technique ✔ Handling counts and conversions to string ✔ Writing optimized space-efficient solutions This problem highlights how careful pointer management can lead to efficient solutions. Consistency builds strong problem-solving skills 🚀 🔗 Problem Link: https://lnkd.in/geeBTB3P #50DaysOfLeetCode #LeetCode #DSA #TwoPointers #Strings #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
To view or add a comment, sign in
-
-
🚀 Day 31/50 – LeetCode Challenge 🧩 Problem: Decode Ways Today’s problem focused on finding the number of ways to decode a numeric string into letters — a great exercise in recursion and backtracking. 📌 Problem Summary: Given a string of digits, count the number of ways to decode it where: '1' → 'A', '2' → 'B', … , '26' → 'Z' Example: Input: "226" Output: 3 Possible decodings: "2 2 6" → B B F "22 6" → V F "2 26" → B Z 🔍 Approach Used (Backtracking) ✔ Explored all possible ways recursively ✔ At each step: Took one digit (if valid) Took two digits (if between 10–26) ✔ Skipped invalid cases like: leading 0 numbers > 26 ✔ Counted all valid decoding paths ⏱ Time Complexity: O(2ⁿ) (exploring all possibilities) 📦 Space Complexity: O(n) (recursion stack) 💡 Key Learning ✔ Understanding backtracking for exploring choices ✔ Handling constraints carefully (like 0 cases) ✔ Breaking problems into smaller subproblems ✔ Realizing when optimization (DP) is needed This problem shows how recursion can generate all possibilities, but also highlights the need for optimization using DP for better performance. Consistency builds strong problem-solving skills 🚀 🔗 Problem Link: https://lnkd.in/gdQpmEeJ #50DaysOfLeetCode #LeetCode #DSA #Backtracking #Recursion #DynamicProgramming #ProblemSolving #CodingJourney #FutureAIEngineer #Consistency
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
-
-
🚀 𝐆𝐅𝐆 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝: 𝐂𝐨𝐮𝐧𝐭 𝐭𝐡𝐞 𝐑𝐞𝐯𝐞𝐫𝐬𝐚𝐥𝐬 Solved an interesting problem on stacks and string balancing that really tests logical thinking 🔍 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐭𝐚𝐭𝐞𝐦𝐞𝐧𝐭: Given a string consisting of only { and }, find the minimum number of reversals required to make the string balanced. 💡 𝐊𝐞𝐲 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: A valid (balanced) string must have: • Equal number of opening { and closing } brackets. • Proper ordering. 👉 If the string length is odd, it can never be balanced ❌ ⚙️ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 𝐈 𝐔𝐬𝐞𝐝: 𝟏. 𝐂𝐡𝐞𝐜𝐤 𝐎𝐝𝐝 𝐋𝐞𝐧𝐠𝐭𝐡: • If n % 2 != 0 → return -1 𝟐. 𝐔𝐬𝐞 𝐒𝐭𝐚𝐜𝐤 𝐟𝐨𝐫 𝐏𝐫𝐨𝐜𝐞𝐬𝐬𝐢𝐧𝐠: • Traverse the string • Push { into stack • For }: a. If stack top is { → pop (valid pair) b. Else → push } 𝟑. 𝐇𝐚𝐧𝐝𝐥𝐞 𝐑𝐞𝐦𝐚𝐢𝐧𝐢𝐧𝐠 𝐔𝐧𝐛𝐚𝐥𝐚𝐧𝐜𝐞𝐝 𝐁𝐫𝐚𝐜𝐤𝐞𝐭𝐬: • After traversal, stack contains only invalid pairs 𝟒. 𝐂𝐨𝐮𝐧𝐭 𝐑𝐞𝐯𝐞𝐫𝐬𝐚𝐥𝐬: • Pop two elements at a time: a. If both same ({{ or }}) → 1 reversal b. If different (}{) → 2 reversals 🧠𝐖𝐡𝐲 𝐓𝐡𝐢𝐬 𝐖𝐨𝐫𝐤𝐬: The stack helps eliminate already balanced pairs. What remains are only invalid combinations, which we fix optimally by counting minimum reversals. 🧾𝐂𝐨𝐫𝐞 𝐋𝐨𝐠𝐢𝐜: if(a == b) ans += 1; else ans += 2; 📈 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: • Time Complexity: O(n) • Space Complexity: O(n) ✨ 𝐖𝐡𝐚𝐭 𝐈 𝐋𝐞𝐚𝐫𝐧𝐞𝐝: • Stack is very useful for bracket-related problems • Eliminating valid pairs simplifies the problem • Edge cases like odd length are very important 🔥 Small problems, big learning! #DSA #Stack #GeeksforGeeks #Coding #CPP #ProblemSolving #Algorithms
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