Solved LeetCode problem 3228 with a greedy approach

This title was summarized by AI from the post below.
View profile for Harsh Srivastava

Building Secure & Scalable Solutions | Software Engineer | Product Management | Cybersecurity | Full-Stack Development | Infosys Virtual Intern | Open Source Contributor | Problem-Solver | B.Tech CSE’26

📅 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

  • text

To view or add a comment, sign in

Explore content categories