id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string getBinary(int num){\n string ans;\n while(num){\n ans+= num%2 ? '1' : '0';\n num/=2;\n }\n string a;\n for(int i=ans.size()-1;i>=0;i--){\n a+=ans[i];\n }\n return ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string toBinary(int n)\n {\n string str = \"\";\n while (n > 0){\n str += (n&1)+'0';\n n >>= 1;\n }\n reverse(str.begin(),str.end());\n return str;\n }\n string convertDateToBinary(string date)\n {\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string d) {\n string tmp=\"\";\n for(int i=0;i<4;i++) tmp.push_back(d[i]);\n string ans=\"\";\n\n int a=stoi(tmp);\n int ps=0;\n\n for(int i=15;i>=0;i--){\n if((a >> i) & 1){\n ps=...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string intToBin(int num){\n string s=\"\";\n while(num){\n s+=(num%2+'0');\n num=num/2;\n }\n reverse(s.begin(), s.end());\n return s;\n }\n string convertDateToBinary(string date) {\n int year=0;\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int year = (date[0]-48)*1000 + (date[1]-48)*100 + (date[2]-48)*10 + (date[3]-48);\n int month = (date[5]-48)*10 + (date[6]-48);\n int day = (date[8]-48)*10 + (date[9]-48);\n return convert(year)+\"-\"+con...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int y=0, m=0, d=0;\n sscanf(date.c_str(), \"%d-%d-%d\", &y, &m, &d);\n const auto itob = [](int x) -> std::string {\n std::string res = \"\";\n int dig = 0;\n while ((x >> dig) >...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n static string to_binary(int x){\n int bit=31-__builtin_clz(x);\n string ans=\"1\";\n for(int i=bit-1; i>=0; i--){\n ans+=(x & (1<<i))?'1':'0';\n }\n return ans;\n }\n static string convertDateToBinary(string& date) {\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string convertBinary(string data) {\n int converted = 0;\n for (auto it : data) {\n converted = converted * 10 + (it - '0');\n }\n string answer = \"\";\n while (converted) {\n if (converted % 2)\n answer...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n static string to_binary(int x) {\n int bit = 31 - __builtin_clz(x);\n string ans = \"1\";\n for (int i = bit - 1; i >= 0; i--) {\n ans += (x & (1 << i)) ? '1' : '0';\n }\n return ans;\n }\n static string convertDateToBinary(...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n static string to_binary(int x) {\n int bit = 31 - __builtin_clz(x);\n string ans = \"1\";\n for (int i = bit - 1; i >= 0; i--) {\n ans += (x & (1 << i)) ? '1' : '0';\n }\n return ans;\n }\n static string convertDateToBinary(...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int year = stoi(date.substr(0, 4));\n int month = stoi(date.substr(5, 2));\n int day = stoi(date.substr(8, 2));\n string y_str = \"\";\n string m_str = \"\";\n string d_str = \"\";\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n string str,str1,str2;\n for(int i=0;i<date.size();i++){\n if(date[i]!='-'){\n str+=date[i];\n }\n else{\n int val=stoi(str);\n bitset<16>decimal(val);\n str1=decimal.to_string();\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\nstring f (int a){\n string x = \"\";\n int size = 0 ;\n while(a>0){\n if(a%2==0){\n x += '0';\n }else{\n x += '1';\n }\n a = a/2 ;\n size ++ ;\n }\n int l = 0 , r = size - 1 ;\n while(l<=r){\n char ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\nprivate:\n static std::string ToBinary(int num) {\n std::string bin;\n bool bNonZero = false;\n for (int i = 8*sizeof(num)-1; i >= 0; --i) {\n if (!(num & (1 << i))) {\n if (bNonZero) {\n bin.push_back('0');\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string DecimalToBinary(int num)\n {\n string str;\n while(num){\n if(num & 1)\n str+='1';\n else\n str+='0';\n num>>=1; \n } \n reverse(str.begin(), str.end());\n return str...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
0
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n string str,str1,str2;\n for(int i=0;i<date.size();i++){\n if(date[i]!='-'){\n str+=date[i];\n }\n else{\n int val=stoi(str);\n bitset<16>decimal(val);\n str1=decimal.to_string();\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\npublic:\n string stringtobin(int &s){\n string binary = bitset<32>(s).to_string();\n int i=binary.find('1');\n return binary.substr(i);\n }\n string convertDateToBinary(string &date) {\n int year=stoi(date.substr(0,4));\n int month=stoi(date.substr(5,2));\...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\npublic:\n string solve(int a) {\n string ans = \"\";\n while (a) {\n if (a % 2 == 1) {\n ans += '1';\n a /= 2;\n } else {\n ans += '0';\n a /= 2;\n }\n }\n reverse(a...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\npublic:\n vector<int> convert(string s){\n vector<int> ans;\n string temp;\n\n for(char c:s){\n if(c=='-'){\n int val=stoi(temp);\n ans.push_back(val);\n temp=\"\";\n }\n else{\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\npublic:\n string to_binary(string dt){\n string temp=\"\";\n int d=stoi(dt);\n while(d){\n if(d%2==1) temp+='1';\n else temp+='0';\n d=d/2;\n }\n reverse(temp.begin(),temp.end());\n return temp;\n }\n stri...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int y=stoi(date.substr(0,4));\n string year = bitset<32>(y).to_string();\n int i=0;\n while(year[i]=='0')\n {\n i++;\n }\n year=year.substr(i);\n int m=stoi(date.sub...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\npublic:\n string helper(string temp) {\n int n;\n stringstream ss;\n ss << temp;\n ss >> n;\n string s;\n while(n > 0) {\n int rem = n%2;\n n = n/2;\n s += rem+'0';\n }\n reverse(s.begin(),s.end())...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\n string convert(int a){\n string s;\n while(a){\n s=((a%2==1)?'1':'0')+s;\n a/=2;\n }\n return s;\n }\npublic:\n string convertDateToBinary(string date) {\n \n string s;\n string output;\n for(char c:da...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
1
{ "code": "class Solution {\npublic:\n\n string getBinaryString(bitset<32>& bits) {\n string s = bits.to_string();\n int idx = s.find('1');\n return s.substr(idx);\n }\n \n string convertDateToBinary(string date) { \n bitset<32> year(stoi(date.substr(0, 4))); \n bitse...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string toBinary(int x) {\n string r;\n while (x != 0) {\n r = (x % 2 ? \"1\":\"0\") + r;\n x /= 2;\n }\n return r;\n }\n string convertDateToBinary(string date) {\n string ans;\n\n ans += toBinary(stoi(date...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string dtob(int n)\n {\n string s = bitset<64>(n).to_string();\n const auto l = s.find('1');\n if (l != string::npos)\n {\n return s.substr(l);\n }\n return \"0\";\n }\n string convertDateToBinary(string date) {\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int n=date.size();\n string ans1=date.substr(0,4);\n string ans2=date.substr(5,2);\n string ans3=date.substr(8,2);\n int a2=stoi(ans2);\n int a3=stoi(ans3);\n int a1=stoi(ans1);\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int num[3], idx = 0;\n string s = \"\";\n for (char ch : date) {\n if (ch == '-') {num[idx] = stoi(s); s = \"\"; idx++;}\n else s += ch;\n }\n num[2] = stoi(s);\n strin...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\nint convert(string num)\n{\n int ind =num.size()-1;\n int mul =1;\n int ans =0;\n\n while(ind>=0)\n {\n int currVal =num[ind]-'0';\n ans +=(mul*currVal);\n mul*=10;\n\n ind--;\n }\n\n return ans;\n}\n\nstring toBinary(string num,ve...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string solve(string s) {\n string ans = \"\";\n int tmp = 0;\n\n for(int i=0; i<s.size(); i++) {\n tmp = tmp*10 + (s[i]-'0');\n } \n\n while(tmp) {\n ans = ((tmp%2 == 0) ? \"0\" : \"1\") + ans;\n tmp /= ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n string res = \"\";\n\n auto decimalToBinary = [](int decimal) {\n if (decimal == 0) return string(\"0\");\n string binary = \"\";\n while (decimal > 0) {\n binary = (deci...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string trimLeadingZeros(const string &binary) {\n size_t pos = binary.find('1');\n if (pos != string::npos) {\n return binary.substr(pos);\n }\n return \"0\"; // In case the number is zero, return \"0\"\n }\n string solve(string d...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n string convertDateToBinary(string date) {\n return toBinary(stoi(date.substr(0, 4))) + \"-\" + toBinary(stoi(date.substr(5, 2))) + \"-\" + toBinary(stoi(date.substr(8, 2)));\n }\n\nprivate:\n string toBinary(int num) {\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string decimalToBinary(int decimal)\n {\n string result;\n while (decimal > 0)\n {\n result.insert(0, to_string(decimal % 2));\n decimal /= 2;\n }\n return result;\n }\n\n string convertDateToBinary(string date...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\n private:\n string f(string &str){\n int num=0,mul=1;\n for(int i=str.size()-1;i>=0;--i){\n num+=mul*(str[i]-'0');\n mul*=10;\n }\n string ans;;\n while(num){\n ans+=to_string(num&1);\n num=num>>1;\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\n string convert(int num)\n {\n string s;\n while(num)\n {\n s+= to_string(num%2);\n num /= 2;\n }\n reverse(s.begin(), s.end());\n\n return s;\n }\npublic:\n string convertDateToBinary(string date) {\n stri...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string convert(int num){\n string ans;\n while(num){\n string k= (num%2==1)? \"1\":\"0\";\n ans=ans+k;\n num=num/2;\n }\n cout<<num<<ans<<endl;\n reverse(ans.begin(),ans.end());\n return ans;\n }\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
2
{ "code": "class Solution {\npublic:\n string convert(int num) \n {\n string s;\n while(num)\n {\n s+= to_string(num%2);\n num /= 2;\n }\n reverse(s.begin(), s.end());\n\n return s;\n }\n string convertDateToBinary(string date) {\n str...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\n string convert(int num)\n {\n string s;\n while(num)\n {\n s+= to_string(num%2);\n num /= 2;\n }\n reverse(s.begin(), s.end());\n\n return s;\n }\npublic:\n string convertDateToBinary(string date) {\n stri...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\nstring convert(int num){\n string s;\n while(num){\n s+=to_string(num%2);\n num/=2;\n }\n reverse(s.begin(),s.end());\n return s;\n}\n string convertDateToBinary(string date) {\n string ans;\n string temp;\n for(auto c:date){\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\n string convert(int num)\n {\n string s;\n while(num)\n {\n s+= to_string(num%2);\n num /= 2;\n }\n reverse(s.begin(), s.end());\n\n return s;\n }\npublic:\n string convertDateToBinary(string date) {\n stri...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string convert(int num) \n {\n string s;\n while(num)\n {\n s+= to_string(num%2);\n num /= 2;\n }\n reverse(s.begin(), s.end());\n\n return s;\n }\n string convertDateToBinary(string date) {\n str...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n\n string binary(int n){\n string s;\n while(n>0){\n s+=to_string(n%2);\n n=n/2;\n }\n reverse(s.begin(),s.end());\n return s;\n } \n\n string convertDateToBinary(string date) {\n \n string ans=\"\"...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string bin(int n){\n string s;\n while(n){\n s+=to_string(n%2);\n n/=2;\n }\n reverse(s.begin(),s.end());\n return s;\n }\n string convertDateToBinary(string d) {\n string ans;\n string temp=\"\";\n ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n \n string convertToBinary(int num){\n \n string s=\"\";\n while(num){\n s += to_string(num%2); \n num = num/2; \n }\n reverse(s.begin(),s.end());\n return s; \n }\n\n string convertDateToBinary(string date){\n\n string temp ...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string decToBin(int n){\n string s=\"\";\n int i=0;\n while(n>0){\n s=to_string(n%2)+s;\n n=n/2;\n i++;\n\n }\n return s;\n }\n string convertDateToBinary(string date) {\n string ans=decToBin(sto...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string to_binary(int num) {\n string result = \"\";\n while (num > 0) {\n result += to_string(num % 2);\n num /= 2;\n }\n reverse(result.begin(), result.end());\n return result.empty() ? \"0\" : result;\n }\n\n st...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int year=stoi(date.substr(0,4));\n int mon=stoi(date.substr(5,2));\n int day=stoi(date.substr(8,2));\n string res=\"\";\n while(year>0)\n {\n int dig=year%2;\n year/=2;...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string decToBin(int n){\n string s=\"\";\n int i=0;\n while(n>0){\n s=to_string(n%2)+s;\n n=n/2;\n i++;\n\n }\n return s;\n }\n string convertDateToBinary(string date) {\n string ans=decToBin(sto...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n \n string year = date.substr(0, 4); // Correct: start at index 0, take 4 characters\n string month = date.substr(5, 2); // Correct: start at index 5, take 2 characters (for month)\n string day = date.sub...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n int first=stoi(date.substr(0,4));\n int second=stoi(date.substr(5,2));\n int third=stoi(date.substr(8,2));\n\n string f=\"\";\n while(first){\n int di=first&1;\n f+=to_string(...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string convertDateToBinary(string date) {\n std::istringstream iss(date);\n std::string word, res;\n while (std::getline(iss, word, '-')) {\n res += to_binary(word);\n res += \"-\";\n }\n\n res.pop_back();\n retu...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string to_binary(string s){\n int num = stoi(s);\n string result =\"\";\n while(num>0){\n int temp = num % 2;\n num /= 2;\n result += to_string(temp);\n }\n reverse(result.begin(),result.end());\n retu...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n string to_binary(string s){\n int num = stoi(s);\n string result =\"\";\n while(num>0){\n int temp = num % 2;\n num /= 2;\n result += to_string(temp);\n }\n reverse(result.begin(),result.end());\n retu...
3,567
<p>You are given a string <code>date</code> representing a Gregorian calendar date in the <code>yyyy-mm-dd</code> format.</p> <p><code>date</code> can be written in its binary representation obtained by converting year, month, and day to their binary representations without any leading zeroes and writing them down in ...
3
{ "code": "class Solution {\npublic:\n\nstring convert(int nums){\n if(nums==0){\n return \"\";\n }\n string ans=convert(nums/2);\n ans=to_string(nums%2)+ans;\n\n return ans;\n}\n\nstring rev(string s){\n reverse(s.begin(),s.end());\n return s;\n}\n string convertDateToBinary(st...
3,476
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p> <p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int minimumOperations(vector<int>& nums) {\n int cnt=0;\n for(auto i:nums){\n if(i%3!=0){\n cnt++;\n }\n }\n return cnt;\n }\n};", "memory": "22400" }
3,476
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p> <p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int minimumOperations(vector<int>& nums) {\n int c=0;\n for(auto it:nums)\n {\n if(it==1)c++;\n else if(it%3!=0)c++;\n else continue;\n }\n return c;\n }\n};", "memory": "22400" }
3,476
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p> <p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int minimumOperations(vector<int>& nums) {\n int ans = 0;\n\n for(int i=0; i<nums.size();i++)\n {\n if(nums[i]%3 != 0)\n ans++;\n\n }\n\n return ans;\n }\n};", "memory": "22500" }
3,476
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p> <p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int minimumOperations(vector<int>& nums) { \n \n int op = 0;\n for(int i : nums){\n if (i %3 != 0){\n op ++;\n }\n }\n return op ;\n }\n};", "memory": "22600" }
3,476
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p> <p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int minimumOperations(vector<int>& nums) {\n int min_num_op = 0;\n for (int i = 0; i < nums.size(); i++){\n if (nums[i] % 3 !=0){\n min_num_op++;\n }\n }\n return min_num_op;\n }\n};", "memory": "22600" }
3,476
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p> <p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int minimumOperations(vector<int>& nums) {\n int c=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]%3!=0){\n c+=1;\n }\n }\n return c;\n }\n};", "memory": "22700" }
3,476
<p>You are given an integer array <code>nums</code>. In one operation, you can add or subtract 1 from <strong>any</strong> element of <code>nums</code>.</p> <p>Return the <strong>minimum</strong> number of operations to make all elements of <code>nums</code> divisible by 3.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int minimumOperations(vector<int>& nums) {\n int ans = 0;\n\n for(int i{0}; i < nums.size(); i++) {\n ans += min(nums[i]%3, 3-nums[i]%3);\n }\n return ans;\n }\n};", "memory": "22700" }
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n int n = nums.size();\n int ans = 0;\n\n for(int i =0; i<n; i++){\n\n if(nums[i]==0){ \n\n if(i+3>n) return -1;\n\n for(int j =i; j<i+3; j++){\n if(nums[j]==0)...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n int ans=0;\n for(int i=0;i<n-2;i++){\n if(nums[i]==0){\n nums[i]=1;\n nums[i+1]=(nums[i+1]==0)?1:0;\n nums[i+2]=(nums[i+2]==1)?0:1;\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int cnt = 0;\n for(int i = 0;i<nums.size()-2;i++){\n if(nums[i] == 0){\n nums[i] = !nums[i];\n nums[i+1] = !nums[i+1];\n nums[i+2] = !nums[i+2] ;\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>&nums) {\n int n=nums.size(),ans=0;\n //if(nums[n-2]==0 || nums[n-1]==0)\n //return -1;\n for(int i=0;i<n-2;++i)\n {\n if(nums[i]==0)\n {\n nums[i]=1-nums[i];\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size(), ans = 0;\n for (int i =0 ; i< n-2; i++){\n if(nums[i] == 0){\n nums[i] = 1-nums[i];\n nums[i+1] = 1-nums[i+1];\n nums[i+2] = 1-nums[i+2];\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
0
{ "code": "class Solution {\n public:\n int minOperations(vector<int>& nums) {\n const int n = nums.size();\n int ans = 0;\n\n for (int i = 0; i + 2 < n; ++i)\n if (nums[i] == 0) {\n nums[i + 1] ^= 1;\n nums[i + 2] ^= 1;\n ++ans;\n }\n\n return nums[n - 1] == 0 || nums[n - ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n int count=0,n=nums.size();\n \n for(int i=0;i<n;i++){\n if(nums[i]==0){\n if(i+3>n){\n return -1;\n }\n for(int j=i;j<i+3;j++){\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
1
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n int ans =0;\n for(int i=0;i<n-2;i++){\n if(nums[i]==0){\n nums[i]=1;\n nums[i+1] = (nums[i+1]==1) ? 0:1;\n nums[i+2] = (nums[i+2]==1) ?...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
1
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int cnt=0;\n for(int i=0;i<nums.size()-2;i++){\n if(nums[i]==0){\n cnt++;\n for(int j=i;j<i+3;j++){\n if(nums[j]==0){\n nums[j]=1;\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int count = 0;\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] == 0) {\n cout <<\" \"<<i<<\" \";\n if ((i + 3) > nums.size())\n return -1;\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n vector<int> t(4, numeric_limits<int>::min());\n t[(nums[0] << 1) | nums[1]] = 0;\n\n int n = nums.size();\n vector<int> nt(4, numeric_limits<int>::min());\n for (int i = 2; i < n; i++) {\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n vector<int> t(4, numeric_limits<int>::min());\n t[(nums[0] << 1) | nums[1]] = 0;\n\n int n = nums.size();\n vector<int> nt(4, numeric_limits<int>::min());\n for (int i = 2; i < n; i++) {\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n vector<int> t(4, numeric_limits<int>::min());\n t[(nums[0] << 1) | nums[1]] = 0;\n\n int n = nums.size();\n vector<int> nt(4, numeric_limits<int>::min());\n for (int i = 2; i < n; i++) {\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int l = nums.size();\n int a[l];\n memset(a,0,sizeof(a));\n int count=0;\n for(int i=0;i<l-2;i++){\n bool flip = a[i]%2!=0;\n if((flip && nums[i]==0) || (!flip && nums[i]==1)){\n...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size(),np=0,cn=0;\n vector<bool> flip(n,0);\n for(int i=0;i<n;i++){\n if(i-3>=0 and flip[i-3]) cn--;\n if(cn&1) nums[i]=nums[i]^1;\n if(i<n-2 and nums[i]==0){\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int k = 3;\n int n = nums.size(), flipCount = 0, result = 0;\n\n vector<bool> isFlipped(n, false);\n\n for(int i = 0; i < n; i++)\n {\n if(i >= k && isFlipped[i - k] == true)flipCount--;\n\...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int k = 3;\n int n = nums.size(), flipCount = 0, result = 0;\n\n vector<bool> isFlipped(n, false);\n\n for(int i = 0; i < n; i++)\n {\n if(i >= k && isFlipped[i - k] == true)flipCount--;\n\...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "\nclass Solution\n{\npublic:\n int minOperations(vector<int> &a)\n {\n int n = a.size();\n vector<bool> b(n);\n int count =0;\n\n for (int i = 0; i < n; i++)\n {\n if (a[i] == 0)\n b[i] = 0;\n else\n {\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int num_flipped_window = 0;\n deque<bool> d;\n for (int i = 0; i < 3; ++i) {\n if ((nums[i]==0 && num_flipped_window%2==0) || (nums[i]==1 && num_flipped_window%2==1)) {\n if (nums.size()-i...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n // Almost same as https://leetcode.com/problems/minimum-number-of-k-consecutive-bit-flips/\n int minOperations(vector<int>& nums) {\n int num_flipped_window = 0;\n deque<bool> d;\n for (int i = 0; i < 3; ++i) {\n if ((nums[i]==0 && num_flipp...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "\n#define endl '\\n'\n#define pint pair<int, int>\n#define vint vector<int>\n#define vpint vector<pair<int, int>>\n#define vstr vector<string>\n#define uset unordered_set\n#define umap unordered_map\n#define vbool vector<bool>\n#define vvint vector<vector<int>>\n#define ll long long\n#define MOD 1000000007...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "\n#define endl '\\n'\n#define pint pair<int, int>\n#define vint vector<int>\n#define vpint vector<pair<int, int>>\n#define vstr vector<string>\n#define uset unordered_set\n#define umap unordered_map\n#define vbool vector<bool>\n#define vvint vector<vector<int>>\n#define vvvint vector<vector<vector<int>>>\n...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int result = 0;\n deque<int> q;\n for (int i = 0; i < nums.size(); ++i) {\n if (!q.empty() && q.front() + 3 == i) {\n q.pop_front();\n }\n if (q.size() % 2 == nums[i]...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n deque<int>dq;\n int ans=0;\n\n for(int i=0;i<nums.size();i++){\n while(!dq.empty() and i>dq.front()+3-1){ // Window has reached more than size of k, so remove front as it longer effects current index\n ...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n queue<int> q;\n int ans=0;\n for(int i=0;i<n;i++){\n while(!q.empty() && q.front()<i-2){\n q.pop();\n\n }\n if((nums[i]+q.size())%2==0){\n...
3,475
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> 3 <strong>consecutive</strong> elements from the array and <strong>flip</st...
3
{ "code": "#pragma GCC optimize(\"03\")\nclass Solution {\npublic:\n int minOperations(vector<int>& nums) {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n\n int n = nums.size();\n queue<int> q;\n bool flip = false;\n int ans = 0;\n for(int i =...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int count = 0;\n for (int i=0; i<nums.size(); i++) {\n if ((count+nums[i])%2==0){\n count++;\n }\n }\n return count;\n }\n};", "memory": "155300" }
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int ans=0;\n // int flag=1;\n for(int i=0;i<nums.size();i++)\n {\n nums[i]=(nums[i]+ans)%2;\n if(nums[i]==0)\n {\n ans++;\n nums[i]=1;\n ...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n // int operations = 0;\n // for(int i=0; i<nums.size(); i++){\n // replaseBinaryNumbers(i, nums, operations);\n // }\n\n // return operations;\n\n\n int i = 1;\n int j = 0;...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int j = 0;\n int ind = 0;\n int operations = 0;\n while(ind < nums.size()){\n if(nums[ind] == j){\n j = j == 0? 1 : 0;\n operations++;\n }\n ind...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n=nums.size();\n int ans=0;\n int prev=1,cur=1;\n for(int i=0;i<n;i++){\n if(nums[i]!=cur){\n cur=nums[i];\n }\n ans+=(cur!=prev);\n prev=cur;\n } \n return...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
0
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n int swapCnt = 0;\n for(int i=0; i<n; ++i) {\n if((nums[i] + swapCnt)%2 == 0) {\n ++swapCnt;\n }\n }\n return swapCnt;\n }\n};", "memory...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
2
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int op = 0;\n for (int i = 0; i < nums.size(); i++) {\n if (nums[i] == 0 && ((op & 1) == 0)) {\n op++;\n }\n else if (nums[i] == 1 && ((op & 1) == 1)) {\n op+...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
2
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int i=0;\n int flipped = 0;\n int ans = 0;\n while(i < nums.size()) {\n if(nums[i] == flipped%2) {\n flipped++;\n ans++;\n }\n i++;\n }\n...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n ios::sync_with_stdio(0);\n cin.tie(NULL);\n cout.tie(NULL);\n int flips = 0;\n int n = nums.size();\n for(int i = 0;i<n;i++){\n if((nums[i] == 0 && (flips%2 == 0)) || (nums[i] == 1 &...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n //NOTE. nhung bit 1 se bi lat CHAN lan\n //NOTE. nhung bit 0 se bi lat LE lan\n int i=nums.size()-1, cnt=0;\n while (i>=0){\n int j=i;\n ...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n ios_base::sync_with_stdio(false); cin.tie(0);\n //NOTE. nhung bit 1 se bi lat CHAN lan\n //NOTE. nhung bit 0 se bi lat LE lan\n int i=nums.size()-1, cnt=0;\n while (i>=0){\n int j=i;\n ...
3,477
<p>You are given a <span data-keyword="binary-array">binary array</span> <code>nums</code>.</p> <p>You can do the following operation on the array <strong>any</strong> number of times (possibly zero):</p> <ul> <li>Choose <strong>any</strong> index <code>i</code> from the array and <strong>flip</strong> <strong>all</...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n int n = nums.size();\n int dp[n];\n dp[0] = 1 - nums[0];\n for (int i = 1; i < n; i++) {\n dp[i] = dp[i-1];\n if ((nums[i] + dp[i]) % 2 == 0) dp[i]++;\n }\n return dp[n-1]...