id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
0
{ "code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& a, vector<int>& b) {\n int n = a.size();\n int m = b.size();\n vector<map<int, int>> mp(m + 1);\n vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1e9));\n dp[0][0] = 0;\n for (int i = 0; i < n; i++){\...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
0
{ "code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& a, vector<int>& b) {\n int n = a.size();\n int m = b.size();\n vector<map<int, int>> mp(m + 1);\n vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1e9));\n dp[0][0] = 0;\n for (int i = 0; i < n; i++){\...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
0
{ "code": "class Solution {\npublic:\n int func(int i, int ind, vector<int>& nums, vector<int>& andV,vector<vector<map<int,int>>>&dp,int andop) {\n int n = nums.size();\n int m = andV.size();\n if(dp[i][ind].count(andop))return dp[i][ind][andop];\n if (i==n and ind == m) {\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
0
{ "code": "class Solution {\npublic:\n vector<vector<map<int,int>>>dp;\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n=nums.size();\n int m=andValues.size();\n dp.resize(n,vector<map<int,int>>(m));\n int ans=find(nums,0,andValues,0,n,m,-1);\n if(ans>...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
0
{ "code": "class Solution {\npublic:\n \n vector<vector<map<int,int>>>dp;\n long long solve(int ind , int ind2 , int curr , vector<int>&nums,vector<int>&req){\n if(ind2==req.size() && ind==nums.size()) return 0;\n if(ind2==req.size()) return INT_MAX;\n if(ind==nums.size()...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
0
{ "code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n\n unordered_map<long long, int> dp;\n auto dfs = [&] (auto&& dfs, long long i, long long j, long long and_) ->int {\n if(i == n) {\n...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n vector<vector<map<int,int>>>mpp;\n int f(vector<int>& nums, vector<int>& v,int i,int j,int curr){\n if(i==nums.size()){\n if(j==v.size()-1 && curr==v[j])return nums[i-1];\n return 1e9;\n }\n if(mpp[i][j].count(curr))return mpp[i][...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n vector<vector<map<int,int>>>mpp;\n int f(vector<int>& nums, vector<int>& v,int i,int j,int curr){\n if(i==nums.size()){\n if(j==v.size()-1 && curr==v[j])return nums[i-1];\n return 1e9;\n }\n if(mpp[i][j].find(curr)!=mpp[i][j].end(...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n int f(vector<int>& nums, vector<int>& v,int i,int j,int curr,vector<vector<map<int,int>>>& dp){\n if(i==nums.size()){\n if(j==v.size()-1 && curr==v[j])return nums[i-1];\n return 1e9;\n }\n if(dp[i][j].find(curr)!=dp[i][j].end())retur...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\nvector<vector<map<int,int>>>dp;\nint fun(vector<int>&nums,vector<int>&ad,int i,int j,int curand){\n if(i>=nums.size()){\n if(j>=ad.size())return 0;\n return 1e7;\n }\n\n if(j>=ad.size())return 1e7;\n if(dp[i][j].count(curand))return dp[i][j][curand];\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\nconst int q=(1<<20)-1;\n int INF = 2e9;\n int func(int n, int m, int i, int j, vector<vector<map<int, int>>>& dp, int range, vector<int>& nums, vector<int>& andValues) {\n if(i==n) {\n if(j==m && range==q) return 0;\n return INF;\n }\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\nconst int q=(1<<20)-1;\n int INF = 2e9;\n int func(int n, int m, int i, int j, vector<vector<map<int, int>>>& dp, int range, vector<int>& nums, vector<int>& andValues) {\n if(i==n) {\n if(j==m && range==q) return 0;\n return INF;\n }\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n int n = nums.size(), m = andValues.size();\n memo.resize(m * n);\n int res = dfs(0, 0, INF, nums, andValues);\n return res < INF ? res : -1;\n }\n\nprivate:\n static const int...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\n\n vector<vector<unordered_map<int, int>>>dp;\n\n long long helper(vector<int>&nums, vector<int>&arr, int ind = 0, int curr_and = (1 << 20) - 1, int group_num = 0) {\n if (ind == nums.size()) {\n if (group_num == (arr.size() - 1) && curr_and == arr.back()) retur...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n m = nums.size(), n = andValues.size();\n dp = vector<unordered_map<int, int>>(m * n);\n int ans = dfs(0, 0, -1, nums, andValues);\n return ans < INT_MAX / 2 ? ans : -1;\n }\npriv...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n int solve(int i, int j, int val, vector<int>& nums, vector<int>& andValues, vector<vector<unordered_map<int, int>>>& dp) {\n if (i >= nums.size()) {\n if (j >= andValues.size()) return 0;\n else return 1000001;\n }\n if (j >= andValu...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n int solve(int i, int j, int val, vector<int>& nums, vector<int>& andValues, vector<vector<unordered_map<int, int>>>& dp) {\n if (i >= nums.size()) {\n if (j >= andValues.size()) return 0;\n else return 1000001;\n }\n if (j >= andValu...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "#include <vector>\n#include <unordered_map>\n#include <algorithm>\n\nclass Solution {\nprivate:\n std::unordered_map<int, long long> mp[10009][11];\n std::vector<int> a, an;\n int n, m;\n \npublic:\n long long solve(int i, int j, int nd) {\n // Base cases\n if (i == n && j == m...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n \n vector<vector<unordered_map<int,int>>>dp;\n long long solve(int ind , int ind2 , int curr , vector<int>&nums,vector<int>&req){\n if(ind2==req.size() && ind==nums.size()) return 0;\n if(ind2==req.size()) return INT_MAX;\n if(ind==n...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n bool chk(int a, int b)\n {\n for (int i = 0; i < 32; i++) {\n int val = (1<<i);\n if (b&val && !(a&val)) {\n return false;\n }\n }\n \n return true;\n }\n int dfs(vector<int>& nums, vector<in...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n vector<vector<map<int,int>>>dp;\n int n,m;\n int f(int i,int j,int val,vector<int>&v,vector<int>&av){\n if(i>=n){\n if(j>=m){\n return 0;\n }\n return 1e9;\n }\n if(j>=m){\n return 1e9;\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n int solve(int ind, int grpId, int _and, vector<int>& nums, vector<int>& andValues, vector<vector<unordered_map<int, int>>>& dp, int& n, int& m) {\n if (ind >= n) {\n if (grpId >= m) return 0;\n else return 1e9;\n }\n if (grpId >= m) ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n vector<vector<unordered_map<int,int>>> dp;\n int f(int i, int j, int currAnd, vector<int> &nums, vector<int> &andVals){\n int n = nums.size(), m = andVals.size();\n if(i == n && j == m) return 0;\n if(i == n || j == m || currAnd < andVals[j]) return 1e...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\n\tpublic:\n\tvector<vector<unordered_map<int,int>>> dp;\n\tint helper(vector<int>& nums, vector<int>& andValues, int cur, int andCur, int And){\n\t\tif(cur>=nums.size()){\n\t\t\tif(andCur>=andValues.size()) return 0;\n\t\t\telse return 1e8;\n\t\t}\n\t\telse if(andCur>=andValues.size()) re...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n vector<vector<unordered_map<int, int>>> dp;\n int n, m;\n\n int rec(int i, int j, int val, vector<int>& nums, vector<int>& andValues) {\n if (i >= n) {\n return (j >= m) ? 0 : 1e9;\n } \n if (j >= m) {\n return 1e9;\n }...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n vector<vector<unordered_map<int, int>>> dp;\n int helper(vector<int>& nums, vector<int>& andValues, int cur, int andCur, int And){\n\t\tif(cur>=nums.size()){\n\t\t\tif(andCur>=andValues.size()) return 0;\n\t\t\telse return 1e8;\n\t\t}\n\t\telse if(andCur>=andValues.size())...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\n\tint helper(vector<int>& nums, vector<int>& andValues, int i, int j, int value){\n if(i == nums.size() && j == andValues.size()) return 0;\n else if(i == nums.size() || j == andValues.size()) return 1e8;\n else if(mem[i][j].count(value)) return mem[i][j][value];\n\t\...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n int n, m;\n vector<int> nums;\n vector<int> andValues;\n vector<vector<unordered_map<int, int> > > memo;\n\n //end at current index if the and value permits else continue\n int solve (int indexNums, int indexValues, int currAnd) {\n if (indexNums >= n) {...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n // int x[10010][15];\n // int t[400050];\n // build(int node,int tl,int tr,vector<int> &nums){\n // if(tl==tr){\n // t[node]=nums[i];\n // return;\n // }\n // int tm=(tl+tr)/2;\n // build(2*node,tl,tm,nums);\n // ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\n vector<vector<unordered_map<int,int>>>dp;\n int solve(vector<int>& nums, vector<int>& andValues, int i, int j, int curand){\n int n = nums.size(), m = andValues.size();\n if(i>=n){\n if(j>=m)return 0;\n return 1e9;\n }\n else if(j>=m)return 1e9;\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n\n vector<vector<unordered_map<int, int>>> dp;\n\n long long solve(int i, int j, vector<int>& nums, vector<int>& andValue, int value){\n int n = nums.size();\n int m = andValue.size();\n if(i >= n && j >= m) return 0;\n if(i >= n) return INT_MAX;...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
1
{ "code": "class Solution {\npublic:\n vector<vector<unordered_map<int,int>>> dp;\n vector<int> N, A;\n int n, m;\n\n int find(int loc, int lef, int andi){\n if(loc == n && lef == m) return 0;\n else if(loc == n) return 1e9;\n else if(lef == m) return 1e9;\n\n if(dp[loc][lef][a...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n vector<vector<unordered_map<ll,ll>>> dp;\n ll solve(int i,int k,ll val,vector<int>& nums,vector<int>& andVal){\n int m=andVal.size();\n int n=nums.size();\n if(k==m && i==n) return 0;\n\n if(i==n) return 1e15;\n if...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "vector<vector<unordered_map<int,int>>>dp;\nconst int changer = 20;\n#define outo(x) cout << x << \" \"\n#define out(x, y, z) cout << x << \" \" << y << \" \" << z << endl\n\nclass Solution {\npublic:\n int inf = 10000007;\n int findmini(int curval,int idx1,vector<int>&a, int idx2, vector<int>&v)\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\n int n;\n int m;\n vector<vector<unordered_map<int, int>>> dp;\n //unordered_map<int, unordered_map<int, unordered_map<int,int>>> dp;\n int solve(int i,int j, vector<int>& nums, vector<int> & andValues, int ansop){\n if(i>=n){\n if(j>=m){\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\n int n;\n int m;\n\n vector<vector<unordered_map<int,int>>> dp;\n int solve(vector<int>& nums, vector<int>& andValues,int i,int j,int andOp){\n // base case\n if(i>=n){\n if(j>=m) return 0;\n else return 1e9;\n } else if(j>=m...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\nconst int q=(1<<20)-1;\n int INF = 2e9;\n int func(int n, int m, int i, int j, vector<vector<unordered_map<int, int>>>& dp, int range, vector<int>& nums, vector<int>& andValues) {\n if(i==n) {\n if(j==m && range==q) return 0;\n return INF;\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\nconst int q=(1<<20)-1;\n int INF = 2e9;\n int func(int n, int m, int i, int j, vector<vector<unordered_map<int, int>>>& dp, int range, vector<int>& nums, vector<int>& andValues) {\n if(i==n) {\n if(j==m && range==q) return 0;\n return INF;\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\n\n vector<vector<unordered_map<int,int> > > dp;\n int solve(int i, int j, int mask, vector<int> &nums, vector<int> &v)\n {\n if(j==v.size())\n {\n return (i>=nums.size()) ? 0 : 1e9;\n }\n\n if(dp[i][j].count(mask)) return dp[i][j][m...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\n int solve(int i,int j,vector<int> &nums,vector<int> &an,unordered_map<int,unordered_map<int,unordered_map<int,int> > > &dp,int x)\n {\n if(j>=an.size())\n return 1e6;\n if(i>=nums.size())\n {\n if(x==an.back() && j+1==an.size())\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\n vector<int> a, b;\n int n, m;\n unordered_map<int,unordered_map<int,unordered_map<int,int>>> dp;\n int inf = 1000000;\n int ans(int i, int j, int k) {\n if (i == n and j == m)return 0;\n if (i == n or j == m)return inf;\n int p=inf;\n i...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\n int n,m;\n vector<vector<unordered_map<int,int>>>dp;\n\n int f(int i, int j, int curr, vector<int>&nums, vector<int>&v)\n {\n if(i == n)\n {\n if(j < m-1) return 1e9;\n if(j == m-1)\n {\n if(curr == v[m-1]) return ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
2
{ "code": "class Solution {\npublic:\n int solve(vector<int>&nums,vector<int>& andValues,int curr,int idx,int currAnd, vector<vector<unordered_map<int,int>>>&dp)\n {\n if(curr==nums.size())\n {\n if(idx==andValues.size())\n return 0;\n return 1e8;\n }\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\n#define ll long long\nint n,m;\n// ll dp[10001][11];\nvector<vector<unordered_map<int,int>>> dp;\nint f(int i,int j,int curand,vector<int>& nums, vector<int>& andv){\n \n if(i==n){\n if(j<m-1) return 1e9;\n if(j==m-1){\n if(curand == andv[m-1]) retu...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\nint n;\nint m;\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n if(nums[0]<andValues[0])return -1;\n n=nums.size();\n m=andValues.size();\n vector<vector<unordered_map<int, int>>> dp(n+1, vector<unordered_map<int, int>>(11));\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\nusing namespace __gnu_pbds;\nusing namespace std;\nusing ll=long long;\ntypedef tree <pair<ll,ll>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;\n/*\n order_of_key (k)\n find_by_order(k)\n*/\ntemplat...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\n int n;\n int m;\n //vector<vector<unordered_map<int, int>>> dp;\n unordered_map<int, unordered_map<int, unordered_map<int,int>>> dp;\n int solve(int i,int j, vector<int>& nums, vector<int> & andValues, int ansop){\n if(i>=n){\n if(j>=m){\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\n /*\n Recursion with memorization\n */\npublic:\n int MAX = 131071;\n vector<vector<unordered_map<int, int>>> memo;\n int minimumValueSum(vector<int>& nums, vector<int>& andValues) {\n memo = vector<vector<unordered_map<int, int>>>(nums.size()+1, vector<unordered_...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\n// int solve(vector<vector<int>> &pre , int l ,int k , vector<int> &And, vector<int> &nums)\n// {\n\n \n \n// if(l == nums.size() &&k == And.size()) return 0;\n// if(l == nums.size() || k == And.size()) return 1e9;\n// int maxm = 1e9;\n// // cout<<\"yes\"...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\n#define ll long long int\nunordered_map<int,unordered_map<int,unordered_map<int,int>>>mp;\nll func(int ind,int ind1,int n,int m,vector<int>&nums,vector<int>&a,int res){\n // cout<<ind<<\" \"<<ind1<<endl;\n if(ind>=n && ind1>=m)\n return 0;\n if(ind>=n || ind1>=m)\n ...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\n long long pos(vector<int>&nums,vector<int>&andvalues,int ind,int value,int covered,unordered_map<int,unordered_map<int,unordered_map<int,int>>>&dp){\n if(covered>=andvalues.size())return 1e6;\n if(ind>=nums.size()){\n if(value==andvalues[andvalues.siz...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\n long long pos(vector<int>&nums,vector<int>&andvalues,int ind,int value,int covered,unordered_map<int,unordered_map<int,unordered_map<int,int>>>&dp){\n if(covered>=andvalues.size())return 1e6;\n if(ind>=nums.size()){\n if(value==andvalues[andvalues.siz...
3,364
<p>You are given two arrays <code>nums</code> and <code>andValues</code> of length <code>n</code> and <code>m</code> respectively.</p> <p>The <strong>value</strong> of an array is equal to the <strong>last</strong> element of that array.</p> <p>You have to divide <code>nums</code> into <code>m</code> <strong>disjoint...
3
{ "code": "class Solution {\npublic:\n long long pos(vector<int>&nums,vector<int>&andvalues,int ind,int value,int covered,unordered_map<int,unordered_map<int,unordered_map<int,int>>>&dp){\n if(covered>=andvalues.size())return 1e6;\n if(ind>=nums.size()){\n if(value==andvalues[andvalues.siz...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n int n = word.length();\n int count = 0;\n for(int i = 0;i < 26;i++){\n char c = char(int('a') + i);\n char cu = char(int (c) - 32);\n bool isl = false,isu = false;\n for...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n int l = 0, u = 0;\n for (char ch: word) {\n if (islower(ch)) {\n int bit = 1 << (ch-'a');\n l = l | bit;\n }\n else {\n int bit = 1 << (ch-'A'...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n int charcnt = 0;\n for (char c = 'a'; c <= 'z'; c++) {\n char lower = c;\n char upper = c - 32;\n if (word.find(lower) != string::npos && word.find(upper) != string::npos) {\n charcnt++;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n int or_lower = 0, or_upper = 0;\n for (char ch : word) {\n if (islower(ch)) {\n or_lower |= (1 << (ch - 'a'));\n } else {\n or_upper |= (1 << (ch - 'A'));\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "\n//M-1 --> brute force\n\n/*\nclass Solution {\npublic:\n int numberOfSpecialChars(string word) {\n \n unordered_map<int, unordered_set<char>> mp;\n\n int ans=0;\n for(auto w: word)\n {\n mp[tolower(w)-'a'].insert(w);\n }\n for(auto it: mp) if...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n int lower=0,upper=0; // store data in bit\n for(char c : word){\n if(islower(c)) lower |= (1 << (c-'a'));\n else upper |= (1 << (c-'A'));\n }\n int count=0;\n for(int i=26;i>=0;...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n \n vector<char>Low(26,0),Up(26,0);\n int Ans=0;\n \n for(int i=0;i<word.size();i++)\n {\n if(word[i]>='a' and word[i]<='z')\n Low[word[i]-'a']++;\n else\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n bool upper[26] = {}, lower[26] = {};\n for (auto c : word) {\n if (isupper(c)) {\n upper[c - 'A'] = true;\n }\n if (islower(c)) {\n lower[c - 'a'] = true;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n vector<int> bitmap(26,0);\n int cnt = 0;\n for(int i = 0;word[i];i++){\n char c = word[i];\n if(c >= 'a' && c <= 'z'){\n if((bitmap[c-'a'] & 1UL) == 0){\n bi...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n vector<int>lower(26),upper(26);\n for(auto it : word){\n if(islower(it)) lower[it-'a']++;\n else upper[it-'A']++;\n }\n int count=0;\n for(int i=0;i<26;i++)\n count +...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n vector<int> mas(26), minu(26);\n for (int i = 0; i < word.size(); i++) {\n if (!(word[i] - tolower(word[i]))) {\n minu[word[i] - 'a']++;\n } else {\n mas[word[i] - 'A']...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n int n = word.size();\n vector<int> a(26, -1);\n vector<int> b(26, -1); \n for (int i = 0; i < n; i++) {\n char ch = word[i];\n if (islower(ch)) {\n a[ch - 'a'] = 1;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n\n int ch[26] = {0};\n int ch2[26] = {0};\n\n for(int i=0;i<word.size();i++){\n if(word[i]-'a' >=0 && word[i]-'a' <26)\n ch[word[i]-'a']++;\n if(word[i]-'A' >=0 && word[i]-'A'<26)\n...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
0
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n vector<int> lowerCase(26,0);\n vector<int> upperCase(26,0);\n for(auto &c: word){\n if(c-'a'>=0 && c-'a'<26){\n lowerCase[c-'a']=1;\n } else {\n upperCase[c-'A']...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
1
{ "code": "\n//M-1 --> brute force\n\n/*\nclass Solution {\npublic:\n int numberOfSpecialChars(string word) {\n \n unordered_map<int, unordered_set<char>> mp;\n\n int ans=0;\n for(auto w: word)\n {\n mp[tolower(w)-'a'].insert(w);\n }\n for(auto it: mp) if...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
1
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n vector<vector<int>> cnt(2, vector<int>(26));\n for(auto& x : word) {\n int i = ('a' <= x) && (x <= 'z');\n if(i == 1) {\n cnt[i][x-'a']++;\n } else {\n cnt[i...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
1
{ "code": "class Solution {\npublic:\n bool isspecial( string s , char ch )\n {\n if( isupper(ch) )\n {\n ch = tolower(ch) ; \n for( auto chr : s )\n {\n if( ch == chr )\n return true ; \n }\n }\n else if(i...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
1
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n int count = 0;\n set<char>st(word.begin(),word.end());\n\n // Loop through the set and count matching uppercase-lowercase pairs\n for(auto it : st){\n if((it >= 'a' && it <= 'z') && st.find(toupp...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
1
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n set<char> s;\n set<char> found;\n\n int special = 0;\n\n for (int i = 0; i < word.size(); ++i) {\n if (s.find(tolower(word[i])) != s.end() && found.find(tolower(word[i])) == found.end()) {\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
1
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n vector<int>hash(26,0);\n set<char>se(word.begin(),word.end());\n for(auto it:se)\n {\n if(int(it)>=97)\n {\n hash[int(it)-97]++;\n }\n else{\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n unordered_map<char,int>m;\n set<char>s;\n for(int i=0;i<word.length();i++)\n {\n char ch=word[i];\n if(ch>='a' && ch<='z')\n {\n m[ch]++;\n }\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n unordered_map<char, int> map;\n for(auto& c: word) {\n map[c]++;\n }\n int cnt = 0;\n for (int i = 0; i < 26; i++) {\n char c = 'a'+i;\n char c1 = 'A' + i;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n unordered_map<char, int> map;\n for(auto& c: word) {\n map[c]++;\n }\n int cnt = 0;\n for (int i = 0; i < 26; i++) {\n char c = 'a'+i;\n char c1 = 'A' + i;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n \n map<char,int>mp;\n int x=0;\n\n for(int i=0;i<word.size();i++)\n {\n mp[word[i]]++;\n }\n\n for(int i=0;i<word.size();i++)\n { char c;\n int d;\n if(int(w...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n unordered_map<int,char>mp;\n set<char>ch(word.begin(),word.end());\n for( auto c : ch)\n {\n c=tolower(c);\n mp[c]++;\n }\n int count=0;\n for(auto it : mp)\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n unordered_map<char,int>mp;\n set<char>ch(word.begin(),word.end());\n for( auto c : ch)\n {\n c=tolower(c);\n mp[c]++;\n }\n int count=0;\n for(auto it : mp)\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n map<char,int> presence;\n vector<int> visited(26,0);\n for(char c : word)\n {\n if(c>=97 && c<=122) \n {\n presence[c] = 1;\n visited[c-97] = 1;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word)\n {\n // A letter is special if it appears both in lowercase and uppercase \n //if it exists increment the counter by 1 else return 0 ;\n unordered_set<char> lowercase;\n unordered_set<char> uppercase;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
2
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n map<char,int> mp1;\n map<char,int>mp2;\n int cnt=0;\n for(auto ch:word){\n if(ch>=65 && ch<=90)mp1[ch]++;\n if(ch>=97 && ch<=122)mp2[ch]++;\n } \n for(auto ch:mp2){\n \n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
3
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word)\n {\n // A letter is special if it appears both in lowercase and uppercase \n //if it exists increment the counter by 1 else return 0 ;\n unordered_set<char> lowercase;\n unordered_set<char> uppercase;\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
3
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n unordered_set<char> lower;\n unordered_set<char> upper;\n for (const auto& w : word) {\n if (isupper(w)) { upper.insert(tolower(w)); }\n if (islower(w)) { lower.insert(w); }\n }\n ...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
3
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string w) {\n int ans = 0;\n unordered_map<char,int>a;\n unordered_set<char>s(w.begin(),w.end());\n for(char y:s){\n y=toupper(y);\n a[y]++;\n }\n for(auto x:a){\n if(x.second=...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
3
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n unordered_map<char, bool> mp;\n vector<bool>ans(26,false);\n int count = 0;\n // ab B C ab\n for (char ch: word) {\n if ('a' <= ch && ch <= 'z') {\n if (mp[toupper(ch)]) {\n...
3,408
<p>You are given a string <code>word</code>. A letter is called <strong>special</strong> if it appears <strong>both</strong> in lowercase and uppercase in <code>word</code>.</p> <p>Return the number of<em> </em><strong>special</strong> letters in<em> </em><code>word</code>.</p> <p>&nbsp;</p> <p><strong class="example...
3
{ "code": "class Solution {\npublic:\n int numberOfSpecialChars(string word) {\n map<char , bool> mp , mp1;\n int count = 0;\n for(auto ch : word){\n if(ch >= 'a' && ch <= 'z'){\n mp[ch] = true;\n }else{\n mp1[ch] = true;\n }\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int res = 0, mult = 1;\n while(true) {\n if(!num1 and !num2 and !num3) break;\n res = min({num1 % 10, num2 % 10, num3 % 10}) * mult + res;\n num1 /= 10; num2 /= 10; num3 /= 10;\n ...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int ans=0,i=1;\n // int n1=num1%10;\n // int n2=num2%10;\n // int n3=num3%10;\n while(num1 || num2 || num3){\n int dig=min({num1%10,num2%10,num3%10});\n ans=ans+dig*i;\n...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int t=4,ten=1,ans=0;\n while(t--){\n int o=num1%10;\n int s=num2%10;\n int t=num3%10;\n int temp=min(o,min(s,t))*ten;\n num1=num1/10;\n num2=num2...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n\n int ans = 0;\n int ten = 1;\n while (num1 && num2 && num3)\n {\n int a = num1%10;\n int b = num2%10;\n int c= num3%10;\n\n int temp = min(min(a,b),min(...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int div = 1000;\n int res = 0;\n\n for(int i = 0; i<4; i++){\n res = res*10 + min(num1/div, min(num2/div, num3/div));\n\n num1 %= div;\n num2 %= div;\n num3 %= d...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int res = 0;\n int prod = 1;\n for (int i = 0; i < 4; i++) {\n res += min(num1 % 10, min(num2 % 10, num3 % 10)) * prod;\n prod *= 10;\n num1 /= 10, num2 /= 10, num3 /= 10;\...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n \n int ans = 0 , temp =1 ; \n while( num1 > 0 || num2 > 0 || num3 > 0 )\n {\n int x = num1 % 10 ; \n num1 /= 10 ; \n int y = num2 % 10 ; \n num2 /= 10 ; \...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int key{0};\n \n int div = 1000;\n for(int i{0}; i<4; ++i)\n {\n key = key*10 + min(num1/div, min(num2/div, num3/div));\n\n num1 = num1%div;\n num2 = num2%div;\n...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int res=0;\n for(int i=0;i<4;i++){\n int a=num1%10;\n int b=num2%10;\n int c=num3%10;\n int ans=min(a,b);\n ans=min(ans,c);\n res+=((pow(10,i)*ans...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n ios_base::sync_with_stdio(false);\n cin.tie(NULL);\n int res=0;\n int mult=1;\n while(1){\n if(!num1 && !num2 && !num3)break;\n else{\n res+=min(num1%10,m...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n int a = 9, b = 9, c = 9, d = 9;\n for(int x : {num1, num2, num3})\n {\n a = min(a, x / 1000);\n b = min(b, (x / 100) % 10);\n c = min(c, (x / 10) % 10);\n d = mi...
3,568
<p>You are given three <strong>positive</strong> integers <code>num1</code>, <code>num2</code>, and <code>num3</code>.</p> <p>The <code>key</code> of <code>num1</code>, <code>num2</code>, and <code>num3</code> is defined as a four-digit number such that:</p> <ul> <li>Initially, if any number has <strong>less than</s...
0
{ "code": "class Solution {\npublic:\n int generateKey(int num1, int num2, int num3) {\n vector<int> ans;\n while(num1 != 0 || num2 != 0 || num3 != 0){\n ans.push_back(min(num1 % 10, min(num2 % 10, num3 % 10)));\n num1 /= 10;\n num2 /= 10;\n num3 /= 10;\n ...