id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "\nint main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n ofstream out(\"user.out\");\n\n char ch;\n bool flag = 0;\n bool start_s = 0;\n\n int max_size = -1;\n int cur_size = 0;\n int size = 0;\n \n\n cin.unsetf(ios_base::skipws);\n while (cin >> ch) {\n // c...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "int main() {\n ios_base::sync_with_stdio(0);\n cin.tie(0);\n ofstream out(\"user.out\");\n\n char ch;\n bool flag = 0;\n bool start_s = 0;\n\n int max_size = -1;\n int cur_size = 0;\n int size = 0;\n \n\n cin.unsetf(ios_base::skipws);\n while (cin >> ch) {\n // cou...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string_view s) {\n int i = s.length() - 2;\n while (i > 0 and s[i] == ' ')\n --i;\n const int back = i;\n while (i > 0 and s[i] != ' ')\n --i;\n return back - i;\n }\n};\n\nint init = [] {\n i...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int start = s.size() - 1;\n int count = 0;\n bool word = false;\n for (int i = start; i >= 0; i--) {\n if (s[i] == ' ') {\n if (word) {\n break;\n }\n ...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int count = 0;\n int n = s.size();\n bool flag = false;\n\n for(int i=n-1; i>=0; i--)\n {\n if(s[i]>='a' && s[i]<='z' || s[i]>='A' && s[i]<='Z')\n {\n flag=true;\n ...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int cnt=0;\n int n=s.size();\n int i=n-1;\n while(isspace(s[i])){\n s.pop_back();\n i--;\n }\n for( ;i>=0;i--){\n if(isspace(s[i])) return cnt;\n cnt++;\n ...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n // start iterating from the back\n int start = -1;\n int end = -1;\n\n // to find the ending index of the last word \n for(int i = s.length()-1;i>=0;i--){\n if(s[i] != ' '){\n sta...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int end = s.length() - 1;\n\n while (end >= 0 && s[end] == ' ') {\n end--;\n }\n\n int start = end;\n while (start >= 0 && s[start] != ' ') {\n start--;\n }\n\n return en...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int length = 0;\n bool counting = false;\n \n for (int i = s.length() - 1; i >= 0; i--) {\n if (s[i] != ' ') {\n counting = true;\n length++;\n }\n el...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
0
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n bool flag=false;\n int count=0;\n for(int i=s.length()-1;i>=0;i--){\n if(s[i]==' ' && flag==true){\n break;\n }else if(s[i]!=' '){\n flag=true;\n count++...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
1
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int len=0;\n int i = s.size()-1;\n while(i>=0 && s[i]==' ')\n i--;\n while(i >=0 && s[i]!=' '){\n len++;\n i--;\n }\n\n return len;\n }\n};", "memory": "8000" }
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
1
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int length = 0;\n int i = s.size() - 1;\n while (i >= 0 && s[i] == ' ') {\n i--;\n }\n while (i >= 0 && s[i] != ' ') {\n length++;\n i--;\n }\n\n return length;\n }\n};", "memory": "8000" }
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
3
{ "code": "class Solution {\n\npublic:\n\n int lengthOfLastWord(string s) {\n\n int length = 0;\n\n bool counting = false;\n\n \n\n for (int i = s.length() - 1; i >= 0; i--) {\n\n if (s[i] != ' ') {\n\n counting = true;\n\n length++;\n\n ...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
3
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n int n = s.size();\n int count = 0;\n int i = n - 1;\n while(i>=0 && s[i]==' ') i--;\n while(i >= 0 && s[i]!=' '){\n count++;\n i--;\n }\n return count;\n }\n};\n", "...
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
3
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n stringstream ss(s);\n int len = 0;\n string word;\n while (ss >> word) {\n //len = word.length();\n }\n len = word.length();\n\n return len;\n }\n};", "memory": "8200" }
58
<p>Given a string <code>s</code> consisting of words and spaces, return <em>the length of the <strong>last</strong> word in the string.</em></p> <p>A <strong>word</strong> is a maximal <span data-keyword="substring-nonempty">substring</span> consisting of non-space characters only.</p> <p>&nbsp;</p> <p><strong class=...
3
{ "code": "class Solution {\npublic:\n int lengthOfLastWord(string s) {\n stringstream ss(s);\n while(ss>>s);\n return s.length();\n }\n};", "memory": "8200" }
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> generateMatrix(int n) {\n vector<vector<int>> ans(n,vector<int >(n,0));\n int val=1;\n int it_i=0,it_j=0;\n if(n==1)\n {\n ans[0][0]=1;\n return ans;\n }\n int i=0,j=0;\n for(i=0...
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\n\npublic:\n\n const int dirs[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };\n\n vector<vector<int>> generateMatrix(int n) {\n\n vector<vector<int>> ans(n, vector<int>(n));\n\n int i = 0, j = 0, k = 0;\n\n for (int v = 1; v <= n * n; ++v) {\n\n ans[i][j...
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> generateMatrix(int n) {\n\n vector<vector<int>> ans(n,vector<int>(n,0));\n\n int left=0;\n int right=n-1;\n int top=0;\n int bottom=n-1;\n\n int count=1;\n\n while(top<=bottom && left<=right){\n f...
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> generateMatrix(int n) {\n vector<vector<int>> res(n,vector<int>(n,-1));\n int count = 1;\n int dir_idx = 0;\n int x = 0,y =0;\n while(count <= n*n){\n res[x][y] = count;\n int new_x = x+dirs[dir_idx]...
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> generateMatrix(int n) {\n vector<vector<int>> ans(n, vector<int>(n));\n int first_col = 0;\n int last_col = n - 1;\n int first_row = 0;\n int last_row = n - 1;\n int count = 0;\n int total = n * n;\n ...
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\npublic:\n vector<int> dx = {0, 1, 0, -1};\n vector<int> dy = {1, 0, -1, 0};\n int x;\n int y;\n\n vector<vector<int>> generateMatrix(int n) {\n vector<vector<int>> ans(n, vector<int>(n, 0));\n\n x = 0, y = 0;\n int dir = 0;\n int cur = 1;\n ...
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> generateMatrix(int n) {\n int x = 0, y = 0, dx = 1, dy = 0;\n vector<vector<int>> res(n, vector<int>(n, 0));\n \n for (int i = 0; i < n * n; ++i) {\n res[y][x] = i + 1;\n if (!(0 <= x + dx && x + dx < n &&...
59
<p>Given a positive integer <code>n</code>, generate an <code>n x n</code> <code>matrix</code> filled with elements from <code>1</code> to <code>n<sup>2</sup></code> in spiral order.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2020/11/13/spi...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> generateMatrix(int n) {\n int m = n;\n vector<vector<int>> ans(n,vector<int>(n,0));\n int top = 0, left = 0;\n int bottom = m-1, right = n-1;\n int count = 1;\n while(top <= bottom && left <= right) {\n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n string ans;\n for (int i = 0; i < n; ++i) ans += ('1' + i);\n while (--k) next_permutation(begin(ans), end(ans));\n return ans;\n }\n};", "memory": "7200" }
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<string> ans;\n string s=\"\";\n for(int i=1;i<=n;i++)\n {\n s+=i+'0';\n }\n // cout<<s;\n while(k>1)\n {\n next_permutation(s.begin(),s.end());\n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n string s;\n for(int i = 1;i<=n;i++){\n s+= i+'0';\n }\n while(k!=1){\n next_permutation(s.begin(),s.end());\n k--;\n }\n return s;\n }\n};", "memory": "7300...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n\n int count = 0;\n string ans = \"\",temp = \"\";\n int check;\n\n string getPermutation(int n, int k) {\n check = pow(2,n)-1;\n find(n,k,0);\n return ans;\n }\n\n void find(int n,int k,int mask){\n if(mask==check){\n cou...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n string s;\n\n for (int i=1; i<=n; ++i) s.push_back(i + '0');\n\n k--;\n while(k--){\n next_permutation(s.begin(), s.end());\n }\n\n return s;\n }\n};", "memory": "7400" }
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> vec;\n for(int i=0;i<n;i++) vec.push_back(i+1);\n for(int i=0;i<k-1;i++) next_permutation(vec.begin(),vec.end());\n string s;\n for(int i=0;i<n;i++) s+='0'+vec[i];\n return s;\n }...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> v={0};\n int tmp=1;\n for(int i=1;i<=n;i++){\n v.push_back(i);\n tmp*=i;\n }\n string s;\n cout<<tmp<<\" \";\n for(int i=n;i>=2;i--){\n tmp/=i...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> v={0};\n int tmp=1;\n for(int i=1;i<=n;i++){\n v.push_back(i);\n tmp*=i;\n }\n string s;\n cout<<tmp<<\" \";\n for(int i=n;i>=2;i--){\n tmp/=i...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n\n int count = 0;\n string ans = \"\",temp = \"\";\n int check;\n\n string getPermutation(int n, int k) {\n check = pow(2,n)-1;\n find(n,k,0);\n return ans;\n }\n\n void find(int n,int k,int mask){\n if(mask==check){\n cou...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n\n\n\n long factorial(int n) { \n if (n < 0) { \n cout << \"Factorial is not defined for negative numbers.\" << endl; \n return 0; // Return 0 or handle the error as needed \n } \n\n long result = 1; \n for (int i = 1; i <= n; ++i) { \n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
0
{ "code": "class Solution {\npublic:\n void solve(int n,int k,vector<int> &vis,int &count,string &s,string &ans){\n if(s.length()==n){\n count++;\n if(count==k){\n ans=s;\n }\n return ;\n }\n for(int i=1;i<=n;i++){\n if(ans!...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
1
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n //make string\n string s =\"\";\n for(int i=1; i<=n; i++){\n string j = to_string(i);\n s.append(j);\n }\n\n for(int i=0; i<k-1; i++){\n next_permutation(s.begin(), s.e...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
1
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n //make string\n string s =\"\";\n for(int i=1; i<=n; i++){\n string j = to_string(i);\n s.append(j);\n }\n\n for(int i=0; i<k-1; i++){\n next_permutation(s.begin(), s.e...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
1
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n int fact = 1;\n vector<int> nums;\n for(int i=1; i<n; i++){\n fact = fact*i;\n nums.push_back(i);\n }\n nums.push_back(n);\n string ans = \"\";\n k = k-1;\n w...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
1
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n string ans;\n bitset<10> vis;\n for (int i = 0; i < n; ++i) {\n int fact = 1;\n for (int j = 1; j < n - i; ++j) fact *= j;\n for (int j = 1; j <= n; ++j) {\n if (vis[j...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
1
{ "code": "\nclass Solution\n{\n public:\n \t\n string getPermutation(int n, int k)\n {\n string ans = \"\";\n vector<int> numbers;\n int fact = 1;\n for (int i = 1; i <= n; i++)\n {\n fact = fact * i;\n number...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
1
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> nums(n);\n for (int i = 1; i <= n; ++i) {\n nums[i - 1] = i;\n }\n \n // Adjust k to be 0-based for easier indexing\n k--;\n \n // Generate permutations using next_permutation\n string r...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
2
{ "code": "\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n int fact=1;\n vector<int>ans;\n for(int i=1;i<n;i++){\n fact=fact*i;\n ans.push_back(i);\n }\n ans.push_back(n);\n string sum=\"\";\n k=k-1;\n while(true){\n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
2
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> v; //to push all elements from 1 - n \n string ans;\n int fact =1;\n\n for(int i = 1;i<n;i++)\n {\n v.push_back(i);\n fact*=i;\n }\n v.push_back(n); // a...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution \n{\npublic:\n string getPermutation(int n, int k) \n {\n vector<int>tp;\n int fact = 1;\n for(int i=1;i<n;i++)\n {\n fact = fact*i;\n tp.push_back(i);\n } \n tp.push_back(n);\n string ans = \"\";\n int f = k-1;\n whil...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n string getPermutation(int n, int k) {\n int fact = 1;\n vector<int> numbers;\n for (int i = 1; i < n; i++) {\n fact = fact * i;\n numbers.push_back(i);\n }\n numbers.push_back(n);\n string ans = \"\";\n k ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n int rep(int i,vector<int>& nums){\n int index=i+1;\n int min=INT_MAX;\n for(int j=index;j<nums.size();j++){\n if(nums[j]-nums[i]>=0 && nums[j]-nums[i]<min){\n min=nums[j]-nums[i];index=j;}\n }return index;\n }\n void...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n void leftShift(int index,string a[],int size){\n for(int i=index;i<size-1;i++){\n a[i]=a[i+1];\n }\n return;\n }\n\n string getPermutation(int n, int k) {\n string a[n];\n int size=n;\n int factorial=1;\n for(i...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n string permutation(string str,int k,string ans){\n int n=str.length();\n if(n==0) return ans;\n int fact=1;\n for(int i=2;i<=n-1;i++){\n fact*=i;\n }\n int idx=k/fact;\n if(k%fact==0) idx--;\n char ch=str[idx];\n string left=str.substr(0,idx);\...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n string helper(string str,int k,string ans){\n int n=str.length();\n if(n==1){\n ans+=str;\n return ans;\n }\n int fact=1;\n for(int i=2;i<=n-1;i++){\n fact*=i;\n }\n int idx=k/fact;\n if(...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n string helper(string str,int k,string ans){\n int n=str.length();\n if(n==0) return ans;\n int fact=1;\n for(int i=2;i<=n-1;i++){\n fact*=i;\n }\n int idx=k/fact;\n if(k%fact==0)idx--;\n char ch=str[idx];\n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n string helper(string str, int k, string ans){\n int n = str.length();\n if(n==1){\n ans += str;\n return ans;\n }\n int fact = 1;\n for(int i=2;i<=n-1;i++){\n fact *= i;\n }\n int idx = k/fact;\...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\nvoid helper(string s, int k,string& ans)\n{\n if(s.size()==0)\n {\n return; \n }\n int n = s.size();\n int fact = 1;\n for(int i=2;i<=(n-1);i++)\n {\n fact*=i;\n }\n int idx = k/fact;\n if(k%fact==0)idx--;\n char ch = s[idx];\n st...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\nvoid fun(int n , vector<int> &pq, string &s, int k ) {\n // cout<<n<<\" \"<<k<<\"\\n\";\n if(n == 1) {\n s = s + to_string(pq[0]);\n ans = s;\n return ;\n }\n if( k <= 1) {\n for(auto x: pq) s+= to_string(x);\n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n string helper(string str,int k,string ans){\n int n=str.length();\n if(n==0){\n return ans;\n }\n int fact=1;\n for(int i=2;i<=n-1;i++){\n fact*=i;\n }\n int idx=k/fact;\n if(k%fact==0)idx--;\n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n \n string getPermutation(int n, int k) {\n string cur=\"\";\n for(int i=1;i<=n;i++){\n cur+=to_string(i);\n }\n while(k-1>0){\n string nums=cur;\n int i = n - 2;\n while (i >= 0 && nums[i] >= nums[i + ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n vector<int> ans,final_ans;\n int vis[10];\n int k1;\n void dfs(int i,int n)\n {\n if(k1<0) return;\n\n if(ans.size()==n)\n {\n k1--;\n //cout << ans.size() << \" \" << k1 << \" \"; \n if(k1==0)\n {\n...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n string solve(string &s, int n) {\n int i = n - 2;\n // Find the first element from the end that is smaller than its next element\n while (i >= 0 && s[i] >= s[i + 1])\n i--;\n \n // If no valid i was found, it means the string is i...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n vector<int> ans,final_ans;\n int vis[10];\n int k1;\n void dfs(int i,int n)\n {\n if(k1<0) return;\n\n if(ans.size()==n)\n {\n k1--;\n //cout << ans.size() << \" \" << k1 << \" \"; \n if(k1==0)\n {\n...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\nint fac(int p)\n{\n int a=1;\n for(int i=1;i<=p;i++)\n {\n a*=i;\n }\n return a;\n}\n string getPermutation(int n, int k) {\n \n \n int mx=n;\n string ans=\"\";\n map<int,int>m;\n if(k==1)\n {\n ...
60
<p>The set <code>[1, 2, 3, ...,&nbsp;n]</code> contains a total of <code>n!</code> unique permutations.</p> <p>By listing and labeling all of the permutations in order, we get the following sequence for <code>n = 3</code>:</p> <ol> <li><code>&quot;123&quot;</code></li> <li><code>&quot;132&quot;</code></li> <li><co...
3
{ "code": "class Solution {\npublic:\n\n int n;\nvector<bool> visited;\nvector<int> ans;\nvector<int> curr;\nint cnt;\nint tar;\nvoid dfs(int x)\n{\n if(x==n)\n {\n cnt++;\n if(cnt==tar)ans=curr;\n return;\n }\n \n for(int i{1}; i<=n; i++)\n {\n if(!visited[i])\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n int n1;\n\n for (int i=0; i<nums1.size(); i++){\n n1 = nums1[i];\n for (int j=i+1; j<nums1.size(); j++){\n if (n1 == nums1[j]){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<int>> answer(2); // Result vector with two lists\n \n // Find unique elements in nums1 that are not in nums2\n for (int num : nums1) {\n bool fo...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) \n {\n vector<vector<int>> res(2);\n int m = nums1.size();\n int n = nums2.size();\n vector<int> vct;\n for(int i=0 ; i<m ; i++)\n {\n int cnt = ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<int>>v(2);\n for(int i=0;i<nums1.size();i++){\n for(int j=0;j<nums1.size();j++){\n if(i!=j&&nums1[i]==nums1[j]){\n nums1[j]=...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "static const auto kds = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<int> temp;\n vector<vector<...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<int>> ret;\n\n vector<int> zero;\n for (int num : nums1) {\n if (!isInVector(num, nums2) && !isInVector(num, zero)) {\n zero.push_back(n...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n ranges::sort(nums1);\n nums1.erase(ranges::unique(nums1).begin(), nums1.end());\n ranges::sort(nums2);\n nums2.erase(ranges::unique(nums2).begin(), nums2.end());\n\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "static const auto kds = []() {\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\nclass Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<int>> vResult(2, vector<int>...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<int> unique1, unique2;\n int n = nums1.size(),m = nums2.size();\n bool found;\n for(int i = 0;i < n;i++){\n found = false;\n for(int j = 0;j < m;j++){\n...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) \n {\n vector<vector<int>> result;\n vector<int>::iterator iter;\n\n std::sort(nums1.begin(), nums1.end());\n std::sort(nums2.begin(), nums2.end());\n\n auto uniq1...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size();\n int n2 = nums2.size();\n vector<vector<int>> ans(2);\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n int...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n int n1 = nums1.size();\n int n2 = nums2.size();\n vector<vector<int>> ans(2);\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n in...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n static bool isitthere(const vector<int>& num, int k, int s, int e){\n if(s > e){\n return false;\n }\n int mid = s + (e - s) / 2;\n if(num[mid] == k){\n return true;\n }\n if(k < num[mid]){\n return is...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n static bool isitthere(const vector<int>& num, int k, int s, int e){\n if(s > e){\n return false;\n }\n int mid = s + (e - s) / 2;\n if(num[mid] == k){\n return true;\n }\n if(k < num[mid]){\n return is...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n static bool isitthere(const vector<int>& num, int k, int s, int e){\n if(s > e){\n return false;\n }\n int mid = s + (e - s) / 2;\n if(num[mid] == k){\n return true;\n }\n if(k < num[mid]){\n return is...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n sort(nums1.begin(), nums1.end()); sort(nums2.begin(), nums2.end());\n vector<int> l, r;\n int i=0, j=0;\n int n1 = nums1.size(), n2 = nums2.size();\n while(i<n1 &...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\r\npublic:\r\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\r\n int n1 = nums1.size();\r\n int n2 = nums2.size();\r\n vector<int> ans1;\r\n vector<int> ans2;\r\n sort(nums1.begin(),nums1.end());\r\n sort(nums2.beg...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n\n vector<vector<int>> ans;\n vector<int> a1,a2;\n\n int arr[2001];\n\n\n for(int i=0;i<2001;i++ )arr[i]=0;\n\n for(auto i:nums2)\n {\n arr[i+10...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n sort(nums1.begin(), nums1.end());\n sort(nums2.begin(), nums2.end());\n int n = nums1.size();\n int m = nums2.size();\n vector<int>v1, v2;\n int i = 0;\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "#define MAX_MAP_SIZE 2001\n#define INT_TO_INDEX(x) (x + 1000)\n#define INDEX_TO_INT(x) (x - 1000)\n\nclass Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n enum {\n NUMS_1 = 1 << 0,\n NUMS_2 = 1 << 1, \n }...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<int> getDistinct(vector<int>& nums){\n vector<int> result;\n for (int i=0; i<nums.size(); i++){\n int isFind=0;\n for (int j=0; j<result.size(); j++){\n if (nums[i] == result[j]){\n isFind = 1;\n }\n }\n if (!i...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "#include <bits/stdc++.h> \nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> diff(vector<int> nums1, vector<int> nums2){\n vector<int> ans1;\n int l = 0;\n int r = 0;\n while(l<nums1.size() && r<nums2.size()){\n if(nums1[l]==nums2[r]){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "#include <bits/stdc++.h> \nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> diff(vector<int> nums1, vector<int> nums2){\n vector<int> ans1;\n int l = 0;\n int r = 0;\n while(l<nums1.size() && r<nums2.size()){\n if(nums1[l]==nums2[r]){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n int max1 = *max_element(nums1.begin(),nums1.end());\n int max2 = *max_element(nums2.begin(),nums2.end());\n int min1 = *m...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<int> removeDuplicates(vector<int>& num) {\n vector<int> ans;\n if (num.size() == 0) return ans;\n\n int lastNum = num[0];\n ans.push_back(lastNum);\n for (int i = 1; i < num.size(); ++i) {\n if (num[i] != lastNum) {\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n int max1 = *max_element(nums1.begin(),nums1.end());\n int max2 = *max_element(nums2.begin(),nums2.end());\n int min1 = *min_element(nums1.begin(),nums1.end());\n int min...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n int max1 = *max_element(nums1.begin(),nums1.end());\n int max2 = *max_element(nums2.begin(),nums2.end());\n int min1 = *m...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n int max1 = *max_element(nums1.begin(),nums1.end());\n int max2 = *max_element(nums2.begin(),nums2.end());\n int min1 = *m...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "#include <bits/stdc++.h>\nclass Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n sort(nums1.begin(),nums1.end());\n sort(nums2.begin(),nums2.end());\n int mini = min(nums1[0],nums2[0]);\n int maxi = max(nums1[nums1.size()-1],nums2[nums2...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n set<int> st;\n vector<vector<int>> ans(2);\n \n // Find elements in nums1 that are not in nums2\n for (int a : nums1) {\n if (find(nums2.begin(), nums2...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "#include <set>\n#include <algorithm>\nclass Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n auto set1 =set<int>{};\n for (const auto& num1:nums1 ){\n if(find(nums2.begin(), nums2.end(), num1) == nums2.end() ){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "#include <set>\n#include <algorithm>\nclass Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n auto set1 =set<int>{};\n for (const auto& num1:nums1 ){\n if(find(nums2.begin(), nums2.end(), num1) == nums2.end() ){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n set<int> nums1diff, nums2diff;\n for (int i{}; i < nums1.size(); ++i){\n if ( find(nums2.begin(),nums2.end(), nums1[i]) == nums2.end()){\n nums1diff.insert(n...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<int>> res;\n set<int> temp;\n for(int x: nums1){\n bool ok = false;\n for(int y: nums2){\n if(x == y){\n o...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n set<int> ans1;\n set<int> ans2;\n vector<vector<int>>finalAns;\n for(auto elem:nums1){\n if(find(nums2.begin(),nums2.end(),elem)==nums2.end()){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<int>>ans(2);\n unordered_map<int,bool>mp;\n for(int i =0; i < nums1.size(); i++){\n if(find(nums2.begin(),nums2.end(),nums1[i]) == nums2.end()){//chec...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int,bool> mpp;\n vector<vector<int>> ans(2);\n for(int i = 0;i < nums1.size();i++){\n if(find(nums2.begin(),nums2.end(),nums1[i]) == nums2.end()){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n set<int> a;\n set<int> b;\n for(int i=0;i<nums1.size();i++){\n int temp=0;\n for(int j=0;j<nums2.size();j++){\n if(nums1[i]==nums2[j]){\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n vector<vector<int>> ans;\n set<int> temp;\n for (auto val: nums1){\n if (find(nums2.begin(),nums2.end(),val)==nums2.end()){\n temp.insert(val);\n ...
1,392
<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p> <ul> <li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which ...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> findDifference(vector<int>& nums1, vector<int>& nums2) {\n set<int> distinct1;\n set<int> distinct2;\n for (int i = 0; i < nums1.size(); i++) {\n bool dist = true;\n for (int j = 0; j < nums2.size(); j++) {\n ...