id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
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 if(nums[0] == 0){dp[0] = 1;}\n else{dp[0] = 0;}\n for(int i = 1; i < n; i++){\n if(nums[i] != nums[i - 1]){\n dp[i] = dp[i - 1] + 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</...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n \n\n int const n = nums.size();\n int z[n+1];\n int o[n+1];\n\n z[n] = 0;\n o[n] = 0;\n\n \n\n for (int i = n-1; i>=0; i--){\n cout<<i;\n if (nums[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 const n = 100000;\n bitset<n+1> bits;\n bitset<n+1> mask;\n\n for(int i = 0;i<n;i++){\n mask[i] = 1;\n }\n\n int i = nums.size()-1;\n for(auto it:nums){\n bits[...
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": "\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,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": "#define ll long long int\nclass Solution {\npublic:\n // for this we have \n ll solve(ll idx,vector<int>&nums,ll n,int f)\n {\n if(idx==n)\n return 0;\n ll ans=INT_MAX;\n if((nums[idx]==0)&&(f%2))\n {\n ans=min(ans,solve(idx+1,nums,n,f)); \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 Solution1 {\n int f1(int i,vector<int> &nums){\n if(i==nums.size())return 0;\n\n if(nums[i]==0){\n //flip from i to n-1\n for(int idx=i;idx<nums.size();idx++)nums[idx]=!nums[idx];\n\n return 1+f1(i+1,nums);\n }\n\n return f1(i+1,nums);\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\n\n int solve(vector<int>&nums,int i,int cnt){\n if(i == nums.size()) return 0;\n int res = 0;\n if(cnt%2 != nums[i]) res = solve(nums,i+1,cnt);\n else res = 1 + solve(nums,i+1,cnt+1);\n return res;\n }\n int minOperations(vector<int>...
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\n static const int mn = 1e5 + 10;\n int dp[mn];\n int minOpsByIndex(int i, vector<int>& nums, int flip = 0) {\n int n = nums.size();\n if(i == n - 1) {\n if(flip == 0)\n return dp[i] = (nums[n - 1] == 0? 1 : 0);\n retur...
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 n;\n int dp[100005][2];\n int rec(int level, int target, vector<int>& nums){\n if(level==n){\n return 0;\n }\n if(dp[level][target]!=-1){\n return dp[level][target];\n }\n\n int ans = 1e9;\n if(nums[lev...
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 dp[100001][2];\n int solve(int level, int op,vector<int>&nums ){\n if(level==nums.size()){\n return 0;\n }\n if(dp[level][op] != -1){\n return dp[level][op];\n }\n int ans;\n if(op == 0){\n if(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 dp[100001][2];\n int solve(int level, int op,vector<int>&nums ){\n if(level==nums.size()){\n return 0;\n }\n if(dp[level][op] != -1){\n return dp[level][op];\n }\n int ans;\n if(op == 0){\n if(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>& n) {\n string nums = \"\";\n for(int i=0;i<n.size();i++) nums+=(n[i]+'0');\n int total = unique(nums.begin(),nums.end()) - nums.begin();\n cout<<total<<\" \"<<nums;\n if(nums[0]=='1') total--;\n return t...
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 deque<int>dq;\n int ans=0;\n\n for(int i=0;i<nums.size();i++){\n if( (nums[i]+dq.size()) % 2 == 0){ //True value is zero\n if(i>nums.size()){\n return -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</...
3
{ "code": "class Solution {\npublic:\n int minOperations(vector<int>& nums) {\n queue<int> q;\n int ans=0;\n int n=nums.size();\n for(int i=0;i<n;i++){\n if((nums[i]+q.size())%2==0){\n q.push(i);\n ans++;\n }\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</...
3
{ "code": "class Solution {\npublic:\n Solution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n }\n int minOperations(vector<int>& nums) {\n int ans=0,n=nums.size();\n queue<int>q;\n for(int i=0; i<n; i++){\n if((q.size() + 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": "#define ll long long int\nclass Solution {\npublic:\n // for this we have \n ll dp[100005][2];\n ll solve(ll idx,vector<int>&nums,ll n,int f)\n {\n if(idx==n)\n return 0;\n if(dp[idx][f]!=-1)\n return dp[idx][f];\n ll ans=INT_MAX;\n if((nums[idx...
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\n int n=nums.size();\n vector<int> rgtz(n,0);\n int z=0;\n for(int i=n-1;i>=0;i--)\n { \n if(!(nums[i]))\n {\n z++;\n }\n rgtz[i]=z;\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:\nint minOperations(vector<int> &nums)\n{\n int size = nums.size();\n int operations = 0;\n int i = 0;\n vector<int> flippingCounts(size, 0);\n int mod = 0;\n while (i < size)\n {\n if (nums[i] == mod)\n {\n flippingCounts[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 \n{\npublic:\n int minOperations(vector<int>&v) \n {\n int ans=0;\n vector<int>t(v.size()+1,0);\n for(int i=0;i<v.size();i++)\n {\n if(i==0)\n {\n if(v[i])\n {\n //pass\n }...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
0
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& req) {\n vector<int> a(n, -1);\n int m = req.size();\n for(int i = 0; i < m; i++)\n a[req[i][0]] = req[i][1];\n if(a[0] != -1 and a[0] != 0)\n return 0;\n int mod = 1...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
0
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& req) {\n vector<int> a(n, -1);\n int m = req.size();\n for(int i = 0; i < m; i++)\n a[req[i][0]] = req[i][1];\n if(a[0] != -1 and a[0] != 0)\n return 0;\n int mod = 1...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
1
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n vector<long long> dp(401, 0), dp_prev(401, 0);\n long long mdl = 1000000007;\n unordered_map<int, int> req;\n for (const auto &r : requirements) {\n if (r[0] == 0 && ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
1
{ "code": "class Solution {\n const int M = 1e9 + 7;\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n vector<int> req(n, -1);\n req[0] = 0;\n for (auto& r : requirements) {\n req[r[0]] = r[1];\n }\n if (req[0] > 0) return 0;\n\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
1
{ "code": "class Solution {\n using ll = long long;\n const static ll mod = 1e9 + 7;\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n // dp[i][j]\n vector<int> r(n, -1);\n int mx = 0;\n for (auto &v : requirements) {\n r[v[0]] = v[1];\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
1
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n constexpr int MOD = 1'000'000'007;\n std::vector<int> end_to_count(n, -1);\n int max_inversions = 0;\n for (const auto &requirement : requirements)\n {\n end_t...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
2
{ "code": "int mod = int(1e9) + 7;\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& r) {\n sort(r.begin(), r.end());\n int k = r.back()[1];\n vector<long long> dp(k+1);\n dp[0] = 1;\n for(int i=1;i<r.size();i++) if(r[i-1][1] > r[i][1]) return 0; /...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
2
{ "code": "int mod = int(1e9) + 7;\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& r) {\n sort(r.begin(), r.end());\n int k = r.back()[1];\n vector<long long> dp(k+1);\n dp[0] = 1;\n for(int i=1;i<r.size();i++) if(r[i-1][1] > r[i][1]) return 0; /...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
2
{ "code": "#include \"bits/stdc++.h\"\nusing namespace std;\ntemplate <class T, size_t size=tuple_size<T>::value>\nstring to_debug(T, string s=\"\")\n\trequires(not ranges::range<T>);\nstring to_debug(auto x)\n\trequires requires(ostream &os) { os<<x; }\n{\n\treturn static_cast<ostringstream>(ostringstream()<<x).str(...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
2
{ "code": "#define ll long long\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& b) {\n const int mod=1e9+7;\n auto add=[&](ll x, ll y){\n ll val= (x%mod+y%mod)%mod;\n while(val<0) val+=mod;\n return val;\n };\n const int...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
2
{ "code": "#define ll long long\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& b) {\n const int mod=1e9+7;\n auto add=[&](ll x, ll y){\n ll val= (x%mod+y%mod)%mod;\n while(val<0) val+=mod;\n return val;\n };\n const int...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
2
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& r) {\n vector<int> f(n+1,-1);\n int M=1e9+7;\n for(int i=0;i<r.size();i++)f[r[i][0]]=r[i][1];\n vector<vector<int>>dp(n+1,vector<int>(402));\n for(int i=1;i<=400;i++)dp[0][i]=1;\n f...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
2
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& req) \n {\n\n\n vector<vector<int>>dp(n,vector<int>(401,0));\n\n \n dp[0][0]=1;\n\n map<int,int>mp;\n\n\n for(auto q:req)\n {\n if(q[1]>((q[0]*(q[0]+1))/2))\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const int mod=1e9+7;\n vector<vector<int>> dp;\n int rec(int idx,int inv,int j,int& n,vector<vector<int>>& v)\n {\n if(idx==n)\n return 1;\n if(dp[idx][inv]!=-1)\n return dp[idx][inv];\n int ans=0;\n for(int i=0;i<=id...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "#define P ((int)1e9 + 7)\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n vector<int> count(n+1, -1);\n for(int i = 0; i < requirements.size(); i++) {\n count[requirements[i][0]] = requirements[i][1];\n }\n if (cou...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& b) {\n const int mod=1e9+7;\n auto add=[&](ll x, ll y){\n ll val= (x%mod+y%mod)%mod;\n while(val<0) val+=mod;\n return val;\n };\n const int...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "const long long mod = 1e9+7;\n\nclass Solution {\n vector<vector<long long>> dp;\n\n long long dfs(int i, int reqs_idx, int cnt, vector<vector<int>> &reqs) {\n if(reqs_idx >= 0 && reqs[reqs_idx][0] == i) {\n if(reqs[reqs_idx][1] != cnt) return 0;\n\n reqs_idx--;\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "typedef long long ll;\nll mod = 1000000007;\n\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n int lim = 401;\n vector<ll> dp(lim, 0);\n map<int,int> reqs;\n for (vector<int> req : requirements) reqs[req[0]] = req[1];\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "// let dp[i][j] find the number of permutations that have max element i and j inversions\n// dp[i][j] = sum (dp[i-1][k], 0<=k=j)\ntypedef long long ll;\nconst ll mod = 1e9+7;\nconst ll mx = 401;\nclass Solution {\npublic:\n int numberOfPermutations(ll n, vector<vector<int>>& requirements) {\n vec...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "int mod = 1e9 + 7;\nclass Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n vector<long long> req(n + 1, -1);\n for (vector<int>& x : requirements) {\n req[x[0]] = x[1];\n }\n vector<vector<long long>> dp(n + 1, vector<lon...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const int MOD = 1000000007;\n\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n // dp[endi][cnti] represents the number of permutations of length endi+1 with cnti inversions\n vector<vector<int>> dp(n + 1, vector<int>(401, 0));\n \n /...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) {\n int mod = 1e9 + 7;\n sort(requirements.begin(),requirements.end());\n int idx = 0 ;\n if(requirements[0][0]==0){\n if(requirements[0][1]==0){\n idx=1;\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& requirements) \n {\n \n int mod = 1e9 + 7;\n sort(requirements.begin(),requirements.end());\n int idx = 0 ;\n \n if(requirements[0][0]==0)\n {\n if(requirements[0][1]==0)\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const long long MOD=1e9 + 7;\n struct cmp{\n bool operator() (vector<int>&a, vector<int>&b){\n return a[0]<b[0];\n }\n };\n int numberOfPermutations(int m, vector<vector<int>>& r) {\n long long ans;\n r.insert(r.begin(),{0,0});\...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const long long MOD=1e9 + 7;\n struct cmp{\n bool operator() (vector<int>&a, vector<int>&b){\n return a[0]<b[0];\n }\n };\n int numberOfPermutations(int m, vector<vector<int>>& r) {\n long long ans;\n r.insert(r.begin(),{0,0});\...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const long long MOD=1e9 + 7;\n struct cmp{\n bool operator() (vector<int>&a, vector<int>&b){\n if(a[0]==b[0]) return a[1]<b[1];\n return a[0]<b[0];\n }\n };\n int numberOfPermutations(int m, vector<vector<int>>& r) {\n long ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const long long mod = 1e9 + 7;\n\n int solve(int numDistinct, int inv, unordered_map<int, int> &req, vector<vector<int>> &memo) {\n if (inv < 0)\n return 0;\n\n if (req.find(numDistinct) != req.end() && req[numDistinct] != inv)\n return ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const long long mod = 1e9 + 7;\n\n int solve(int pos, int inv, int &n, unordered_map<int, int> &req, vector<vector<int>> &memo) {\n if (pos == n)\n return 1;\n\n if (inv > 400)\n return 0;\n\n if (memo[pos][inv] != -1)\n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\n const long long mod = 1e9 + 7;\n\n int solve(int numDistinct, int inv, unordered_map<int, int> &req, vector<vector<int>> &memo) {\n if (inv < 0)\n return 0;\n\n if (req.find(numDistinct) != req.end() && req[numDistinct] != inv)\n return ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>>dp;\nint dfs(int i, int j, int cnt, vector<vector<int>>& reqs) \n{\n if ( j >= 0 && reqs[j][0] == i ) \n {\n if (reqs[j][1] != cnt)\n return 0;\n j--;\n }\n\n if ( i == 0 || i * (i + 1) / 2 < cnt )\n return cnt == 0; \n ...
3,460
<p>You are given an integer <code>n</code> and a 2D array <code>requirements</code>, where <code>requirements[i] = [end<sub>i</sub>, cnt<sub>i</sub>]</code> represents the end index and the <strong>inversion</strong> count of each requirement.</p> <p>A pair of indices <code>(i, j)</code> from an integer array <code>nu...
3
{ "code": "int MOD = 1e9 + 7;\nclass Solution {\n vector<vector<int>> dp;\npublic:\n int numberOfPermutations(int n, vector<vector<int>>& reqs) {\n sort(reqs.begin(), reqs.end());\n dp = vector<vector<int>>(301, vector<int>(401, 0));\n\n dp[0][0] = 1; \n if (reqs[0][0] == 0 &&...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
0
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& v) {\n int n=v.size();\n sort(v.begin(),v.end());\n int i=0,j=n-1;\n double ans=INT_MAX;\n while(i<j) {\n double k = (v[i]+v[j])/(2*1.0);\n ans=min(ans,k);\n i++;\n ...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
0
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n double res = DBL_MAX;\n int l = 0;\n int r = nums.size() - 1;\n\n sort(nums.begin(), nums.end());\n\n while (l < r) {\n\n res = min(res, (double)(nums[l] + nums[r])/2);\n l++...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
0
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n sort(nums.begin(), nums.end()); \n int left = 0;\n int right = nums.size() - 1;\n double minAvg = INT_MAX;\n while(left < right){\n double avg = (nums[left] + nums[right]) / 2.0; \n ...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
0
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n double res=INT_MAX;\n sort(nums.begin(), nums.end());\n int l=0, r=nums.size()-1;\n while(l<r){\n double avg = (nums[l++] +nums[r--])/2.0;\n res=min(res, avg);\n }\n r...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
0
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n \n int n = nums.size();\n int i = 0,j= n-1;\n double ans = 3000;\n\n while(i<j){\n double sum = (nums[i]+nums[j])/double(2.0);\n ...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
0
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n sort(begin(nums), end(nums));\n\n double avg = FLT_MAX;\n int n=nums.size();\n\n //[7,8,3,4,15,13,4,1]\n // 1,3,4,4,7,8,13,15\n for (int i = 0; i < n/2; i++)\n {\n double ...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
0
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n double num=10000000;\n int n=nums.size();\n sort(nums.begin(),nums.end());\n int i=0, j=n-1;\n while(i<j)\n {\n num = min(num , (double)(nums[j]+nums[i])/2);\n i++;\n ...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
1
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n vector<double> averages ;\n sort(nums.begin(), nums.end()) ;\n double avg ;\n int i = 0 ;\n int j = nums.size()-1 ;\n double maxAvg = DBL_MAX ;\n while(i < j){\n avg = (do...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
1
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n sort(nums.begin(), nums.end()) ;\n double avg ;\n int i = 0 ;\n int j = nums.size()-1 ;\n double maxAvg = DBL_MAX ;\n while(i < j){\n avg = (double)((nums.at(i)+nums.at(j))/2.0) ...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
1
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n sort(nums.begin() , nums.end());\n int n= nums.size();\n int low=0, high=n-1;\n vector<double>avg;\n double maxi = INT_MAX;\n while(low<high){\n double average = double(nums[high...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
1
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n vector<double>ans;\n double avg;\n int n=nums.size();\n int start=0,end=n-1;\n while(start<end){\n avg=(nums[start]+nums[end])/2.0;\n ...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
2
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n sort(nums.begin() , nums.end());\n int n= nums.size();\n int low=0, high=n-1;\n vector<double>avg;\n double maxi = INT_MAX;\n while(low<high){\n double average = double(nums[high...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
2
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n vector<double> v;\n sort(nums.begin(), nums.end());\n int l=0, r=nums.size()-1;\n while(l<=r) v.push_back(((double)nums[l++]+(double)nums[r--])/(double)2);\n return *min_element(v.begin(), v.end(...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
3
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n vector<double> av;\n \n while (nums.size() > 1) {\n auto min_it = min_element(begin(nums), end(nums));\n auto max_it = max_element(begin(nums), end(nums));\n \n doubl...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
3
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n vector<double> v;\n sort(nums.begin(), nums.end());\n int n=nums.size();\n int l=0, r=n-1;\n while(l<=r){\n double avg= ((double)nums[l++]+(double)nums[r--])/(double)2;\n v.p...
3,471
<p>You have an array of floating point numbers <code>averages</code> which is initially empty. You are given an array <code>nums</code> of <code>n</code> integers where <code>n</code> is even.</p> <p>You repeat the following procedure <code>n / 2</code> times:</p> <ul> <li>Remove the <strong>smallest</strong> elemen...
3
{ "code": "class Solution {\npublic:\n double minimumAverage(vector<int>& nums) {\n int time = nums.size()/2;\n vector<double>avg;\n sort(nums.begin(),nums.end());\n int s = 0 ;\n int e = nums.size()-1;\n while(time>0 && s<=e){\n double d = double(nums[s]+nums[e...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nint parse_input_and_solve(const std::string& s) {\n const int S = s.size();\n int cols = 0;\n int rows = 0;\n int k = 2;\n\n int m...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nint parse_input_and_solve(const std::string& s) {\n const int S = s.size();\n int cols = 0;\n int rows = 0;\n int k = 2;\n\n int m...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n\nint parse_input_and_solve(const std::string& s) {\n const int S = s.size();\n int cols = 0;\n int rows = 0;\n int k = 2;\n\n int m...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\nclass Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int m=grid.size();\n int n=grid[0].size();\n int...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int up = grid.size();\n int bottom = 0;\n int left = grid[0].size();\n int right = 0;\n for(int i = 0;...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "static const bool Booster = [](){\n std::ios_base::sync_with_stdio(false);\n std::cout.tie(nullptr);\n std::cin.tie(nullptr);\n return true;\n}();\n#include<iostream>\n\nclass Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int min_x=grid.size(),min_y=grid[0].size...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n int lRow=INT_MAX;\n int hRow=INT_MIN;\n int lCol=INT_MAX;\n int hCol=INT_MIN;\n int n=grid.size();\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int max_r=0, max_c=0;\n int min_r=grid.size(), min_c=grid[0].size();\n for(int i=0;i<grid.size();i++){\n for(int j=0;j<grid[0].size();j++){\n if(grid[i][j]==1){\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int n =grid.size();\n int m =grid[0].size();\n int mini_row=INT_MAX,mini_col=INT_MAX;\n int maxi_row=0,maxi_col=0;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& v) {\n int n=v.size();\n int m=v[0].size();\n int r1=INT_MAX,c1=INT_MAX,r2=INT_MIN,c2=INT_MIN;\n for(int i=0;i<n;i++) {\n for(int j=0;j<m;j++) {\n if(v[i][j]==1) {\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\n\n typedef pair<int,int> pi;\npublic:\n\n int row_sum(int x, int y1, int y2, vector<vector<int>>& mat){\n for(int j = y1; j <= y2; j++){\n if(mat[x][j]){\n return 1;\n }\n }\n\n return 0;\n }\n\n int row_col(int y, int ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int rowStartIndex = -1, rowEndIndex = -1;\n int jStartIndex = -1, jEndIndex = -1;\n int rows = grid.size();\n int cols = grid[0].size();\n \n // Find the topmost and bottommost rows with ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int r_min=INT_MAX, c_min=INT_MAX, r_max=INT_MIN, c_max=INT_MIN;\n for(int i=0;i<grid.size();i++){\n for(int j=0;j<grid[0].size();j++){\n if(grid[i][j]){\n r_min=min(r_min...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
0
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int minRow = INT_MAX, maxRow = INT_MIN;\n int minCol = INT_MAX, maxCol = INT_MIN;\n\n for (int row = 0; row < grid.size(); ++row) {\n for (int col = 0; col < grid[row].size(); ++col) {\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
2
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int lRow=INT_MAX;\n int hRow=INT_MIN;\n int lCol=INT_MAX;\n int hCol=INT_MIN;\n int n=grid.size();\n int m=grid[0].size();\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++)...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
2
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& g) {\n int n=g.size(),m=g[0].size();\n int t=0,b=n-1,l=0,r=m-1;\n while(t<n){\n bool x=0;\n for(int i=0;i<m;i++){\n if(g[t][i]==1){\n x=1;\n br...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n \n int rows=grid.size();\n int cols=grid[0].size();\n int above_row=rows,down_row=rows,left_col,right_col;\n // int rows=grid.size();\n // int cols=grid[0].size();\n for(int i=0;i<...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n vector<int> row(grid.size(),0);\n vector<int> col(grid[0].size(),0);\n for(int i=0;i<grid.size();i++){\n for(int j=0;j<grid[0].size();j++){\n if(grid[i][j]==1){\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int r=grid.size();\n int c=grid[0].size();\n vector<int> hz(c,0);\n vector<int> vr(r,0);\n for(int i=0;i<r;i++){\n for(int j=0;j<c;j++){\n if(grid[i][j]==1){\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int rs=int(grid.size()), cs=int(grid[0].size());\n vector<int> r1(rs), c1(cs);\n for (int r=0; r<rs; ++r) {\n for (int c=0; c<cs; ++c) {\n r1[r]+=grid[r][c];\n c1[c]+=...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int n = grid.size(),m=grid[0].size();\n vector<int> vert(n,0),hor(m,0);\n\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(grid[i][j] == 1){\n vert[i]=(1);\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n \n // checking for rows\n\n int n = grid.size();\n int m = grid[0].size();\n \n vector<int> row;\n for(int i =0;i<n;i++){\n int sum = 0;\n for(int j =0;j<m;j+...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int r = grid.size();\n int c = grid[0].size();\n vector<int> rows;\n vector<int> cols;\n\n for (int i = 0; i < grid.size(); i++){\n int sum = 0;\n for (int j = 0; j < grid[...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n int i=-1,j=-1;\n vector<int>row(n,0);\n vector<int>col(m,0);\n for(int x=0;x<n;x++){\n for(int y=0;y<m;y++){\n if(gr...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n bool ch(vector<int> v1){\n for(int i=0;i<v1.size();i++){\n if(v1[i]==1) return false;\n }\n return true;\n }\n\n int minimumArea(vector<vector<int>>& grid) {\n int len=grid[0].size();\n int hei=grid.size();\n\n int a=0;\n...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n bool ch(vector<int> v1){\n for(int i=0;i<v1.size();i++){\n if(v1[i]==1) return false;\n }\n return true;\n }\n\n int minimumArea(vector<vector<int>>& grid) {\n int len=grid[0].size();\n int hei=grid.size();\n\n int a=0;\n...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n bool ch(vector<int> v1){\n for(int i=0;i<v1.size();i++){\n if(v1[i]==1) return false;\n }\n return true;\n }\n\n int minimumArea(vector<vector<int>>& grid) {\n int len=grid[0].size();\n int hei=grid.size();\n\n int a=0;\n...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n set<int>row; set<int>col;\n int minimumArea(vector<vector<int>>& grid) {\n int n = grid.size();int m = grid[0].size();\n for(int i = 0;i<n;i++){\n for(int j =0;j<m;j++){\n if(grid[i][j]==1){ row.insert(i);col.insert(j);}\n\n }\n }\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int n=grid.size();\n int m=grid[0].size();\n set<int> row,col;\n for(int i=0;i<n;i++)\n {\n for(int j=0;j<m;j++)\n {\n if(grid[i][j])\n {\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n unordered_set<int>row;\n unordered_set<int>col;\n int n = grid.size();\n int m = grid[0].size();\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(grid[i][j]==1){\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int n = grid.size();\n int m = grid[0].size();\n queue<pair<int,int>>q;\n for(int i=0;i<n;i++){\n for(int j=0;j<m;j++){\n if(grid[i][j]==1){\n q.push({i,j})...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN;\n int i = 0;\n for (auto row: grid) {\n int j = 0;\n for (auto element:row) {\n if (element == 1) {\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "class Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n int m = grid.size();\n int n = grid[0].size();\n // transpose of grid\n vector<vector<int>>transpose(n, vector<int>(m, 0));\n for(int i=0;i<m;i++){\n for(int j=0;j<n;j++){\n ...
3,461
<p>You are given a 2D <strong>binary</strong> array <code>grid</code>. Find a rectangle with horizontal and vertical sides with the<strong> smallest</strong> area, such that all the 1&#39;s in <code>grid</code> lie inside this rectangle.</p> <p>Return the <strong>minimum</strong> possible area of the rectangle.</p> <...
3
{ "code": "\nclass Solution {\npublic:\n int minimumArea(vector<vector<int>>& grid) {\n\n vector<pair<int, int>> v;\n for (int i = 0; i < grid.size(); i++) {\n for (int j = 0; j < grid[0].size(); j++) {\n if (grid[i][j] == 1) {\n v.push_back({i, j});\n ...