id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,508
<p>You are given two positive integers <code>n</code> and <code>k</code>.</p> <p>You can choose <strong>any</strong> bit in the <strong>binary representation</strong> of <code>n</code> that is equal to 1 and change it to 0.</p> <p>Return the <em>number of changes</em> needed to make <code>n</code> equal to <code>k</c...
3
{ "code": "class Solution {\npublic:\n string decToBinary(int n)\n{\n // Size of an integer is assumed to be 32 bits\n string s=\"\";\n for (int i = 31; i >= 0; i--) {\n int k = n >> i;\n if (k & 1)\n s+=\"1\";\n else\n s+=\"0\";\n }\n return s;\n}\n\n in...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string_view s) {\n return ranges::any_of(s, [](char ch) { return string_view{\"aoeiu\"}.contains(ch); });\n }\n};", "memory": "14900" }
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "auto FastIO = [](){\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n return nullptr;\n}();\nclass Solution {\npublic:\n static bool doesAliceWin(string_view s) {\n return std::ranges::any_of(\"aioue\"s,[s](char ch){return s.contains(ch);});\n \n }\n};", "me...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\n \nprivate:\n \n unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u'};\n \npublic:\n \n bool doesAliceWin(string& s) {\n \n int aliceWins = false;\n \n for (auto ch: s) {\n if (vowels.find(ch) != vowels.end()) {\n a...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(const string& str) {\n unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u'};\n\n for (char c : str) {\n if (vowels.count(c)) {\n return true;\n }\n }\n return false;\n }\n};\n", "memory"...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "#include <vector>\n#include <unordered_set>\n#include <string>\n\nusing namespace std;\n\nclass Solution {\npublic:\n Solution() : st{'a', 'e', 'i', 'o', 'u'}, v(st.begin(), st.end()) {}\n\n bool doesAliceWin(const string& s) {\n int cnt = 0;\n for (char c : s) {\n if (v.find...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(const std::string& s) {\n int n = s.size();\n int vowelCount = 0;\n std::unordered_set<int> seen;\n\n // Variable to keep track of the current prefix sum\n int currentSum = 0;\n\n for (char c : s) {\n if (...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string& s) {\n int n = s.size();\n int vowelCount = 0;\n unordered_set<int> seen;\n\n \n int currentSum = 0;\n\n for (char c : s) {\n if (isVowel(c)) {\n vowelCount++;\n }\n\n ...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int c=0;\n for(int i=0;i<s.size();i++)\n {\n if(s[i]=='a'|| s[i]=='e'|| s[i]=='i'|| s[i]=='o'|| s[i]=='u')\n c++;\n }\n if(c>0)\n return true;\n else\n return false;...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\nprivate:\n bool isVowel(char ch){\n if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')return true;\n return false;\n }\npublic:\n bool doesAliceWin(string s) {\n ios_base::sync_with_stdio(false);\n cin.tie(nullptr);\n int n = s.le...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int t=0;\n for(char c : s){\n if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u') t++;\n }\n return (t>0);\n }\n};\n", "memory": "17300" }
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int vowels = 0 ; \n for( auto i : s ){\n if( i == 'a' || i == 'e' || i == 'i' || i == 'o' || i == 'u'){\n vowels++ ; \n }\n }\n if( vowels == 0 ){\n return false ; \n ...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
0
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int cnt = 0;\n for(int i=0;i<s.size();i++){\n if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u') cnt++;\n }\n \n return cnt!=0;\n \n }\n};", "memory": "17400" }
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
1
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) \n {\n int countVowel = 0;\n for(auto c:s)\n if(c == 'a' or c == 'e' or c == 'i'\n or c == 'o' or c == 'u') countVowel++; \n return countVowel;\n }\n};", "memory": "17500" }
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
1
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int count=0;\n for(char c:s)\n {\n if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')\n {\n count++;\n }\n }\n if(count==0) return false;\n return true;\n }\n}...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
2
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int n = s.size();\n int count = 0;\n for(int i=0;i<n;i++){\n if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u'){\n count++;\n }\n }\n if(count != 0...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
2
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int cnt=0;\n for(auto ch:s){\n if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'){\n cnt++;\n }\n }\n if(cnt==0) return false;\n return true;\n }\n};", "memory": "17600" ...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int cnt = 0;\n vector<char> v = {'a','e','i','o','u'};\n for(auto it: s){\n if(find(v.begin(), v.end(),it) != v.end())\n cnt++;\n }\n if(cnt == 0) return false;\n if(cnt != 0 && cn...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int vowelCount = 0;\n set<char> charst ={'a','e','i','o','u'};\n for(char& c :s){\n if(charst.contains(c)){\n vowelCount++;\n }\n }\n if(vowelCount){\n return tr...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n set<char> vowels = {'a' , 'e' , 'i' , 'o' , 'u'};\n int cnt = 0;\n for(auto &x : s){\n if(vowels.find(x) != vowels.end()) cnt++;\n }\n if(cnt) return true;\n return false;\n }\n};", "mem...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int cnt=0;\n set<char> st={'a','e','i','o','u'};\n for(int i=0;i<s.length();i++){\n if(st.find(s[i])!=st.end())cnt++;\n }\n if(cnt==0)return false;\n return true;\n }\n};", "memory": "18...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n unordered_set<char> vowels = {'a','e','i','o','u'};\n int countOfVowels = 0;\n for(auto c:s){\n if(vowels.find(c) != vowels.end()){\n countOfVowels++;\n }\n }\n\n if(countO...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n bool noVowels = true;\n std::unordered_set<char> us{'a','e','i','o','u'};\n for(char c : s) {\n if(us.count(c)>0) {\n noVowels = false;\n }\n }\n if(noVowels) return false;...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n int memo[100000][2];\n bool doesAliceWin(string s) {\n int count = 0;\n memset(memo,-1,sizeof(memo));\n for(char c: s){\n if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')\n count++;\n }\n if(count == 0) return false;\n...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution \n{\nprivate:\n unordered_set<char> vowels = {'a','e','i','o','u'};\npublic:\n bool doesAliceWin(string s) \n {\n int vowel_count;\n for (auto c : s)\n if (vowels.find(c) != vowels.end()) return true;\n return false;\n }\n};", "memory": "18400" }
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int count = 0;\n unordered_set<char> st;\n st.insert('a');\n st.insert('e');\n st.insert('i');\n st.insert('o');\n st.insert('u');\n for(int i = 0;i<s.size();i++){\n if(st.count...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n unordered_set<char> vowel_list;\n vowel_list.insert('a');\n vowel_list.insert('e');\n vowel_list.insert('i');\n vowel_list.insert('o');\n vowel_list.insert('u');\n\n int vowel_count = 0;\n ...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int n = s.size();\n unordered_map<char, int> mp;\n for (int i = 0; i < n; i++) {\n if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||\n s[i] == 'u') {\n mp[s[i]]++;\n ...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(std::string s) {\n // Define a set of vowels for easy lookup\n std::unordered_set<char> vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};\n \n // Count the number of vowels in the string\n int vowelCount = 0;...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool doesAliceWin(string s) {\n int n=s.size();\n map<int,int>mp;\n int v=0;\n bool odd=0,even=0;\n mp[0]=1;\n for(char ch:s)\n {\n if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')\n ++v;\n ...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n bool isVowle(char c) {\n static set<char> st({'i','o','e','a','u'});\n return st.find(c) != st.end();\n }\n bool doesAliceWin(string s) {\n int num = 0;\n for (auto c:s) {\n if (isVowle(c)) {\n num++; \n }\...
3,462
<p>Alice and Bob are playing a game on a string.</p> <p>You are given a string <code>s</code>, Alice and Bob will take turns playing the following game where Alice starts <strong>first</strong>:</p> <ul> <li>On Alice&#39;s turn, she has to remove any <strong>non-empty</strong> <span data-keyword="substring">substrin...
3
{ "code": "class Solution {\npublic:\n unordered_map<char, int> v = {\n {'a', 1}, {'e', 1}, {'i', 1}, {'o', 1}, {'u', 1},\n };\n bool doesAliceWin(string s) {\n for (char ch : s) {\n if (v[ch])\n return true;\n }\n return false;\n }\n};", "memory": "...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string& s) {\n cin.tie(nullptr) -> sync_with_stdio(false);\n /*std::vector<int> dp(s.length(),0);\n if(s[0]=='1') dp[0]=1;\n for(int i=1;i<s.length();i++){\n if(s[i]=='1') dp[i]=dp[i-1]+1;\n else dp[i]=dp[i-1...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "#include <string>\nusing namespace std;\n\nclass Solution {\n\npublic:\n int maxOperations(const string& binaryString) const {\n int countOnes = binaryString[0] - '0';\n int maxOperations = 0;\n\n for (size_t i = 1; i < binaryString.size(); ++i) {\n countOnes += binaryStr...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string_view s) {\n //1000111\n //2\n int cnt{0};\n int ans{0};\n for(int i = 0;i<s.size();i++){\n if(s[i]=='1'){\n cnt++;\n }else{\n while(i<s.size() && s[i]=='0')i++;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string_view s) {\n int oneCount = 0, ans = 0, n = s.size();\n for(int i = 0; i < n; i++)\n {\n if(s[i] == '0') ans += oneCount;\n while(i < n and s[i] == '0') ++i;\n if(i < n && s[i] == '1') ++oneCount;\n...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n static int maxOperations(const string &s) {\n const uint n = s.length();\n uint t = 0, k = 0, i = 0;\n for ( ; i < n && s[i] == '0'; i++)\n ;\n bool z = false;\n for ( ; i < n; i++) {\n const bool y = s[i] & 1;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n /*\n 1 0 0 1 1 0 1\n In any case we encounter a 10, we will have to move the 1 till either the end of array\n or till we find another 1.\n this entire thing of finding a 10 and moving 1 is considered as a single operation\n the number of 0s or how many places m...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int cnt=0;\n int n=s.length();\n int totalcnt=0;\n for(int i=0;i<n;i++)\n {\n if(s[i]=='1') cnt++;\n else if(i<s.length()&&s[i]=='0'&&s[i+1]=='0') continue;\n else \n {\...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int last_one=s.length()-1;\n // int last_zero;\n // int j=s.length()-1;\n // while(j>=0&&s[j]=='0')j--;\n // last_one=j;\n int i=last_one;\n while(i>=0&&s[i]=='1')i--;\n int k=0;int count=...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int one = 0, zero = 0, count = 0, ans = 0;\n for(int i = s.length()-1; i >= 0; i--){\n if(s[i] == '0'){\n zero++;\n }\n if(s[i] == '1'){\n if(zero > 0){\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n = s.length();\n int count=0;\n int ans=0;\n if(s[0]=='1') count++;\n for(int i=1;i<n;i++) {\n if(s[i]=='0' && s[i-1]=='1') {\n ans+=count;\n } else if(s[i]=='1') coun...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n const int N = s.length();\n int result = 0;\n int zeroGroupCnt = 0;\n\n for (int i = N - 1; i >= 0; --i) {\n if (s[i] == '0') {\n if (i == N - 1 || s[i + 1] != '0') {\n ++...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
0
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n const int N = s.length();\n int result = 0;\n int oneCnt = 0;\n\n for (int i = 0; i < N; ++i) {\n if (s[i] == '0') {\n result += oneCnt;\n\n while (i < N && s[i] == '0') {\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
1
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n reverse(s.begin(), s.end());\n int startindex = 0;\n for (int i = 0; i < s.size(); i++) {\n\n if (s[i] == '0' || i==s.size()-1) {\n startindex = i;\n break;\n }\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
1
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n = s.size(), o_cnt = 0, s_cnt = 0,idx = n-1, skip = 0;\n bool enc = false;\n if(idx == -1) return 0;\n bool smaran = false;\n for(;idx>=0;--idx){\n if(s[idx]=='1' && !enc) continue;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n reverse(s.begin(),s.end());\n int n = s.size();\n int startIndex ;\n int ops=0;\n int j;\n for(int i=0;i<n;i++)\n {\n if(s[i]=='0')\n {\n startIndex = i;\n break;\n } \n }...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s)\n {\n int x=0;\n int n=s.size();\n int ans=0;\n string y=\"\";\n \n for(int i=0;i<n-1;i++)\n {\n if(s[i]=='1')\n {\n x++;\n }\n if(s[i]...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n \n int n = s.length();\n int prev[n+1];\n prev[0] = 0;\n for(int i =0; i < n ; i++){\n if(s[i] == '1'){\n prev[i+1] = prev[i]+1;\n }else{\n prev[i+1]= prev[i...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n=s.size();\n int pre[n];\n if(s[0]=='1') pre[0]=1;\n else pre[0]=0;\n for(int i=1;i<n;i++){\n if(s[i]=='1') pre[i]=pre[i-1]+1;\n else pre[i]=pre[i-1];\n }\n int count=0...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int one =0 ;\n\n while(s.size()){\n if(s.back() == '0') one = 1,s.pop_back();\n else break;\n }\n if(s.size() == 0) return 0;\n \n int n = s.size();\n int post[n+1];\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic: \n int maxOperations(string s) {\n int n=s.size();\n int a=0;\n if(s[n-1]=='1'){\n s+=\"0\";\n a=1;\n }\n\n int k=0;\n int ans=0;\n for(int i=0;i<n;i++){\n if(s[i]=='1'){\n k++;\n...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic: \n int maxOperations(string s) {\n int n=s.size();\n int a=0;\n if(s[n-1]=='1'){\n s+=\"0\";\n a=1;\n }\n int k=0;\n int ans=0;\n for(int i=0;i<n;i++){\n if(s[i]=='1'){\n k++;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int i=0,j=0;\n stack<int> st;\n int cnt=0,k=0;\n while(i<s.length()-1){\n if(s[i]=='1' && s[i+1]=='0'){\n j=i+1;\n while(s[j+1]!='1'){\n j++;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n stack<int>q;\n int cnt=0;\n int ans=0;\n int n=s.size();\n for(int i=0;i<n;i++){\n \n if(s[i]=='0'){\n ans+=cnt;\n while(i<n&&s[i]!='1'){\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n stack<int>st;\n int n=s.length();\n int ans=0;\n int countone=0;\n for(int i=0; i<n; i++){\n if(s[i]=='0'){\n ans+=countone;\n }\n while(i<n && s[i]!='1'){\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n // s+=('0');s+=('1');\n int n = s.length();\n if(s[n-1] == '0') s+='1',n++;\n int flag = 0;int ans = 0;\n for(int i=0;i<n;i++){\n // cout<<flag<<endl;\n if(s[i] == '1'){\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int ans = 0;\n int countone = 0;\n for(auto x : s){\n if(x=='1')\n countone++;\n }\n if(s.back()=='0'){\n s.push_back('1');\n countone++;\n }\n int...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int temp =0;\n int ret =0;\n int check =0;\n s= s+'1';\n for(int i=0;i<s.length();i++)\n {\n if( s[i]=='1')\n {\n if(check ==1 )\n {\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int l=0,r=0;\n int n = s.size();\n int cnt = 0;\n map<char,int>mpp;\n while(r<n){\n if(s[r]=='0'){\n mpp['0']++;\n }\n else{\n if(mpp['0']>0){\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int allOneAtBegining(string str){\n int n=str.length(),c0=0,cb=0,f=0;\n for(int i=0;i<n;i++){\n if(str[i]=='0'){\n c0++;\n if(f==0) cb++;\n }\n if(str[i]=='1') f=1;\n }\n\n return c0==c...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int lastOne = -1;\n int count = 0;\n int numOnes = 0; \n s.push_back('1');\n for (int i = 0; i < s.length(); i++) {\n if (s[i] == '1') {\n if (lastOne < i - 1) {\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int ones = 0;\n int res = 0;\n bool resetOnes = false;\n s += '1';\n for(int i = 0;i < s.size(); i++) {\n if(s[i] == '1') {\n ones++;\n resetOnes = true;\n }...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n s += '1';\n int ans = 0 ;\n int cnt1 = 0;\n int cnt0 = 0;\n for(int i=0;i<s.size();i++)\n {\n if(s[i] == '1')\n {\n if(cnt0 > 0) ans += cnt1;\n cnt0 =...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int ones=0, result=0;\n string temp=\"1\";\n s+=temp;\n for(int i=0;i<s.size();i++){\n if(s[i]=='0') continue;\n if(i>0&&s[i-1]=='0')\n result+=ones;\n ones++;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\n int maxOperations(string& s, int blocksAfter) {\n if (s.empty()) {\n return 0;\n }\n while (!s.empty() && s.back() == '0') {\n s.pop_back();\n }\n int onesInBlock = 0;\n while (!s.empty() && s.back() == '1') {\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) \n {\n stack<int>st;\n int i=s.size()-1;\n while(i>=0&&s[i]=='1')\n {\n i--;\n }\n for(int j=i;j>=0;j--)\n {\n int count=0;\n while(j>=0&&s[j]=='1')\n {...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n\n int n=s.length();\n int ans=0;\n bool a=1;\n bool b=0;\n int k=0;\n int i=0;\n\n stack<char>st;\n\n for(int i=0;i<n;i++)\n {\n st.push(s[i]);\n }\n\n whil...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n stack<char> st;\n int ans = 0;\n int index = -1;\n for(int i=0; i<s.size(); i++) {\n if(s[i] == '1') {\n st.push('1');\n i++;\n while(s[i] == '1' && i<s.size())...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n // now imagine we take \n // 1 0 0 1 1 0 1\n // 0 0 1 1 1 0 1\n stack<pair<int,int>> st;\n\n int res = 0;\n int n = s.length();\n for(int i = 0 ;i<n ; i++)\n {\n if(s[i]=='1')\n...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int ans = 0;\n \n int n = s.size();\n\n stack<char>st;\n \n for(int i = 0; i < n ; i++){\n if(st.empty()){\n st.push(s[i]);\n }\n else ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n \n int cnt=0;\n \n string ans=\"\";\n \n for(int i=0;i<s.size();i++)\n {\n if(s[i]=='1')\n {\n ans+=s[i]; \n }\n else{\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n string ak; int i=0;\n while(i<s.size()){\n if(s[i]!='0') {ak+=s[i]; i++;}\n else{\n ak+='0';\n while(i<s.size() && s[i]=='0'){\n i++;\n }\n }\n }\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n priority_queue <char, vector<char>, greater<char>>q;\n reverse(s.begin(),s.end());\n q.push(s[0]);\n \n bool flag =false;\n int count0=0;\n int count=0,sum=0;\n if(s[0]=='0'){ count0++;\n...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n string s1;\n // s1.push_back(s[0]);\n for(int i=0;i<s.length();i++){\n // if(s1[i-1]=='0'&&s[i]=='0')continue;\n if(s[i]=='0'){\n while(s[i]=='0')i++;\n i--;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int ans = 0;\n vector<int> oneSegs;\n for(int i = 0; i < s.length() -1; i++){\n int ones = 0;\n if(s[i] - '0' == 1){\n ones = 1;\n while(i + 1 < s.length() && s[i+1] - '0'...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int ans = 0;\n vector<int>temp;\n for(int i=0;i<s.size();i++){\n if(s[i]=='1' && i!=s.size()-1){\n int count=1;\n while(i+1<s.size() && s[i+1]=='1'){\n count++;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n \n int n = s.length();\n vector<int> ones;\n int i = 0;\n\n while(i < n)\n {\n int size = 0;\n while(i < n && s[i] == '1')\n {\n size++;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n=s.size();\n int c=0;\n vector<int>vp;\n for(int i=0;i<n;i++){\n if(s[i]=='1')c++;\n else{\n if(c>0)vp.push_back(c);\n c=0;\n }\n }\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n vector<int> st;\n int f=-1,n=s.size();\n for(int i=0;i<n;++i){\n if (s[i]=='0' and f==-1){\n f=i;\n st.push_back(f);\n }else if(s[i]=='1'){\n f=-1;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n vector<int> temp;\n int ret = 0;\n int cons_one = 0;\n for (int i = 0; i < s.length(); i++) {\n switch (s[i]) {\n case '1':\n cons_one += 1;\n break;\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n=(int)s.size();\n int ans=0;\n\n stack<int> st;\n s+='1';\n int i=0;\n while(i<=n)\n {\n if(st.size()==0)\n {\n st.push(s[i]-'0');\n i++...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n=(int)s.size();\n int ans=0;\n\n stack<int> st;\n s+='1';\n int i=0;\n while(i<=n)\n {\n if(st.size()==0)\n {\n st.push(s[i]-'0');\n i++...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n=s.size(),i, ans=0, zero=0;\n stack<int>st;\n for(i=0;i<n;i++)\n {\n if(s[i]=='1')\n {\n if(zero)\n {\n ans+=st.size();\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int n=s.size(),i, ans=0, zero=0;\n stack<int>st;\n for(i=0;i<n;i++)\n {\n if(s[i]=='1')\n {\n if(...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\nprivate:\n string removeZero(string s) {\n string ans = \"\";\n for(int i=0;i<s.size();i++){\n if(s[i]=='0' && i+1<s.size() && s[i+1]=='0')\n continue;\n ans+=s[i];\n }\n\n return ans;\n }\npublic:\n int maxOperatio...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n = s.length();\n int i = 0, j = 0;\n vector<int> arr;\n while(j < n && i < n) {\n if(s[i] == '1') {\n while(j < n && s[j] == '1') {\n j++;\n }\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string A) {\n int n=A.size();\n vector<int>v;\n int cnt=0;\n for (int i = 0; i < n; i++) {\n if (A[i] == '1') {\n cnt++;\n } else {\n if (cnt > 0) {\n v.push_b...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "auto debug(auto a){\n while (!a.empty()){\n cout << a.top() << \" \";\n a.pop();\n }\n cout << '\\n';\n}\n\nclass Solution {\npublic:\n int maxOperations(string s) {\n int ans = 0;\n int n = s.size();\n stack<int> st;\n int curr = 0;\n for (int i...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n \n s = s + \"1\";\n int n = s.size();\n int start = 0;\n vector<int>ans;\n for(int i = 0 ; i<n ; i++)\n {\n if(s[i] == '1')\n {\n start++;\n }\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n vector<int> cnt; \n s += '0';\n int len = 0; \n char last = '0'; \n for (int i=0; i<ssize(s); i++) {\n if (last != s[i]) {\n if (s[i] == '1') {\n len = 1; \n } else {\n cn...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int ans=0;\n s+=\"1\";\n vector<int> ones_group;\n int count = 0;\n\n for (char c : s) {\n if (c == '1') {\n count++;\n } else if (count > 0) {\n ones_group....
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n = size(s);\n vector<int>dp(n,0);\n if(s.back() == '0'){\n dp.back() = 1;\n }\n for(int i=n-2;i>=0;i--){\n if(s[i] == '0' && s[i+1] == '0'){\n dp[i] = dp[i+1];\n }else if(s[i] == '1' && s[i+1] == '0'){\n ...
3,493
<p>You are given a <span data-keyword="binary-string">binary string</span> <code>s</code>.</p> <p>You can perform the following operation on the string <strong>any</strong> number of times:</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the string where <code>i + 1 &lt; s.length</code> such that ...
3
{ "code": "class Solution {\npublic:\n int maxOperations(string s) {\n int n = s.length();\n vector<int> v(n,0);\n v[0]=s[0]-'0';\n for(int i=1;i<n;i++) {\n v[i] = (v[i-1]+(s[i]-'0'));\n } \n int ans=0;\n for(int i=n-1;i>0;i--) {\n if(s[i]=='0'...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n long lo...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
0
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n long increase = 0, decrease = 0, operations = 0;\n\n for (int i = 0; i < n; ++i) {\n int difference = target[i] - nums[i];\n\n if (difference > 0) {\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
1
{ "code": "using LL = long long;\nclass Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n int diff[n];\n for(int i=0; i<n; i++) diff[i] = target[i]-nums[i];\n\n LL min_oper = 0;\n for(int l=0; l<n; l++){\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
1
{ "code": "using LL = long long;\nclass Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n int diff[n];\n for(int i=0; i<n; i++) diff[i] = target[i]-nums[i];\n\n LL min_oper = 0;\n for(int l=0; l<n; l++){\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
1
{ "code": "class Solution {\npublic:\n long long help(vector<int>& arr) {\n int n = arr.size();\n if (!n) {\n return 0;\n }\n long long res = abs(arr[0]);\n for (int i = 1; i < n; i++) {\n if (abs(arr[i]) > abs(arr[i - 1])) {\n res += abs(arr[...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
1
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n(nums.size());\n stack<int> stk({0});\n long res(0);\n for (int i(0); i <= n; ++i) {\n int dif = i < n ? target[i]-nums[i] : 0;\n if (stk.top() < dif...