id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 0 | {
"code": "#include <vector>\n#include <cstring>\n#include <algorithm>\n\nclass Solution {\npublic:\n int dp[101][101];\n\n int findMaxForm(std::vector<std::string>& arr, int m, int n) {\n // Initialize the DP table\n memset(dp, 0, sizeof(dp));\n\n // Traverse each string in the array\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int sz = strs.size();\n if(sz == 0)return(0);\n vector<int> arr0(sz, 0);\n vector<int> arr1(sz, 0);\n for(int i=0;i<sz;i++){\n arr0[i] = accumulate(strs[i].begin(), strs[i].e... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& str, int n, int m) {\n int nn = str.size();\n vector<int>a(nn); vector<int>b(nn); \n vector<vector<int>>dp(n+1,vector<int>(m+1));\n for(int i=0;i<nn;i++){\n string s = str[i];\n for(auto c:s){\n... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int maxlength=INT_MIN;\n vector<vector<int>> dp(m+1,vector<int> (n+1,0));\n\n \n for(auto str:strs){\n for(int i=m;i>=zeroes(str);i--){\n for(int j=n;j>=ones(str);j--){\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int maxlength=INT_MIN;\n vector<vector<int>> dp(m+1,vector<int> (n+1,0));\n\n \n for(auto str:strs){\n for(int i=m;i>=zeroes(str);i--){\n for(int j=n;j>=ones(str);j--){\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\nprivate:\n int helper(vector<pair<int, int>>& data, int zeros, int ones, int idx){\n if(idx >= data.size() or (zeros == 0 and ones == 0)){\n return 0;\n }\n if(dp[idx][zeros][ones] != -1) return dp[idx][zeros][ones];\n if(data[idx].first > zeros o... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int sz = strs.size();\n int f[sz + 1][m + 1][n + 1];\n memset(f, 0, sizeof(f));\n for (int i = 1; i <= sz; ++i) {\n auto [a, b] = count(strs[i - 1]);\n for (int j = 0; j ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n // dp[i][m][n] =max(1+dp[i+1][m-m1][n-n1],dp[i+1][m][n]);\n int sz=strs.size();\n vector<pair<int,int>>count(sz);\n for(int i=0;i<sz;i++){\n for(auto ch:strs[i]){\n if(ch==... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int dp[601][101][101];\n\n cout << strs.size() << endl;\n int numZeros[601];\n int numOnes[601];\n\n for(int i = 0; i < strs.size(); i++) {\n int currentOnes = 0;\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int sz=strs.size();\n int dp[sz][m+1][n+1];\n memset(dp,-1,sizeof(dp));\n function<int(int,int,int)> f=[&](int i,int z,int o)->int{\n if(i==sz) return 0;\n if(dp[i][z][o]... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "/*\nIntuition: Similar to knapsack with one additional parameter\ndp[i][j][k] denotes the max length for i ones, j zeros, if we consider first k \nelements of the array\ncurrMax denotes dp[i][j][index_of_currElement]\nWe just have two options:\n1. Take the curr element in subset :\nmax(currMax, dp[i - ones... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int k = strs.size();\n int dp[k + 1][m + 1][n + 1];\n memset(dp, 0, sizeof(dp));\n \n for(int i = 1; i < k + 1; i++) {\n auto count = convert(strs[i - 1]);\n auto zeros =... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int dp[600][101][101];\n pair<int,int>cnt(string &s){\n int cnt0=0,cnt1=0;\n for(int i=0;i<s.size();i++){\n if(s[i]=='0') cnt0++;\n if(s[i]=='1') cnt1++;\n } \n return {cnt0,cnt1};\n }\n\n int solve(int i, int m, int... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int t[101][101][601];\n int solve(vector<string>& strs, int m, int n,int i){\n if(m<0 || n<0) return -1;\n if(i>=strs.size()) return 0;\n if(t[m][n][i]!=-1) return t[m][n][i];\n int take =0,leave=0;\n int ones = 0,zeros = 0;\n for(... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxFormHelper(vector<vector<int>>& freq, int m, int n, int i,int dp[101][101][601]){\n if(m < 0 || n < 0) return INT_MIN+1;\n if(i == freq.size()) return 0;\n if(dp[m][n][i] != -1) return dp[m][n][i];\n int op1 = 1+findMaxFormHelper(freq, ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n // 3 D dp vector, as we dicused, We will give it maximum size,\n //see Constraints, 1 <= strs.length <= 600 and 1 <= m, n <= 100\n int dp[601][101][101]; \n \n // Count one and Zero function take string as parameter and count the number of ones and zeroes present ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n pair<int, int> count(string str){\n int zero = 0;\n int one = 0;\n for(auto i:str){\n if(i=='0') zero++;\n else one++;\n }\n return {zero,one};\n }\n int findMax(vector<string>&str, int l, int m, int n){\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int dp[605][105][105];\n int solve(int ind,vector<string>& strs, int m, int n){\n if(ind>=strs.size()){\n if(m>=0 && n>=0) return 0;\n else return INT_MIN;\n }\n if(m<0 or n<0) return INT_MIN;\n if(dp[ind][m][n]!=-1) return... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int dp[700][101][101];\n vector<string>v;\n int solve(int curr,vector<string>&strs,int m,int n){\n if(curr<0||(m<=0&&n<=0)){\n return 0;\n }\n \n if(dp[curr][m][n]!=0){\n return dp[curr][m][n];\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n map<int, pair<int, int>> mp;\n int dp[610][110][110];\n int len;\n int recur(int i, int m, int n) {\n if (i == len) {\n return 0;\n }\n if (dp[i][m][n] != -1) {\n return dp[i][m][n];\n }\n int onecnt = mp[i].se... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int zero, one;\n\n void count(string s){\n zero = 0, one = 0;\n for(int i = 0; i < s.length(); i++){\n if(s[i] == '0') zero++;\n else one++;\n }\n }\n\n int findMaxForm(vector<string>& strs, int m, int n) {\n int dp[6... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\nint dp[110][110][800];\n int solve(vector<string>& strs, int m, int n,int i)\n {\n if(m<=0 && n<=0)\n return 0;\n if(i==strs.size())\n return 0;\n if(dp[m][n][i]!=-1)\n return dp[m][n][i];\n int a=0;\n int b=0;\n string s=strs[i];\n for(int j=0;j<s... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "#define ll long long int\nclass Solution {\npublic:\n ll dp[605][105][105];\n ll solve(ll indx, vector<string>& s, ll m, ll n, ll N, vector<ll>&one, vector<ll>&zero){\n if(indx==N){\n if(m>=0 && n>=0) return 0;\n return INT_MIN;\n }\n if(m<0 || n<0) return INT_MIN;... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "#define ll long long int\nclass Solution {\npublic:\n ll dp[605][105][105];\n ll solve(ll indx, vector<string>& s, ll m, ll n, ll N, vector<ll>&one, vector<ll>&zero){\n if(indx==N){\n if(m>=0 && n>=0) return 1;\n return INT_MIN;\n }\n if(m<0 || n<0) return INT_MIN;... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\nprivate:\n struct Counts {\n int zeros = 0;\n int ones = 0;\n };\npublic:\n int findMaxForm(const vector<string>& strs, int m, int n) {\n vector<int> cache(strs.size() * (m + 1) * (n + 1), -1);\n\n const auto get_cached = [&cache, m, n](int i, int km, int kn) -> int& {\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\nprivate:\n struct Counts {\n int zeros = 0;\n int ones = 0;\n };\npublic:\n int findMaxForm(const vector<string>& strs, int m, int n) {\n vector<int> cache(strs.size() * (m + 1) * (n + 1), -1);\n\n const auto get_cached = [&cache, m, n](int i, int km, int kn) -> int& {\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\nprivate:\n struct Counts {\n int zeros = 0;\n int ones = 0;\n };\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n vector<Counts> counts;\n counts.reserve(strs.size());\n\n for (const auto& s: strs) {\n counts.push_back({});\n auto& count = cou... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n vector<pair<int, int>> num(strs.size(), std::pair<int, int>(0, 0));\n for(int i = 0; i < strs.size(); ++i) {\n for(char ch: strs[i]) {\n if (ch == '0') {\n ++num... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n\n int back(vector<string> &strs, int m, int n, vector<vector<vector<int>>> &dp, int i) {\n if(i==strs.size()) return 0;\n if(dp[m][n][i]!=-1) return dp[m][n][i];\n int zero = count(strs[i].begin(), strs[i].end(), '0');\n int one = strs[i].size()-ze... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int func(int m, int n, int i,vector<string>&s, vector<vector<vector<int>>> &dp)\n {\n if(i==s.size())return 0;\n if(dp[m][n][i]!=-1)return dp[m][n][i];\n int z=0,o=0;\n for(int j=0;j<s[i].length();j++)s[i][j]=='1'?o++:z++;\n if(z<=m && o<... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int len=strs.size();\n vector<vector<vector<int>>> dp(m+1, vector<vector<int>>(n+1, vector<int>(len, -1)));\n\n auto f=[&](int m,int n,int ind, auto &&f)->int{\n if(ind==len) return 0;\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n // Initialize memoization table with dimensions [m + 1][n + 1][strs.size()], filled with -1\n vector<vector<vector<int>>> memo(m + 1, vector<vector<int>>(n + 1, vector<int>(strs.size(), -1)));\n retu... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int solve(vector<string>&nums,int n,int m,int index,vector<vector<vector<int>>>&dp){\n if(index == nums.size()){\n return 0;\n }\n\n if(dp[n][m][index] != -1){\n return dp[n][m][index];\n }\n\n int zero = 0;\n in... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n vector<vector<vector<int>>> v(m + 1, vector<vector<int>>(n + 1, vector<int>(strs.size(), -1)));\n vector<int> z;\n vector<int> o;\n for (auto& s : strs){\n int oneC = 0, zeroC = 0;\... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int solve(vector<pair<int,int>>& count, int m, int n, int index, vector<vector<vector<int>>>& dp){\n if(index >= count.size()){\n return 0;\n }\n\n if(dp[m][n][index] != -1){\n return dp[m][n][index];\n }\n\n int zeros ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\nprivate:\n vector<vector<vector<int>>> dp;\n int dfs(vector<vector<int>>& count, int m, int n, int from) {\n if (from >= count.size())\n return 0;\n int& r = dp[m][n][from];\n if (r >= 0)\n return r;\n \n int temp = dfs(count,... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n\n int util (vector<pair<short, short>> &nums, int m, int n, int idx, vector <vector<vector<int>>> &dp) {\n if (idx == nums.size()) return 0;\n if (m <= 0 && n <= 0) return 0;\n\n if (dp [m][n][idx] != -1) return dp [m][n][idx];\n\n int s1 = 0;\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\nprivate:\n int solve(vector<pair<int,int>>&nums, int num0, int num1, int index, vector<vector<vector<int>>> &dp) {\n if(index == nums.size() || (num0 == 0 && num1 == 0)) {\n return 0;\n }\n\n if(dp[num0][num1][index] != -1) {\n return dp[num0]... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n // what choices do you have and what is your capacity defines the problem.\n // dp[n][n][i] = max(dp[m][m][i+1] + dp[m-zeroes][n-ones][i+1])\n // count ones and zeroes in a string in cpp\n // ve... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int helper(vector<string>& strs, int m, int n,int ind,vector<vector<vector<int>>>&dp){\n if(ind==strs.size()){\n return 0;\n }\n if(dp[m][n][ind]!=-1){\n return dp[m][n][ind];\n }\n int cntZeros=count(strs[ind].begin(),... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 1 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int len = strs.size();\n vector<pair<int,int>> vii(len, {0,0}); // { zeros_count, ones_count }\n vector<vector<vector<int>>> memo(m+1, vector<vector<int>> (n+1,vector<int> (len+1,-1) ));\n\n f... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 2 | {
"code": "class Solution {\npublic:\n int count(int i,char val,vector<string>& strs){\n int count = 0;\n\n for(int j = 0;j<strs[i].size();j++){\n if (strs[i][j]==val){\n count++;\n }\n }\n return count;\n }\n \n int rec(int i,int one,int ze... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 2 | {
"code": "class Solution {\npublic:\n int solve(vector<pair<int,int>>& v,int m,int n,int ind,int c1,int c0,vector<vector<vector<int>>>& dp){\n if(ind>=v.size()){\n if(c1<=n && c0<=m){return 0;}\n return -1e9;\n }\n if(c1>n || c0>m){return -1e9;}\n if(dp[ind][c1][c... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 2 | {
"code": "class Solution {\npublic:\n vector<vector<vector<int>>> dp;\n int help(vector<pair<int, int>>& a, int i, int one, int zero, int m,\n int n) {\n if (one > n || zero > m)\n return INT_MIN;\n if (i == a.size())\n return 0;\n\n if (dp[i][one][zero] !... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 2 | {
"code": "class Solution {\npublic:\n int cnt1(string &str)\n {\n int cnt=0;\n for(auto i:str)\n {\n if(i=='1')\n cnt++;\n }\n return cnt;\n }\nint solve(vector<string>&strs,int m,int n,int index, vector<vector<vector<int>>>&dp)\n {\n if(index==strs.size())\n return 0;\... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 2 | {
"code": "class Solution {\npublic:\n pair<int , int> count(string str){\n int cnt0 = 0 , cnt1 = 0;\n for(int i = 0 ; i < str.size() ; i++){\n if(str[i] == '0'){\n cnt0++;\n }else if(str[i] == '1'){\n cnt1++;\n }\n }\n retu... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 2 | {
"code": "class Solution {\npublic:\n int f(vector<vector<vector<int>>> &dp, vector<string>& strs, vector<int> &countOne, int m, int n, int zeroCount, int oneCount, int index){\n if(index < 0) return 0;\n if(zeroCount>m || oneCount>n) return 0;\n if(dp[index][zeroCount][oneCount]!=-1) return ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n pair<int , int> count(string str){\n int cnt0 = 0 , cnt1 = 0;\n for(int i = 0 ; i < str.size() ; i++){\n if(str[i] == '0'){\n cnt0++;\n }else if(str[i] == '1'){\n cnt1++;\n }\n }\n retu... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int si = 0;\n int cnt0(string s) {\n int cnt = 0;\n for (auto it : s) {\n if (it == '0')\n cnt++;\n }\n return cnt;\n }\n int helper(vector<string>& strs, int i, int m, int n,vector<vector<vector<int>>>&dp) {\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n int i = 0;\n vector<vector<vector<int>>> dp(\n strs.size() + 1, vector<vector<int>>(m + 1, vector<int>(n + 1, 0)));\n\n vector<vector<int>>curr(m + 1, vector<int>(n + 1, 0));\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int count_zeroes(string s){\n int count =0;\n for(int i=0;i<s.size();i++){\n if(s[i]=='0'){\n count=count+1;\n }\n }\n return count;\n }\n int count_ones(string s){\n int count =0;\n for(int ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\nprivate:\nint dp[602][200][200];\nint solve(int index , unordered_map<int,pair<int,int>> &map ,int ones , int zeros, int m , int n , int size){\n if(zeros>m || ones>n){\n return INT_MIN;\n }\n if(index==size){\n return 0;\n }\n if(dp[index][ones][zeros] !=-1){... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\nprivate:\nint dp[602][200][200];\nint solve(int index , unordered_map<int,pair<int,int>> &map ,int ones , int zeros, int m , int n , int size){\n if(zeros>m || ones>n){\n return INT_MIN;\n }\n if(index==-1 ){\n return 0;\n }\n if(dp[index][ones][zeros] !=-1){\... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\nvector<string> strs;\n\nint memo[601][202][202];\n int cnt(string& s) {\n int res = 0;\n for(int i = 0; i < s.size(); i++) {\n res += s[i] == '1';\n }\n return res;\n }\n int sol(int i, int m, int n) {\n if(i == strs.size() o... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\nvector<string> strs;\n\nint memo[601][202][202];\n int cnt(string& s) {\n int res = 0;\n for(int i = 0; i < s.size(); i++) {\n res += s[i] == '1';\n }\n return res;\n }\n int sol(int i, int m, int n) {\n if(i == strs.size() o... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n vector<vector<short>> cache(strs.size(), vector<short>(10101, -1)); \n\n return findMaxForm(0, strs, cache, m, n);\n }\nprivate:\n short findMaxForm(int current, vector<string>& strs, vector<ve... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int m, int n) {\n vector<vector<short>> cache(strs.size(), vector<short>(10101, -1)); \n\n return findMaxForm(0, strs, cache, m, n);\n }\nprivate:\n short findMaxForm(int current, vector<string>& strs, vector<ve... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n void count(vector<string>& strs,vector<pair<int,int>>& pq,int i){\n if(i>=strs.size()){\n return ;\n }\n string s=strs[i];\n int zeroes=0;\n int ones=0;\n for(int j=0;j<s.length();j++){\n if(s[j]=='0'){\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int maxOne, maxZero;\n int dp[601][101][101];\n\n pair<int, int> findFreq(string& s){\n pair<int, int> p = {0, 0};\n\n for(auto it : s){\n if(it == '0') p.first++;\n else p.second++;\n }\n\n return p;\n }\n\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<pair<int,int>> &zeroOnes,int m ,int n,int i){\n\n if(i >= zeroOnes.size())\n return 0 ;\n\n int include = 0 ;\n int currZero = zeroOnes[i].first ;\n int currOne = zeroOnes[i].second ;\n if(currZero <= m && currO... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n \n\n int solveTab(vector<pair<int,int>> &zeroOnes,int m ,int n){\n vector<vector<vector<int>>> dp(m+1,vector<vector<int>>(n+1,vector<int>(zeroOnes.size()+1,0)));\n\n for(int i=0; i<=m; i++){\n for(int j=0; j<=n; j++){\n for(int index... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int dp[601][101][101]; \n int sub(vector<string>& strs, int n, int m, int idx){\n if( idx >= strs.size()) return 0;\n if (dp[idx][n][m] != -1) return dp[idx][n][m];\n vector<int> cnt = count(strs[idx]);\n\n int take = 0;\n if(n - cnt[0] >... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<vector<long>>> memo;\n int m, n;\n vector<string> strs;\n \n int findMaxForm(vector<string>& strs, int m, int n) {\n this->m = m;\n this->n = n; \n this->strs = strs;\n memo = vector<vector<vector<long>>>(strs.size(), vect... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<vector<long>>> memo;\n int m, n;\n vector<string> strs;\n \n int findMaxForm(vector<string>& strs, int m, int n) {\n this->m = m;\n this->n = n; \n this->strs = strs;\n memo = vector<vector<vector<long>>>(strs.size(), vect... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n \n \n int t[101][101][601];\n\n\n vector<int> countZeroOne(string str){\n \n \n\n vector<int>count(2);\n for(char c : str){\n\n count[c-'0']++;\n\n }\n\n return count;\n\n\n }\n \n int help... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic: \n\n void convertStrsToNums(vector<string>& strs , vector<pair<int , int> > &nums){\n for(auto str : strs){\n int zeros = 0;\n int ones = 0;\n\n for(auto s : str){\n if(s == '0') zeros++;\n else ones++;\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int recursive(vector<string>& strs, int m, int n,int idx){\n if(idx >= strs.size()){\n return 0;\n }\n\n string s = strs[idx];\n\n int zeros = count(s.begin(),s.end(),'0');\n int ones = s.length() - zeros;\n\n int include =... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int recursive(vector<string>& strs, int m, int n,int idx){\n if(idx >= strs.size()){\n return 0;\n }\n\n string s = strs[idx];\n\n int zeros = count(s.begin(),s.end(),'0');\n int ones = s.length() - zeros;\n\n int include =... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\n int size, base = 601, mod = 1e9+7;\n unordered_map<int, pair<int, int>> map;\n unordered_map<int, int> dp;\n\n int calculateHash(int idx, int m, int n) {\n return (1LL*idx*base*base+m*base+n)%mod; \n }\n\n int solve(int idx, int m, int n) {\n if (m < 0 ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int findMaxForm(vector<string>& strs, int zeros, int ones) {\n int n = strs.size();\n vector<pair<int,int>> counts;\n vector<vector<vector<int>>> dp(n);\n for(int i=0; i<n; i++){\n vector<vector<int>> state(zeros+1, vector<int>(ones+1));... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n vector <pair<int,int>> arr;\n vector <vector <vector <int>>> dp;\n\n pair<int,int> f(string temp){\n\n int zero=0;\n int one=0;\n\n for(char c:temp){\n if(c=='0')\n zero++;\n else\n one++;\n }\n\n ... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n vector<string> strs;\n vector<int> count1;\n vector<int> count0;\n vector<vector<vector<int>>> dp;\n int dfs(int index, int zero, int one) {\n // end\n if (zero == 0 && one == 0)return 0;\n if (index >= strs.size() || one < 0 || zero < 0)return 0;... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<string>& strs, int zero, int one, int i, vector<vector<vector<int>>> &dp){\n if(i>=strs.size() || zero+one==0){\n return 0;\n }\n\n if(dp[i][zero][one] != -1){\n return dp[i][zero][one];\n }\n\n// Count the number of zer... |
474 | <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p>
<p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong> </em><code>m</code><em> </em><code>0</code><em>'s and </em><code>n</code><em> </em><co... | 3 | {
"code": "class Solution {\npublic:\n int solve(vector<string>& strs, int m, int n, int i,vector<pair<int,int>> &count,vector<vector<vector<int>>> &dp){\n if(m < 0 || n < 0){\n return INT_MIN;\n }\n if(i == strs.size() ||(n == 0 && m == 0)){\n return 0;\n }\n ... |
477 | <p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
<p>Given an integer array <code>nums</code>, return <em>the sum of <strong>Hamming distances</strong> between all the p... | 0 | {
"code": "class Solution {\npublic:\n int totalHammingDistance(vector<int>& nums) {\n int total = 0;\n int n = nums.size();\n for (int i = 0; i < 32; ++i) {\n int countOnes = 0;\n for (int num : nums) {\n if (num & (1 << i)) {\n ++countO... |
477 | <p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
<p>Given an integer array <code>nums</code>, return <em>the sum of <strong>Hamming distances</strong> between all the p... | 0 | {
"code": "class Solution {\npublic:\n \n int totalHammingDistance(vector<int>& nums) {\n int size=nums.size();\n if(size<2) return 0;\n int ans=0;\n int* zerone=new int[2];\n while(true){\n int zerocount=0;\n zerone[0]=0;\n zerone[1]=0;\n ... |
477 | <p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
<p>Given an integer array <code>nums</code>, return <em>the sum of <strong>Hamming distances</strong> between all the p... | 0 | {
"code": "class Solution {\npublic:\n int totalHammingDistance(vector<int>& nums) {\n int total = 0;\n int n = nums.size();\n for (int i = 0; i < 32; ++i) {\n int countOnes = 0;\n for (int num : nums) {\n if (num & (1 << i)) {\n ++countO... |
477 | <p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
<p>Given an integer array <code>nums</code>, return <em>the sum of <strong>Hamming distances</strong> between all the p... | 0 | {
"code": "class Solution {\npublic:\n int totalHammingDistance(vector<int>& nums) {\n int t=0;\n int n=nums.size();\n\n for(int i=31;i>=0;i--)\n {\n int a=0;\n\n for(int j : nums)\n if(1&(j >> i))\n a++;\n \n t+=a*(n-a);... |
477 | <p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
<p>Given an integer array <code>nums</code>, return <em>the sum of <strong>Hamming distances</strong> between all the p... | 1 | {
"code": "class Solution {\npublic:\n int totalHammingDistance(vector<int>& nums) {\n int n = nums.size();\n long long totalSum = 0;\n \n // Iterate over each bit position from 0 to 31\n for (int bit = 0; bit < 32; ++bit) {\n int countOnes = 0;\n \n ... |
477 | <p>The <a href="https://en.wikipedia.org/wiki/Hamming_distance" target="_blank">Hamming distance</a> between two integers is the number of positions at which the corresponding bits are different.</p>
<p>Given an integer array <code>nums</code>, return <em>the sum of <strong>Hamming distances</strong> between all the p... | 1 | {
"code": "class Solution {\n public:\n int totalHammingDistance(vector<int>& nums) {\n constexpr int kMaxMask = 1 << 30;\n int ans = 0;\n\n for (int mask = 1; mask < kMaxMask; mask <<= 1) {\n const int ones =\n ranges::count_if(nums, [mask](int num) { return num & mask; });\n const int z... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "class Solution {\npublic:\n bool isSubPath(ListNode* head, TreeNode* root, bool in_start = true) {\n if(head->val == root->val){\n if(head->next == nullptr) return true;\n\n if(root->left && isSubPath(head->next, root->left, false)) return true;\n if(root->right &... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 0 | {
"code": "class Solution {\n public:\n bool isSubPath(ListNode* head, TreeNode* root) {\n if (root == nullptr)\n return false;\n return isContinuousSubPath(head, root) || isSubPath(head, root->left) ||\n isSubPath(head, root->right);\n }\n\n private:\n bool isContinuousSubPath(ListNode* head,... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 1 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 2 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "class Solution {\n bool traverseTree(std::vector<int> &kmpPrefix, std::vector<int> &listNums, TreeNode *node, int curIndex = 0) {\n if(curIndex == listNums.size()) return true;\n if(node) {\n // std::cout<<node->val<<\", \"<<listNums[curIndex]<<\", \"<<curIndex<<std::endl;\n ... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
1,484 | <p>Given a binary tree <code>root</code> and a linked list with <code>head</code> as the first node. </p>
<p>Return True if all the elements in the linked list starting from the <code>head</code> correspond to some <em>downward path</em> connected in the binary tree otherwise return False.</p>... | 3 | {
"code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n/**\n * Definition for a bi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.