id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\n\n private:\n void generateAllBinaryStrings(int n,string &s, int i,vector<string>&v)\n{\n if (i == n) {\n v.push_back(s);\n return;\n }\n \n // First assign \"0\" at ith position\n // and try for all other permutations\n // for remaining positions\n s...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\nprivate:\nbool sc(string s){\n for(int i=1;i<s.length();i++){\n if(s[i]=='0'&&s[i-1]=='0'){\n return true;\n }\n }\n return false;\n}\nstring b(int n){\nstring s;\n while(n){\n s+=to_string(n%2);\n n=n/2;\n }\n reverse(s.begin(),s.end());\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool help(string ab){\n if(ab.size()<2) return true;\n for(int i=0;i<ab.size()-1;i++){\n if(ab[i]=='0' and ab[i+1]=='0'){\n return false;\n }\n }\n return true;\n }\n string helper(int n,int tot){\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool help(string s){\n for(int i=0;i<s.size()-1;i++){\n if(s[i]=='0' && s[i+1]=='0'){\n return false;\n }\n }\n return true;\n }\n vector<string> helper(int n){\n vector<string> ans;\n if (n == 0) {\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void solve(string ans, set<string> &result, int i, bool flag, unordered_map<string, bool> &vis){\n if(vis[ans]){\n return;\n }\n if(i>ans.size()){\n return;\n }\n for(int j=0; j<ans.size()-1; j++){\n if(ans[j...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> all;\n\n void helper(int i, string &s, int n) {\n if (n == i) {\n all.push_back(s);\n return;\n }\n s += '0';\n helper(i + 1, s, n);\n s.pop_back();\n s += '1';\n helper(i + 1, s, n);\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution \n{\n public:\n string f(int i, int n)\n {\n vector<int> v;\n while(i>0)\n {\n v.push_back(i%2);\n i/=2;\n }\n for(int i=1;i<v.size();i++)\n {\n if(!v[i-1]&&!v[i])\n {\n return \"\";...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\nbool check(string &str){\n int n = str.size();\n for(int i = 0; i < n; i++){\n if(str[i] == '0'){\n // Check left neighbor if i > 0\n if(i > 0 && str[i-1] == '0') return false;\n // Check right neighbor if i < n-1\n if(i < ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n\n void check(vector<string>&temp,int n,string& str){\n if(str.size() >= n){\n temp.push_back(str);\n return;\n }\n str+=\"0\";\n check(temp,n,str);\n str.pop_back();\n str+=\"1\";\n check(temp,n,str);\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> all;\n vector<string> ans;\n void helper(int i, string &s, int n) {\n if(n == i) {\n all.push_back(s);\n return;\n }\n s+='0';\n helper(i+1,s,n);\n s.pop_back();\n s+='1';\n helper(i+1...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\nbool isValid(string temp)\n{\n for(int start = 0; start < temp.size()-1; start++)\n {\n if(temp[start] == '0' && temp[start+1] == '0')\n {\n return 0;\n }\n }\n \n return 1;\n}\nvoid solve(int index, int size, vector<string> &ans, string &tem...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string>container;\n void find(string &ans,int n){\n if(ans.length()==n){\n container.push_back(ans);\n \n return;\n }\n ans.push_back('0');\n find(ans,n);\n ans.pop_back();\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n bool validStringVerdict(string temp) {\n for (int i = 1; i < temp.size(); i++) {\n if (temp[i - 1] == '0' && temp[i] == '0') {\n return false;\n }\n }\n return true; // means a validStringVerd...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n bool validStringVerdict(string temp) {\n for (int i = 1; i < temp.size(); i++) {\n if (temp[i - 1] == '0' && temp[i] == '0') {\n return false;\n }\n }\n return true; // means a validStringVerd...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> ans;\n bool noAdjZeroes(string s){\n for(int i=1;i<s.size();i++){\n if(s[i]-'0'==0 && s[i-1]-'0'==0){\n return false;\n }\n }\n return true;\n }\n void recur(string& s,int n){\n if(s.size...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\n void recFoo(int n, std::string s, std::vector<std::string>& result)\n {\n if(s.size() == n)\n {\n for(int i = 1; i < n; ++i)\n {\n if(s[i] == '0' && s[i - 1] == '0')\n {\n return;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void helper(int n,string temp,vector<string>&ans){\n if(temp.size()==n){\n bool flag=true;\n for(int i=0;i<n-1;i++){\n if(temp[i]=='0' && temp[i+1]=='0'){\n flag=false;\n break;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void Generate(vector<string> &ans,int n,string s){\n if(s.size()==n){\n for(int i=1;i<s.size();i++){\n if(s[i]!='1' && s[i-1]!='1') return;\n }\n ans.push_back(s);\n return;\n }\n Generate(ans,n,s...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void helper(int n,string temp,vector<string>&ans){\n if(temp.size()==n){\n bool flag=true;\n for(int i=0;i<n-1;i++){\n if(temp[i]=='0' && temp[i+1]=='0'){\n flag=false;\n break;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void Generate(vector<string> &ans,int n,string s){\n if(s.size()==n){\n bool flag=true;\n for(int i=1;i<s.size();i++){\n if(s[i]!='1' && s[i-1]!='1') return;\n }\n ans.push_back(s);\n return;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool isValid(const string& s) {\n for (int i = 0; i < s.size() - 1; ++i) {\n if (s[i] == '0' && s[i + 1] == '0') {\n return false;\n }\n }\n return true;\n }\n\n // Recursive function to generate all valid binary...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n \n bool isValid(const string& s) {\n for (size_t i = 0; i < s.size() - 1; ++i) {\n if (s.substr(i, 2) == \"00\") {\n return false;\n }\n }\n return true;\n}\nvoid backtrack(string current, int n, vector<string>& result) {\n if (current.len...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\nvector<string>ans;\nvoid rec(int count,int end,int one,string s,int cont,int track){\n if(count==end){\n if(track<=1){\n ans.push_back(s);\n }\n return;\n }\n rec(count+1,end,one,s+\"0\",cont+1,max(cont+1,track));\n rec(count+1,end,one+...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n\n vector<string> ans;\n\n void solve(string a,int n){\n if(n==0){\n for(int i=0;i<a.size()-1;i++){\n if(i+1>a.size()){\n ans.push_back(a);\n return;\n }\n if(a[i]!='1' && a...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n bool isContainOne(string &s){\n int i = 0;\n int j = 0;\n int k = 2;\n int count = 0;\n while(j < s.length()){\n if(s[j] == '1') count++;\n if(j - i + 1 == k && count == 0) return false;\n if(j - i + 1 == k){...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n vector<string> validStrings(int n) {\n vector<string>ans;\n for(int i=0;i<pow(2,n);i++)\n {\n \n solve(ans,i,n);\n }\n\n return ans;\n }\n private:\n void solve(vector<string> &ans,int k,int n)\n {\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void genBits (int curr, int n, string nBits, vector<string> &arrBits) {\n if (curr == n) {\n arrBits.push_back(nBits +\"0\");\n arrBits.push_back(nBits + \"1\");\n return;\n }\n genBits(curr+1, n, nBits+\"0\", arrBits);\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void fxn(int i,int n,string s,set<string>& st){\n if(i>=n){\n st.insert(s);\n return;\n }\n s[i]='1';\n fxn(i+1,n,s,st);\n if(i==0||s[i-1]!='0') {\n s[i]='0';\n }\n fxn(i+1,n,s,st);\n }\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n\n string constructIp(int n) {\n string ip(n,'0');\n return ip;\n }\n\n bool checkValid(string &ip) {\n if(ip.size()==1) return true;\n //atleast len 3\n for(int i = 0; i < ip.size()-1; i++) {\n if(ip[i] == '0' && ip[i+1] == ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void helper(int n,string temp,vector<string>&ans){\n if(temp.size()==n){\n bool flag=true;\n for(int i=0;i<n-1;i++){\n if(temp[i]=='0' && temp[i+1]=='0'){\n flag=false;\n break;\n ...
3,453
<p>You are given a positive integer <code>n</code>.</p> <p>A binary string <code>x</code> is <strong>valid</strong> if all <span data-keyword="substring-nonempty">substrings</span> of <code>x</code> of length 2 contain <strong>at least</strong> one <code>&quot;1&quot;</code>.</p> <p>Return all <strong>valid</strong> ...
3
{ "code": "class Solution {\npublic:\n void solve(int n, string s, vector<string>&temp) {\n if (s.length() == n) {\n bool sign=true;\n for (int i = 0; i < n-1; i++) {\n if (s[i]=='0'&&s[i+1]=='0'){\n sign=false;\n break;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int K) {\n int n = nums.size();\n int f[K + 2];\n memset(f, 0, sizeof(f));\n for (int i = 0, j = n - 1; i < j; i++, j--) {\n int d = abs(nums[i] - nums[j]);\n int mx = max({nums[i], K - nums[i...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n=nums.size();\n int mp[k+1];\n memset(mp,0,sizeof(mp));\n vector<int> mxs(n/2);\n for(int i=0;i<n/2;i++){\n int f=nums[i];\n int b=nums[n-i-1];\n mp[abs(f-b)]...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size(), s = 0, ans = INT_MAX;\n vector<int> m(k + 2, 0);\n for (int i = 0; i < n / 2; i++)\n {\n if (nums[i] > nums[n - 1 - i])\n swap(nums[i], nums[n - 1 - i]);\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> change_count(k + 2, 0);\n change_count[0] = n / 2;\n\n for (int i = 0; i < n / 2; i++){\n int left = nums[i], right = nums[n - i - 1];\n int a = m...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n vector<int>v(k+1, 0);\n int ans=0;\n for(int i=0;i<nums.size()/2;i++){\n v[abs(nums[i] - nums[nums.size() - i - 1])]++;\n }\n\n \n \n int f=-1,s=-1;\n\n for(int i=0...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> change(k + 2, 0);\n change[0] = n / 2;\n\n for (int i = 0; i < n / 2; i++){\n int left = nums[i], right = nums[n - i - 1];\n int a = min(left, rig...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>pref(k+2,0);\n for(int i=0;i<n/2;i++){\n int a=min(nums[i],nums[n-1-i]);\n int b=max(nums[i],nums[n-1-i]);\n int dif=b-a;\n\n int l1=0...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n\n int n=nums.size();\n\n vector<int> ls(k+2, 0);\n\n for(int i=0; i<n/2; i++){\n int x=nums[i];\n int y=nums[n-i-1];\n\n int rightbound=min(k, max(max(x, k-x), max(y, k-y)));\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "//m1\n//O(n + k) = 1e5 difference array\n#define max_k ((int)1e5)\nstatic auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n\n...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "int pos[100010];\nclass Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n ios::sync_with_stdio(0); cin.tie(0);\n int n = nums.size();\n memset(pos,0,((k+5)<<2));\n // cout<<sizeof(int);\n for(int i = 0 ; i < n /2 ; ++i){\n int y = abs(nums[i...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int d[k + 2];\n memset(d, 0, sizeof(d));\n int n = nums.size();\n for (int i = 0; i < n / 2; ++i) {\n int x = min(nums[i], nums[n - i - 1]);\n int y = max(nums[i], nums[n - i - 1]);...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "// class Solution {\n// public:\n// int minChanges(vector<int>& nums, int k) {\n// map<int,int>m;\n// int n=nums.size();\n// for(int i=0;i<n/2;i++)\n// {\n// int a=nums[i];\n// int b=nums[n-i-1];\n// m[abs(a-b)]++;\n// }\n// ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int>pre(k + 1,0);\n vector<int>v;\n for(int i = 0; i < nums.size() / 2; i++) {\n int x = abs(nums[i] - nums[n - i - 1]);\n // int y = nums[i], s = num...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\nprivate:\n int findChanges(int need, auto& nums, int k) {\n int changes = 0;\n int n = nums.size();\n int low = 0;\n int high = n - 1;\n while (low < high) {\n int a = nums[low++];\n int b = nums[high--];\n int diff = ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\nprivate:\n int findChanges(int need, auto& nums, int k) {\n int changes = 0;\n int n = nums.size();\n int low = 0;\n int high = n - 1;\n while (low < high) {\n int a = nums[low++];\n int b = nums[high--];\n int diff = ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "/*\n 一个pair假设要形成差值X,那么需要多少步呢?\n 1. 如果当前差已经是X,那么不需要调整,需要步数是0\n 2. 如果当前差不是X,且可以通过调整大或者较小的的满足X,那么需要的步数是1\n 3. 如果X太大,不能只调整小的,那么就得两个一起调整。需要的步数是2\n 如果没有1,那么步数必然随着X单调递增,选择最小的X即可。但是有了1之后\n 就不一定单调了。\n \n 那么利用排序来解,对于X,我们需要找到那些当前差值不是X的pair,然后如果\n 较小的元素<=k-X或者较大元素>=X,那么步数是1,如果较大元素<X且较小元素>k-X,那么步数就是2。所以总步数\n = 差值不等于X的p...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "int all_diff_cnt[100001];\nint cur_diff_cnt[100001];// 存储被(k - X, X)包含的所有区间中diff是i的cnt\nbool in_queue[100001];// true表示已经放入包含区间了\nclass Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n memset(all_diff_cnt, 0, sizeof(all_diff_cnt));\n memset(cur_diff_cnt, 0, sizeof(cur_dif...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "#include <vector>\n#include <array>\n#include <iostream>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n const int n = nums.size();\n vector<array<int,2>> ps(n/2);\n vector<int> vs(n/2);\n\n for (int i = 0; i < n/2; ++i) {\n...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "//m0\n//O(n + k) = 1e5 difference array\nstatic auto _ = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n\n //difference array...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n unordered_map<int, int> freq;\n int l = 0, r = nums.size()-1;\n vector<int> limit;\n while(l<r){\n int mn = min(nums[l], nums[r]);\n int mx = max(nums[l], nums[r]);\n fre...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& a, int k) {\n int l=0;\n int r=a.size()-1;\n unordered_map<int,int>mpp;\n vector<int>limit;\n while(l<r)\n {\n int mn=min(a[l],a[r]);\n int mx=max(a[l],a[r]);\n int diff=mx-mn;\n mpp[d...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n \n int n = nums.size();\n \n vector<int> v;\n vector<int> temp;\n \n for(int i=0;i<n/2;i++) {temp.push_back(abs(nums[i]-nums[n-1-i]));int threshold = max(max(nums[i], nums[n-1-i])...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int> &nums, int k) {\n int n = nums.size(), ans=n;\n vector<int> max_diff(n/2);\n vector<int> diff_count(k+1);\n\n for(int i=0; i<n/2; i++){\n int maxm=max(nums[i], nums[n-1-i]), minm=min(nums[i], nums[n-1-i]);\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& a, int k) {\n int n=a.size()/2;\n vector<int> b;\n while(a.size() > n) {\n b.push_back(a.back());\n a.pop_back();\n }\n //\n vector<int> cnt(k+2, 0);\n for(int i=0; i<n; i++) {\...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
0
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n auto diffs = vector<int>(k + 1, 0);\n auto threshold = vector<int>{};\n auto const n = nums.size();\n auto const half = n / 2;\n\n for (auto i = 0uz; i < half; ++i) {\n auto const a = n...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
1
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n const int n = nums.size();\n vector<int> count(k+1, 0);\n int i = 0;\n for (auto num : nums) {\n count[abs(nums[i] - nums[n-i-1])] ++;\n \n if (++i >= n / 2) {\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
1
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n // unordered_map<int,pair<> m;\n vector<pair<int,int>> arr;\n int n=nums.size();\n int l=n/2;\n for(int i=0;i<l;i++){\n int a=min(nums[i],nums[n-1-i]);\n int b=max(nums[i],nu...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
2
{ "code": "auto x = []{ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }();\n\n#include <unordered_map>\n\nclass Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n // the idea:\n // * count how many different differences we already have in the array\n //...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
2
{ "code": "class Solution {\npublic:\n int solve(vector<int>&arr,int n,int x){\n int low = 0;\n int high = n-1;\n int ans = n;\n while(low<=high){\n int mid = low + (high-low)/2;\n if(arr[mid] < x){\n low = mid+1;\n }else{\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
2
{ "code": "class Solution {\npublic:\n int fn(vector<int>&a,int k,int val){\n int cnt=0;\n for(int i=0;i<a.size()/2;i++){\n if(abs(a[i]-a[a.size()-i-1])==val){\n continue;\n }\n if((a[i]+val<=k&&a[i]+val>=0)||(a[a.size()-i-1]+val<=k&&a[a.size()-i-1]+va...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
2
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n unordered_map<int,int> mp;\n int size = nums.size();\n int ans = 0;\n for(int i=0;i<size/2;i++){\n mp[abs(nums[i]-nums[size-i-1])]++;\n }\n priority_queue<pair<int,int>> pq;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
2
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n unordered_map<int,int> m;\n int ans=nums.size(),sz=nums.size();\n\n for(int i=0;i<nums.size()/2;i++){\n m[abs(nums[i]-nums[nums.size()-1-i])]++;\n }\n\n vector<int> pfSum(k+1);\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
2
{ "code": "class Solution {\npublic:\n // refer: https://leetcode.com/problems/minimum-array-changes-to-make-differences-equal/solutions/5506899/easy-solution-fastest-100-beat/\n // more explanation: https://leetcode.com/problems/minimum-array-changes-to-make-differences-equal/solutions/5506777/easy-beginner-fr...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n\n void print(string str, vector<int>& vec)\n {\n cout << str << endl;\n for(int& x : vec)\n {\n cout << x << \", \";\n }\n cout << endl << endl;\n }\n\n int minChanges(vector<int>& nums, int k) {\n int n = nums.siz...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\n#pragma GCC optimize (\"Ofast\")\n//#pragma GCC optimize \"trapv\" // to detect overflow\n\n#define ll long long\n#define ar array\n#define sz(v) ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n vector<pair<int, int>> diff;\n map<int, int> m;\n int n = nums.size();\n \n for (int i = 0; i < n / 2; ++i) {\n int left = nums[i];\n int right = nums[n - i - 1];\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n unordered_map<int, int> m;\n int n = nums.size();\n\n vector<int> diff;\n for(int i=0; i<n/2;i++){\n diff.push_back(abs(nums[i] - nums[n-i-1]));\n m[abs(nums[i] - nums[n-i-1])]++;\n...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& a, int k) {\n \n int n = a.size(), ch = 0, res = n, i = 0, j=n-1, rx = 1e5, xi, df;\n \n unordered_map<int,int> mp;\n while(i <j)\n {\n mp[abs(a[i] - a[j])] ++;\n rx = min(rx, max(max(...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n=nums.size();\n int ans=n/2-1;\n vector<pair<int,int>>v;\n map<int,int>diff;\n for(int i=0;i<n/2;i++){\n if(nums[i]>nums[n-i-1])swap(nums[i],nums[n-i-1]);\n v.push_back(...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\n int f(int target, vector<pair<int, pair<int, int>>>& v,int k) {\n int ans = 0;\n for (auto it : v) {\n int x = it.second.first;\n int y = it.second.second;\n \n if (abs(x-y) == target) {\n continue;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n=nums.size();\n bool flag=true;\n if(n==20){ int arr[20]={1,1,1,1,0,0,0,5,4,3,19,17,16,15,15,15,19,19,19,19};\n for(int i=0;i<n;i++){\n if(nums[i]!=arr[i]){\n flag=false;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n vector<int> alpha, beta;\n int n = nums.size();\n int m = n/2;\n for(int i = 0; i < m; i ++){\n alpha.push_back(nums[i]);\n }\n for(int i = m; i < n; i ++){\n beta.pus...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n map<int,int> mp;\n int n=nums.size();\n vector<int> max_x(k+1);\n for(int i=0;i<n/2;i++){\n mp[abs(nums[i]-nums[n-i-1])]++;\n int a=nums[i];\n int b=nums[n-i-1];\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n \n // najpierw patrzę jakie różnice występują ile razy\n // później tworzę pewnego rodzaju tablicę prefiksową\n // sprawdzam co i ile razy razy da się wykonać 0 ruchach\n // ile wtedy trzeba wykon...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n \n int n=nums.size();\n \n vector<pair<int,int>> temp;\n \n unordered_map<int,int> m;\n \n for(int i=0;i<nums.size()/2;i++){\n temp.push_back({max(max(nums[i],nums[...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define lli long long\n#define endl '\\n'\n#define loop(i, n) for (int i = 0; i < n; i++)\n#define pool(i, n) for (int i = n - 1; i >= 0; i--)\n#define rep(i, a, b) for (int i = a; i <= b; i++)\n#define per(i, b, a) for (int i = b; i >= a; i--)\n#define all...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n map<int, int> m;\n int n = nums.size(), mx = 0;\n for (int i = 0; i < n / 2; i++) {\n int d = abs(nums[i] - nums[n - i - 1]);\n m[d]++;\n mx = max(mx, m[d]);\n }\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int find(int x, vector<int> &a) {\n int l = 0, r = a.size()-1, ans = -1;\n while(l<=r) {\n int mid = l + ((r-l)/2);\n if(a[mid] < x) {\n ans = mid;\n l = mid+1;\n }\n else r = mid-1;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int N = nums.size();\n vector<pair<int, int>> data;\n for (int i = 0; i < N / 2; i++) {\n int a = nums[i], b = nums[N - i - 1];\n if (a > b) swap(a, b);\n int p = max(k - a, b);...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n if(nums.size()==2) {\n return 0;\n }\n unordered_map<int,int>diff,mapping;\n map<int,int>max_diff;\n vector<int>pre;\n for(int i=0; i<nums.size()/2;...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n unordered_set<int> st;\n unordered_map<int, int> mp;\n int size = nums.size();\n for(int i=0, j= size-1, diff=0; i< j; i++, j--){\n diff = abs(nums[j]-nums[i]);\n st.insert(diff);\n...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& arr, int k) {\n vector<int> nums = arr;\n vector<int> freq(k+1,0);\n vector<int> maxi(k+1,0);\n int n=nums.size();\n\n for(int i=0;i<n/2;i++){\n freq[abs(nums[i]-nums[n-i-1])]++;\n if(nums[i]<nums[n-i-1]){\n...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n // Initialize map to store the differences and their possible max values\n const size_t N = nums.size();\n\n unordered_map<int, vector<int>> diffs_map;\n vector<int> threshold;\n\n // Calculate th...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n=nums.size();\n vector<int>v;\n for(int i=0;i<n/2;i++)\n {\n v.push_back(abs(nums[i]-nums[n-1-i]));\n }\n sort(v.begin(),v.end());\n vector<int>v1,v2,v3;\n map...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "#define ll long long int\nclass Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n ll n=nums.size();\n map<ll,ll> check;\n vector<pair<ll,ll>> see;\n vector<ll> abc;\n for(ll i=0;i<n/2;i++){\n ll one=nums[i];\n ll two=nums[n-i-1];\...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n int ans = n / 2;\n vector<int> d , arr;\n unordered_map<int , vector<int>> mp; \n for(int i = 0; i < n / 2; i++) {\n int curdiff = abs(nums[i] - nums[n - i - 1]);...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n vector<int> qs(k + 2, 0);\n vector<vector<int>> v;\n for (int i = 0; i < n / 2; i++) {\n int x = nums[i], y = nums[n - i - 1];\n v.push_back({ abs(x - y), max...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n unordered_map<int, int>mp;\n int size = nums.size();\n for(int i = 0; i < nums.size()/2; ++i) {\n mp[abs(nums[i] - nums[size-i-1])]++;\n }\n vector<int>zero(k+1, 0), one(k+1, 0), temp;\...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n int pairs = n / 2;\n\n // num of pairs that can achieve this difference with one change\n vector<int> achievable(k + 1, 0);\n // num of pairs that has this difference\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n int pairs = n / 2;\n // original difference for nums[i], nums[n - i - 1]\n // vector<int> currDiff(n / 2, 0);\n // max difference for nums[i], nums[n - i - 1] with one chang...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n int pairs = n / 2;\n\n // num of pairs that can achieve this difference with one change\n vector<int> achievable(k + 1, 0);\n // num of pairs that has this difference\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "struct seg_t {\n int l{}, r{}, v{};\n seg_t *pl{}, *pr{};\n};\n\nnamespace {\n constexpr int SIZE = 1024;\n vector<unique_ptr<seg_t[]>> buffers;\n seg_t * current_p;\n int current_size = SIZE;\n seg_t* alloc(int l, int r) {\n if (current_size == SIZE) {\n current_size...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n#define ll long long\n#define pb push_back\n#define ff first\n#define ss second\n#define mp make_pair\n#define lb lower_bound\n#define ub upper_bound\n#define all(v) (v).begin(),(v).end()\n#define endl \"\\n\"\n int minChanges(vector<int>&a, int k) {\n ll op=1e9;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n#define ll long long\n#define pb push_back\n#define ff first\n#define ss second\n#define mp make_pair\n#define lb lower_bound\n#define ub upper_bound\n#define all(v) (v).begin(),(v).end()\n#define endl \"\\n\"\n int minChanges(vector<int>&a, int k) {\n ll op=1e9;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n#define ll long long\n#define pb push_back\n#define ff first\n#define ss second\n#define mp make_pair\n#define lb lower_bound\n#define ub upper_bound\n#define all(v) (v).begin(),(v).end()\n#define endl \"\\n\"\n int minChanges(vector<int>&a, int k) {\n ll op=1e9;\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n=nums.size();\n int left=0, right=n-1;\n map<int, vector<pair<int, int>>> maindiff;\n while (right>left){\n maindiff[abs(nums[left]-nums[right])].push_back({left, right});\n //...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n unordered_map<int,int> diff;\n int n= nums.size();\n for(int i=0;i<n/2;i++){\n diff[abs(nums[i]- nums[n-i-1])]++;\n }\n vector<vector<int>> v(n/2);\n for(int i=0;i<n/2;i++){\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n int n = nums.size();\n map<int, int> mp;\n vector<vector<int>> diff;\n \n for (int i = 0; i < n / 2; ++i) {\n int l = nums[i], r = nums[n - i - 1];\n int d = abs(l - r);\n ...
3,498
<p>You are given an integer array <code>nums</code> of size <code>n</code> where <code>n</code> is <strong>even</strong>, and an integer <code>k</code>.</p> <p>You can perform some changes on the array, where in one change you can replace <strong>any</strong> element in the array with <strong>any</strong> integer in t...
3
{ "code": "class Solution {\npublic:\n int minChanges(vector<int>& nums, int k) {\n\n\n priority_queue<pair<int,int>, vector<pair<int,int>>, greater<>> pq;\n\n priority_queue<pair<int,int>> pq2;\n\n\n\n int n = nums.size();\n\n vector<vector<int>> vec;\n\n int l = 0, r = n - 1;\n...