From abad45a47e9040fdf4606906294fc1495416747b Mon Sep 17 00:00:00 2001 From: chayan das Date: Fri, 14 Nov 2025 00:21:23 +0530 Subject: [PATCH] Create 3228. Maximum Number of Operations to Move Ones to the End --- ...mber of Operations to Move Ones to the End | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 3228. Maximum Number of Operations to Move Ones to the End diff --git a/3228. Maximum Number of Operations to Move Ones to the End b/3228. Maximum Number of Operations to Move Ones to the End new file mode 100644 index 0000000..5a8dd45 --- /dev/null +++ b/3228. Maximum Number of Operations to Move Ones to the End @@ -0,0 +1,21 @@ +class Solution { +public: + int maxOperations(string s) { + int ans = 0; + int count = 0; + int n = s.size(); + bool flag = true; + + for (int i = 0; i < n; i++) { + if (s[i] == '0' && flag) { + ans += count; + flag = false; + } + else if (s[i] == '1') { + count++; + flag = true; + } + } + return ans; + } +};