id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string answer = \"\";\n\n bool generate_binary_string(unordered_set<string> nums, string& s, int i) {\n if (i >= s.size()) {\n if (nums.find(s) == nums.end()) {\n answer = s;\n return true;\n }\n return ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class TrieNode {\npublic:\n unordered_map<char, TrieNode*> next;\n\n ~TrieNode() {\n for (auto& [key, node] : next) delete(node);\n }\n};\n\nclass Trie {\npublic:\n Trie() {\n root = new TrieNode();\n }\n\n void insert(string s) {\n TrieNode* node = root;\n for... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(int n,string temp,string &s,unordered_map<string,int> mp){\n if(temp.size()==n){\n if(mp.find(temp)==mp.end()) s = temp;\n return;\n }\n if(!s.empty()) return;\n solve(n,temp+\"0\",s,mp);\n solve(n,temp+\"1\"... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(int n,string temp,string &s,unordered_map<string,int> mp){\n if(temp.size()==n){\n if(mp.find(temp)==mp.end()) s = temp;\n return;\n }\n if(!s.empty()) return;\n solve(n,temp+\"0\",s,mp);\n solve(n,temp+\"1\"... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string findDifferentBinaryString(vector<string>& nums) {\n vector<int> ok;\n string ans;\n for (string i : nums)\n ok.push_back(stoi(i, 0, 2));\n for (int i = 0; i <= (1 << nums.size()) - 1; i++) {\n if (find(ok.begin(), ok.en... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string fin = \"\";\n\n void func(int n, int c, set<string> &ans, vector<char> &sen) {\n if(c == n) {\n string s(sen.begin(), sen.end()); \n if(ans.find(s) == ans.end())\n fin = s; \n return;\n }\n\n sen[c... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string fin = \"\";\n\n void func(int n, int c, set<string> &ans, vector<char> &sen) {\n if(c == n) {\n string s(sen.begin(), sen.end()); \n if(ans.find(s) == ans.end()) {\n fin = s; // Assign the string to fin if it's not found ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string solve(set<string>&st,int n,string &bin){\n if(bin.size()==n){\n if(st.find(bin)==st.end())\n {\n return bin;\n }\n else{\n return \"\";\n }\n }\n bin+=\"1\";\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n set<string> s;\n string findDifferentBinaryString(vector<string>& nums) {\n for(string i:nums) s.insert(i);\n return dfs(0,nums[0].size(),\"\");\n }\n string dfs(int i,int n,string cur){\n if(i==n){\n if(s.count(cur)) return \"\";... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(string s,int i,int n,vector<string>&nums,string &ans){\n if(i==n){\n if(find(nums.begin(),nums.end(),s)==nums.end())ans= s;\n return ;\n }\n solve(s+'0',i+1,n,nums,ans);\n solve(s+'1',i+1,n,nums,ans);\n\n }\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(string &ans , unordered_set<string>&st , string res , int n){\n if(res.size()==n){\n if(!st.count(res)){\n ans = res ;\n return ; \n }\n return ;\n }\n\n solve(ans , st , res+\"0\" ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string findUniqueString(unordered_map<string, bool> &hmap, int n, string crSt){\n if(n==0) {\n if(hmap.find(crSt)==hmap.end()){\n return crSt;\n }\n else {\n return \"\";\n }\n }\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string ans=\"\";\n void solve(string temp, set<string> &chk, int n){\n //bc\n if(temp.size()==n){\n if(chk.find(temp)==chk.end()){\n ans=temp;\n }\n return;\n }\n //cd\n solve(temp+'0', chk,... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n bool rec(int i, string s, set<string> &sett, string &ans)\n {\n if(i == sett.size())\n {\n if(sett.find(s) == sett.end())\n {\n ans = s;\n return true;\n }\n return false;\n }\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string temp=\"\";\n\n void helper(int cb,int tb,string str,unordered_map<string,int>&map)\n {\n if(cb==tb)\n {\n if(!map.count(str))\n {\n temp=str;\n \n }\n return;\n }\n\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n unordered_set<string> st;\n string ans = \"\";\n\n void solve(int ind, int n, string s, vector<string>& nums) {\n\n if (n == ind) {\n if (st.find(s) == st.end()) \n ans = s;\n return;\n }\n\n solve(ind + 1, n, s ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<string,bool> m;\n string ans=\"\";\n int n;\n void solve(int i,string s){\n if(i==n){\n if(m.find(s)==m.end()){\n ans=s;\n }\n return;\n }\n solve(i+1,s+'0');\n solve(i+1,s+'1')... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\nset<string> se;\nstring ans;\n string findDifferentBinaryString(vector<string>& nums) {\n for(int i=0;i<nums.size();i++) {\n se.insert(nums[i]);\n }\n helper(0,\"\",nums.size());\n return ans;\n }\n void helper(int index,string temp... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\n int n;\n unordered_map<string, int> mp;\n string sol;\n void backtrack(string bin){\n if(bin.length() == n){\n if(mp.count(bin) > 0) return;\n else{\n sol = bin;\n return;\n }\n }\n backtrack(... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n int deci(string &str){\n int j = 0, n = 0;\n for(int i=str.length()-1; i>=0; i--){\n n += (str[i]-'0') * (1<<j);\n j++;\n }\n return n;\n }\n string bin(int n){\n string str = \"\";\n while(n > 0){\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n int deci(string &str){\n int j = 0, n = 0;\n for(int i=str.length()-1; i>=0; i--){\n n += (str[i]-'0') * (1<<j);\n j++;\n }\n return n;\n }\n string bin(int n){\n string str = \"\";\n while(n > 0){\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string findDifferentBinaryString(vector<string>& a) {\n vector<int >x;\n int n=a[0].length();\n unordered_map<int,int> m;\n for(int i=0;i<pow(2,a[0].length());i++){\n m[i]++;\n }\n for(auto i:a){\n int j= stoi(i,... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void uniqStr(string str, int sz, set<string>& st, string& ans){\n if(str.size()==sz){\n if(!st.count(str)) ans=str;\n return;\n }\n str.push_back('0');\n uniqStr(str, sz, st, ans);\n str.pop_back();\n str.push_ba... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(int idx,int n,string curr,unordered_set<string>& set,string& ans){\n if(idx==n){\n if(set.find(curr)==set.end()){\n ans=curr;\n }\n return;\n }\n curr.push_back('0');\n solve(idx+1,n,curr,s... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\n void solve(string& ans, string temp, int n, set<string>& st) {\n if (temp.length() == n) {\n if (st.find(temp) == st.end()) {\n ans = temp;\n }\n return;\n }\n string org= temp;\n temp+= \"0\";\n solve(... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string ans=\"\";\n set<string>st;\n string solve(int i,string s, int n){\n if(i==n){\n if(st.find(s)==st.end())\n return s;\n else return \"\";\n }\n s+='1';\n string a=solve(i+1, s, n);\n s.pop_back();\n s+='0';\n string b=solve(i... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n set<string> st;\n string ans = \"\";\n string rec(int sz,string s,int total){\n if(sz == total){\n if(st.find(s) == st.end()){\n return s;\n }\n else{\n return \"\";\n }\n }\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\n string res;\n string curr;\n unordered_map<string, int> m;\n \npublic:\n string findDifferentBinaryString(vector<string>& nums) {\n int n = nums.size();\n string curr = \"\";\n\n for(int i=0; i<nums.size(); i++){\n m[nums[i]] = 1;\n }... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\n string res;\n string curr;\n unordered_map<string, int> m;\n \npublic:\n string findDifferentBinaryString(vector<string>& nums) {\n int n = nums.size();\n string curr = \"\";\n\n for(int i=0; i<nums.size(); i++){\n m[nums[i]] = 1;\n }... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\n string res;\n string curr;\n unordered_map<string, int> m;\n \npublic:\n string findDifferentBinaryString(vector<string>& nums) {\n int n = nums.size();\n string curr = \"\";\n\n for(int i=0; i<nums.size(); i++){\n m[nums[i]] = 1;\n }... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "vector<string> tmp;\nchar a[20];\nclass Solution {\npublic:\n void Try(int i, int n){\n for(int j = 0; j <= 1; j++){\n a[i] = j + '0';\n if ( i == n - 1){ \n string ret;\n for(int t = 0; t < n; t++) ret += a[t];\n tmp.push_back(re... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void f(int ind, string temp, set<string> &st, string &ans){\n if(ind==temp.size()){\n if(st.find(temp)==st.end()) ans=temp;\n return ;\n }\n temp[ind]='0';\n f(ind+1,temp,st,ans);\n temp[ind]='1';\n f(ind+1,temp,... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(string s, unordered_map<string,int> &mp, int i, string &ans){\n if(i>=s.length()){\n return;\n }\n if(mp.find(s)==mp.end()){\n ans=s;\n }\n solve(s,mp,i+1,ans);\n\n if(s[i]=='0'){\n s[i]='1'... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<string>& nums,string s,int i,int n,string &ans){\n if(i>=n){\n auto it=find(nums.begin(),nums.end(),s);\n if(it==nums.end() ){\n ans=s;\n \n }\n return ;\n }\n \n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void generateAllStrings(vector<string> &v,int n,int i,string &s){\n if(i==n){\n v.push_back(s);\n return;\n }\n s.push_back('0');\n generateAllStrings(v,n,i+1,s);\n s.pop_back();\n s.push_back('1');\n gene... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void helper(int index, int n,string &temp,vector<string> &ans){\n if(index==n){\n ans.push_back(temp);\n return;\n }\n temp.push_back('1');\n helper(index+1,n,temp,ans);\n temp.pop_back();\n temp.push_back('0');\... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void generate(int i, string &str1, vector<string> &ans, int n) {\n if (i == n) {\n ans.push_back(str1);\n return;\n }\n str1.push_back('0');\n generate(i + 1, str1, ans, n);\n str1.pop_back();\n str1.push_back('1... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void fun(int ind,int n,string&ans,vector<string>&ve){\n if(ind==n){\n ve.push_back(ans);\n return;\n }\n fun(ind+1,n,ans,ve);\n ans[ind]='1';\n fun(ind+1,n,ans,ve);\n ans[ind]='0';\n }\n string findDifferen... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\nvector<string> ans;\nset<string> st;\nvoid Helper(int n,int i,string& s){\n if(i==n){\n if(st.find(s)==st.end())ans.push_back(s);\n return;\n }\n s+='0';\n Helper(n,i+1,s);\n s.pop_back();\n s+='1';\n Helper(n,i+1,s);\n s.pop_back();\n}\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n\n int len;\n bool flag = false;\n string res;\n public:\n\n void helper( string val , vector<int> Hash){\n if(flag)\n return;\n\n if(val.length()==len){\n int num = std::stoi(val , nullptr, 2);\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string findDifferentBinaryString(vector<string>& nums) {\n unordered_set<string> seen(nums.begin(), nums.end()); // Use a set for efficient checking\n queue<string> q;\n q.push(\"0\");\n q.push(\"1\");\n int n = nums[0].size();\n\n wh... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string findDifferentBinaryString(vector<string>& nums) {\n queue <string> q;\n set <string> se(nums.begin(), nums.end());\n q.push(\"0\");\n q.push(\"1\");\n int n = nums[0].size();\n while (!q.empty()) {\n string top = q.f... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\nunordered_set<string> set;\n string helper(int i, int n,string str){\n\n if(i == n) {\n return !set.count(str) ? str :\"\";\n }\n \n str.push_back('0');\n string a = helper(i+1,n,str);\n // if(!a.empty()) return a;\n ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "#include <vector>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n void solve(vector<int>& v, int index, vector<vector<int>>& ans, vector<string>& nums) {\n if (index == nums[0].size()) {\n ans.push_back(v);\n return;\n }\n v[index] = 1;\... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n\n vector<string> rec(int level)\n {\n vector<string> ans;\n if(level==1)\n {\n ans.push_back(\"0\");\n ans.push_back(\"1\");\n return ans;\n }\n vector<string> prev=rec(level-1);\n for(int i=0;i<pre... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n string findDifferentBinaryString(vector<string>& nums) {\n vector<string>allPos; \n set<string>st; \n for(auto it: nums) \n st.insert(it); \n\n int n = nums[0].size(); \n\n for(int i=0;i<(1<<n);i++)\n {\n string s; \... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n\n string solve(unordered_map<string, bool>&present, char current, int n , string &ans){\n if(ans.length()==n){\n // cout<<\"init\"<<ans<<endl;\n if(present[ans]==false) return ans;\n return \"\";\n }\n ans.push_back(curren... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\nprivate:\n \npublic:\n\n\n string findDifferentBinaryString(vector<string>& nums) {\n auto num_bits = nums.front().length();\n \n \n std::vector<std::string> poss;\n size_t maxn = pow(2, num_bits) ;\n maxn = std::max(maxn, (size_t)1);\n // cout... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\nprivate:\n \npublic:\n\n\n string findDifferentBinaryString(vector<string>& nums) {\n auto num_bits = nums.front().length();\n \n \n std::vector<std::string> poss;\n size_t maxn = pow(2, num_bits) ;\n const std::string cmask = \"00000000000000000000\... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\nprivate:\n \npublic:\n\n\n string findDifferentBinaryString(vector<string>& nums) {\n auto num_bits = nums.front().length();\n \n\n \n std::vector<std::string> poss;\n size_t maxn = pow(2, num_bits) ;\n const std::string cmask = \"0000000000000000000... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void createBinaryUsingNumber(int n,vector<string> &s){\n int maxNumber=1<<n;\n for(int i=0;i<maxNumber;i++){\n bitset<32> binary(i);\n string str=binary.to_string();\n s.push_back(str.substr(32-n));\n }\n }\n string ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void createPermutations(string s, int &n, vector<string> &allStrings) {\n if (s.size() == n) {\n allStrings.push_back(s);\n return ;\n }\n \n createPermutations(s + '1', n, allStrings);\n createPermutations(s + '0', n, ... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void tn(vector<string> &arr,string s,int n){\n if (s.size()==n){\n arr.push_back(s);\n return;\n }\n tn(arr,s+\"0\",n);\n tn(arr,s+\"1\",n);\n\n\n \n\n }\n string findDifferentBinaryString(vector<string>& nums) {\... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n vector<string> need;\n\n void backtrack(int n, vector<string>& nums, vector<string>& need, string s) {\n if (s.length() == n) {\n need.push_back(s);\n return;\n }\n\n \n backtrack(n, nums, need, s + '0');\n backtrack... |
2,107 | <p>Given an array of strings <code>nums</code> containing <code>n</code> <strong>unique</strong> binary strings each of length <code>n</code>, return <em>a binary string of length </em><code>n</code><em> that <strong>does not appear</strong> in </em><code>nums</code><em>. If there are multiple answers, you may return <... | 3 | {
"code": "class Solution {\npublic:\n void solve(int n,vector<string>&ans,string s){\n if(n==0){\n ans.push_back(s);\n return;\n }\n if(s.empty()){\n solve(n-1,ans,s+'0');\n solve(n-1,ans,s+'1');\n }\n else{\n solve(n-1,ans,... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 0 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n string ans=\"\";\n int i=0;\n int j=0;\n int l1=word1.length();\n int l2=word2.length();\n while(i<l1&&j<l2){\n if(ans.length()%2==0){\n ans+=word1[i];\... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 0 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n \n int pointerOne = 0, pointerTwo = 0;\n\n while(word2.size() > pointerTwo){\n pointerOne++; // Increment pointerOne by 1 before the insertion\n if(pointerOne <= word1.size()){\n wor... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 0 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int i1 = 0;\n int i2 = 0;\n string merged = \"\";\n bool w1 = true;\n\n while(i1 < word1.size() && i2 < word2.size()){\n if(w1){\n merged.push_back(word1[i1]);... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 0 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int i1 = 0;\n int i2 = 0;\n string merged = \"\";\n\n while(i1 < word1.size() || i2 < word2.size()){\n if(i1 < word1.size()){\n merged.push_back(word1[i1]);\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 2 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n \n bool flag = false;\n string res = \"\";\n\n int idx1 = 0;\n int idx2 = 0;\n\n while(idx1 < word1.size() || idx2 < word2.size()){\n if(idx2 >=word2.size()){\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 2 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n string ans=\"\";\n int i=0,n=word1.size(),m=word2.size();\n while(i<max(n,m)){\n if(i<n)ans+=word1[i];\n if(i<m)ans+=word2[i];\n i++;\n }\n return ans;\... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n char merged[400];\n int i = 0, j=0;\n if(word1.size() == word2.size()){\n while(word1[i] != '\\0'){\n merged[j++] = word1[i];\n merged[j++] = word2[i];\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n const int n = min(word1.length(), word2.length());\n string prefix;\n for (int i = 0; i < n; ++i) {\n prefix += word1[i];\n prefix += word2[i];\n }\n return prefix + word1.substr(n) + word2.subst... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n const int n = min(word1.length(), word2.length());\n string prefix;\n for(int i=0;i<n;i++){\n prefix +=word1[i];\n prefix +=word2[i];\n }\n return prefix + word1.s... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n const int n = min(word1.length(), word2.length());\n string prefix;\n for(int i=0;i<n;i++){\n prefix +=word1[i];\n prefix +=word2[i];\n }\n return prefix + word1.s... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int i=0, j=0;\n string ans;\n while(i < word1.length() && j < word2.length()){\n ans += word1.substr(i++, 1) + word2.substr(j++, 1);\n }\n while(i < word1.length()){\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int shortLength;\n string result;\n\n if (word1.length() < word2.length()) {\n shortLength = word1.length();\n }\n else {\n shortLength = word2.length();\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n string result(\"\");\n int i =0;\n while(i < word1.length() | i < word2.length())\n {\n if (i < word1.length())\n {\n result += word1.substr(i,1);\n }\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n // string in C++ takes heap allocation. Attaching a letter takes amortized O(1) or O(n)\n std::list<char> lst;\n\n // std::string::iterator, not a pointer\n auto it1 = word1.begin(); \n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n string result = string();\n while ((word1.size() > 0) && (word2.size() > 0)) {\n result += word1[0];\n result += word2[0];\n word1 = word1.substr(1);\n word2 = wo... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int i = 0;\n int j = 0;\n string ret = \"\";\n while(i < word1.size() || j < word2.size()){\n ret += word1.substr(i, 1);\n ret += word2.substr(j, 1);\n if(i < ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n \n int num = word1.size() + word2.size();\n\n string ans=\"\";\n \nwhile(num != 0)\n{\n ans = ans + word1[0];\n ans = ans + word2[0];\n \nnum --;\nword1.erase(0,1);\nword2.erase(0,1);\n\nif(word1.size() == 0)\... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n \n int num = word1.size() + word2.size();\n\n string ans=\"\";\n \nwhile(num != 0)\n{\n ans = ans + word1[0];\n ans = ans + word2[0];\n \nnum --;\nword1.erase(0,1);\nword2.erase(0,1);\n\nif(word1.size() == 0)\... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n string ans;\n int n=word1.length();\n int m=word2.length();\n int i;\n for(i=0;i<min(n,m);i++)\n {\n ans=ans+word1[i];\n ans=ans+word2[i];\n }\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2)\n {\n string ans;\n int n=word1.length();\n int m=word2.length();\n int i;\n for(i=0;i<min(n,m);i++)\n {\n ans=ans + word1[i];\n ans=ans + word2[i];\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n \n int is = 0;\n int ie = word1.length();\n\n int js = 0;\n int je = word2.length();\n\n string str;\n while(word1[is] != '\\0' && word2[js] != '\\0')\n {\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n\n int n=word1.size();\n int m=word2.size();\n int i=0;\n int j=0;\n string res=\"\";\n while(i<n && j<m){\n res=res+word1[i];\n i++;\n res+=word... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int i=0, word1Size = word1.length(), word2Size = word2.length();\n string result=\"\";\n while (i < min(word1Size, word2Size)) {\n result = result + word1[i] + word2[i];\n i++;\... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int i = 0, j = 0;\n\n string mergedResult = \"\";\n while(i < word1.length() && j < word2.length()) {\n mergedResult = mergedResult + word1[i] + word2[j];\n i++;\n j+... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n int i=0,j=0;\n int s1=word1.length();\n int s2=word2.length();\n string merge;\n while(i<s1||j<s2){\n if(i<s1){\n merge=merge+word1[i++];\n }\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2){\n string word;\n for(int i=0; i<word1.length()||i<word2.length();i++)\n {\n if(i<word1.length())\n word = word + word1[i];\n if(i<word2.length())\n word = word + word2[i];\n }return w... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2) {\n string ans=\"\";\n int i=0;\n int j=0;\n int k=0;\n int n=word1.size();\n int m=word2.size();\n while(i<n && j<m){\n if(k%2) ans = ans+word2[j++];\n ... |
1,894 | <p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters onto the end of the merged string.</p>
<p>Return <em>the merged string.</em></p>
<... | 3 | {
"code": "class Solution {\npublic:\n string mergeAlternately(string word1, string word2){\n string word;\n for(int i=0; i<word1.length()||i<word2.length();i++)\n {\n if(i<word1.length())\n {\n word = word + word1[i];\n }\n if(i<word2.length())\n {\n ... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int l=0;\n int r=nums.size()-1;\n int n=nums.size();\n int ans;\n if(n==1)return 0;\n else if(nums.size()>=2 && nums[0]>INT_MIN && nums[0]>nums[1])return 0;\n else if(nums.size()>=2 &... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int l=0;\n int r=nums.size()-1;\n int n=nums.size();\n int ans;\n if(n==1)return 0;\n else if(nums.size()>=2 && nums[0]>INT_MIN && nums[0]>nums[1])return 0;\n else if(nums.size()>=2 &... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int l = 0, r = nums.size() - 1;\n\n if (nums.size() == 1) return 0;\n if (nums[0] > nums[1]) return 0;\n if (nums[r] > nums[r - 1]) return r;\n\n while (l < r) {\n int mid = l + (r - l) /... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int i=0;\n int j=nums.size()-1;\n if (nums.size()==1){\n return 0;\n }\n if (nums.size()==2){\n return nums[0]>nums[1] ? 0:1;\n }\n while (i<j){\n int m... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int low = 1;\n int high = nums.size()-2;\n int n = nums.size();\n if (n==1) return 0;\n if (nums[0]>nums[1]) return 0;\n if (nums[n-1]>nums[n-2]) return n-1;\n while(low<=high){\n ... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int left = 0;\n int right = nums.size() - 1;\n \n while (left <= right) {\n int mid = left + (right - left) / 2;\n \n \n bool isLeftGreater = (mid > 0) && (nums[m... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int n = nums.size();\n for(int i = 0; i < n - 1; i++) {\n if(nums[i] > nums[i + 1]) {\n return i;\n }\n }\n return n - 1; \n }\n};\n// Time Complexity = O(N)\... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int n=nums.size();\n int low=1;\n int high=n-2;\n if (n==1){\n return 0;\n }\n if (nums[0]>nums[1]){\n return 0;\n }\n if (nums[n-1]>nums[n-2]){\n ... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int sz = nums.size();\n // if there is only one element then that's the peak.\n if(sz == 1)\n return 0;\n // check if first element can be peak\n if(nums[0]>nums[1])\n return 0... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 0 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int n=nums.size();\n if(n==1)\n {\n return 0;\n\n }\n if(nums[0]>nums[1])\n {\n return 0;\n\n }\n if(nums[n-1]>nums[n-2])\n {\n return n-1;\n }\n int start=1;\n int end=n-... |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 1 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& nums) {\n int n = nums.size();\n for(int i=0; i<n-1; i++){\n if(nums[i] > nums[i+1]){\n return i;\n }\n }\n return n-1;\n \n }\n};",
"memory": "11600"
} |
162 | <p>A peak element is an element that is strictly greater than its neighbors.</p>
<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find a peak element, and return its index. If the array contains multiple peaks, return the index to <strong>any of the peaks</strong>.</p>
<p>You may imagine that <c... | 1 | {
"code": "class Solution {\npublic:\n int findPeakElement(vector<int>& a) {\n int n = a.size();\n if(n==1) return 0;\n for(int i=0;i<n;i++) \n {\n if(i==0 && a[i]>a[i+1])\n {\n return i;\n }\n if(i== n-1 && a[i]>a[i-1])\n {\n retu... |
164 | <p>Given an integer array <code>nums</code>, return <em>the maximum difference between two successive elements in its sorted form</em>. If the array contains less than two elements, return <code>0</code>.</p>
<p>You must write an algorithm that runs in linear time and uses linear extra space.</p>
<p> </p>
<p><st... | 0 | {
"code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(NULL);\n cin.tie(0); cout.tie(0);\n }\n int maximumGap(vector<int>& nums) {\n if (nums.size() < 2)\n return 0;\n\n \n ranges::sort(nums);\n\n int res = nums[1] - nums[0];\n\n ... |
164 | <p>Given an integer array <code>nums</code>, return <em>the maximum difference between two successive elements in its sorted form</em>. If the array contains less than two elements, return <code>0</code>.</p>
<p>You must write an algorithm that runs in linear time and uses linear extra space.</p>
<p> </p>
<p><st... | 0 | {
"code": "class Solution {\npublic:\n Solution() {\n ios_base::sync_with_stdio(NULL);\n cin.tie(0); cout.tie(0);\n }\n int maximumGap(vector<int>& nums) {\n if (nums.size() < 2)\n return 0;\n\n \n ranges::sort(nums);\n\n int res = nums[1] - nums[0];\n\n ... |
164 | <p>Given an integer array <code>nums</code>, return <em>the maximum difference between two successive elements in its sorted form</em>. If the array contains less than two elements, return <code>0</code>.</p>
<p>You must write an algorithm that runs in linear time and uses linear extra space.</p>
<p> </p>
<p><st... | 0 | {
"code": "class Solution {\npublic:\n int maximumGap(vector<int>& nums) {\n int n = nums.size();\n if(n < 2){\n return 0;\n }\n sort(nums.begin(), nums.end());\n int maxDiff = 0;\n for(int i=1;i<n;i++){\n int diff = nums[i] - nums[i-1];\n ... |
164 | <p>Given an integer array <code>nums</code>, return <em>the maximum difference between two successive elements in its sorted form</em>. If the array contains less than two elements, return <code>0</code>.</p>
<p>You must write an algorithm that runs in linear time and uses linear extra space.</p>
<p> </p>
<p><st... | 0 | {
"code": "class Solution {\npublic:\n int maximumGap(vector<int>& nums) {\n if(nums.size()<2){\n return 0;\n }\n int maxDiff=0;\n sort(nums.begin(),nums.end());\n for(int i=0;i<nums.size()-1;i++){\n maxDiff= max( maxDiff , nums[i+1]-nums[i]);\n }\n ... |
164 | <p>Given an integer array <code>nums</code>, return <em>the maximum difference between two successive elements in its sorted form</em>. If the array contains less than two elements, return <code>0</code>.</p>
<p>You must write an algorithm that runs in linear time and uses linear extra space.</p>
<p> </p>
<p><st... | 0 | {
"code": "class Solution {\npublic:\n int maximumGap(vector<int>& nums) {\n if(nums.size()==1)\n {\n return 0;\n }\n sort(nums.begin(),nums.end());\n int i=0;\n int j=1;\n int MaxDiff=INT_MIN;\n while(i<nums.size()-1)\n {\n if(nu... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.