📅 Day 49 of #100DaysOfCode Problem: 3228. Maximum Number of Operations to Move Ones to the End (LeetCode) Approach: 1️⃣ Keep a counter of how many '1's you’ve seen as you go through the string. 2️⃣ When you see a '0' that’s right before a '1' or at the end, you can “move” all those previous '1's past this '0' — so add that counter to the result. 3️⃣ Every time you hit a '1', increment the counter; for '0', check the condition and reset logic as needed. 4️⃣ Return the total operations counted — it’s just one pass through the string = O(n) time, O(1) space. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #Algorithms #Greedy #CodingChallenge #Programming #DeveloperLife #CodeNewbie #DailyDSA #SoftwareEngineering #KeepLearning #TechCommunity #GrowthMindset #Motivation
Solved LeetCode problem 3228 with a greedy approach
More Relevant Posts
-
📅 Day 44 of #100DaysOfCode Problem: Minimum Number of Operations to Make Array Continuous (LeetCode 2009) Approach: 1️⃣ For each element, assumed it to be the starting point of the range. 2️⃣ Calculated what the range should end at → start + n - 1. 3️⃣ Iterated over all numbers, counted how many don’t fit in this range (those need to be replaced). 4️⃣ Kept track of the minimum replacements across all possible ranges. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #Algorithms #CodingChallenge #Programming #DeveloperLife #CodeNewbie #DailyDSA #SoftwareEngineering #CodingJourney #TechCommunity #KeepLearning #GrowthMindset #Motivation #LearningInPublic
To view or add a comment, sign in
-
-
📅 Day 50 of #100DaysOfCode Problem: Simplify Path (LeetCode 71) Approach: 1️⃣ Used a stringstream to split the path by '/'. 2️⃣ Ignored empty tokens and "." since they don’t change the directory. 3️⃣ For "..", popped the last directory from the stack (if any). 4️⃣ Rebuilt the canonical path from the stack in the correct order. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Stacks #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodingJourney #CodeNewbie #DailyDSA #SoftwareEngineering #KeepLearning #GrowthMindset #Motivation #TechCommunity #CleanCode
To view or add a comment, sign in
-
-
📅 Day 31 of #100DaysOfCode Problem: Reverse Pairs (LeetCode 493) Approach: 1️⃣ Divide the array using merge sort to count pairs efficiently. 2️⃣ Count cross-pairs where nums[i] > 2 * nums[j] while merging. 3️⃣ Merge the halves back in sorted order to maintain correct comparisons. 4️⃣ Sum up counts from left, right, and cross halves for the final result. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #DailyDSA #SoftwareEngineering #CodingJourney #LearningInPublic #TechCommunity #KeepLearning #DivideAndConquer #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
📅 Day 48 of #100DaysOfCode Problem: Search in Rotated Sorted Array II (LeetCode 81) Approach: 1️⃣ First, used a pivot function to find the smallest element’s index, skipping duplicate values on both sides. 2️⃣ Once the pivot was found, split the array into two sorted parts. 3️⃣ Applied normal binary search on both halves to find the target. 4️⃣ Combined both steps to handle rotations and duplicates efficiently. #100DaysOfCode #LeetCode #DSA #ProblemSolving #BinarySearch #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #SoftwareEngineering #CodingJourney #DailyDSA #KeepLearning #TechCommunity #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
📅 Day 45 of #100DaysOfCode Problem: Count Operations to Obtain Zero (LeetCode 2169) 🧩 Approach: 1️⃣ Used a simple loop while both numbers are greater than zero. 2️⃣ In each step, added num1 / num2 to the count — because instead of subtracting repeatedly, we can do it in one go. 3️⃣ Took modulus to simulate the remainder after multiple subtractions. 4️⃣ Swapped numbers and repeated the process until one hit zero. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #DailyDSA #MathLogic #SoftwareEngineering #TechCommunity #KeepLearning #GrowthMindset #Motivation #CodingJourney
To view or add a comment, sign in
-
-
📖 Starting 𝗧𝗵𝗲 𝗥𝘂𝘀𝘁 𝗕𝗼𝗼𝗸. A key insight from the intro: Rust challenges one of programming’s oldest beliefs - that power and ease can’t coexist. It’s not just a language; it’s a philosophy. The compiler’s strictness isn’t friction, it’s guidance. It catches your mistakes before they exist, turning runtime bugs into compile-time conversations. And it comes with tools like Cargo, rustfmt, and rust-analyzer - each designed to make “systems-level” work feel natural and empowering. Let’s see how this mindset plays out in practice. 🦀 #RustLang #Programming #FullStackDeveloper #LearningInPublic #BuildingInPublic #100DaysOfRust #MakLearnsRust
To view or add a comment, sign in
-
-
📅 Day 42 of #100DaysOfCode Problem: Subsets (LeetCode 78) Approach: 1️⃣ Used backtracking to explore every possibility — either include the current element or skip it. 2️⃣ When the index reaches the end, added the current subset to the result. 3️⃣ Backtracked properly to remove elements before exploring the next choice. 4️⃣ This ensures every possible combination is covered without duplicates. #100DaysOfCode #LeetCode #Backtracking #Recursion #DSA #Cplusplus #ProblemSolving #CodingChallenge #Algorithms #Programming #DeveloperLife #CodeNewbie #DailyDSA #TechCommunity #KeepLearning #GrowthMindset #SoftwareEngineering #LearningInPublic #Motivation
To view or add a comment, sign in
-
-
🌟 Day 78 of #100DaysOfCode Today I solved the “Lemonade Change” 🍋 problem — a great exercise in Greedy Algorithms and logical decision-making. 🧩 The Problem: You’re running a lemonade stand where each glass costs $5. Customers pay with $5, $10, or $20 bills — and you must give the correct change for every transaction in order. 💡 The Approach: Maintain counts of $5 and $10 bills. For each customer: If they pay with $5 → keep it. If they pay with $10 → give one $5 as change. If they pay with $20 → try to give one $10 + one $5 (prefer larger denominations first), else give three $5 bills. If at any point change can’t be given → return false. ⚙️ Concept Used: ➡️ Greedy Algorithm — always make the optimal local decision (use larger bills first) to ensure global success. ✅ Takeaway: A simple problem that strengthens understanding of conditional logic, greedy thinking, and resource tracking in real-world scenarios. 💻✨ #DSA #Coding #CPlusPlus #ProblemSolving #GreedyAlgorithm #Programming #CodeNewbie #100DaysOfCodeChallenge
To view or add a comment, sign in
-
-
📅 Day 41 of #100DaysOfCode Problem: Merge k Sorted Lists (LeetCode 23) This one was all about optimization and clean recursion. Instead of merging lists one by one, I used a divide and conquer approach merge them in pairs, just like merge sort. Approach: 1️⃣ If there’s only one list, return it - base case. 2️⃣ Split the range of lists into two halves using recursion. 3️⃣ Merge both halves using a helper function that merges two sorted lists. 4️⃣ Keep dividing until everything is combined into one sorted list. #100DaysOfCode #LeetCode #DSA #Cplusplus #ProblemSolving #DivideAndConquer #Recursion #CodingChallenge #Algorithms #Programming #CodeNewbie #DeveloperLife #LearningInPublic #KeepLearning #SoftwareEngineering #TechCommunity #DailyDSA #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
📅 Day 28 of #100DaysOfCode 🚀 Problem: 49. Group Anagrams (LeetCode) Approach: -> For each string, sort its characters — the sorted version acts as a unique key for its anagram group. -> Store all words with the same sorted key inside a hash map (unordered_map<string, vector<string>>). -> After processing all words, collect all grouped values from the map into a result vector. ->This leverages hashing + sorting for efficient grouping — O(n * k log k) where k is average string length. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Cplusplus #CodingChallenge #Algorithms #DataStructures #Hashing #StringManipulation #CodingCommunity #Programming #DeveloperLife #LearnToCode #TechCommunity #DailyDSA #CodeNewbie #SoftwareEngineering #CodingJourney #Consistency #KeepLearning #LearningInPublic #GrowthMindset #Motivation
To view or add a comment, sign in
-