id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
2
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
2
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
2
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
2
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
3
{ "code": "\nclass Solution {\npublic:\n void dfs(TreeNode* root, string temp, vector<string>& ans){\n // bc\n if(!root) return;\n if(!root->left && !root->right){\n temp+= to_string(root->val);\n ans.push_back(temp);\n\n }\n\n //task\n temp+= to_stri...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
257
<p>Given the <code>root</code> of a binary tree, return <em>all root-to-leaf paths in <strong>any order</strong></em>.</p> <p>A <strong>leaf</strong> is a node with no children.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" src="https://assets.leetcode.com/uploads/2021/03/12/paths-t...
3
{ "code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod...
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
0
{ "code": "class Solution {\npublic:\n int addDigits(int num) {\n if (num == 0) return 0;\n return 1 + (num - 1) % 9;\n }\n};\n", "memory": "8000" }
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
0
{ "code": "class Solution {\npublic:\nint fun(int num){\n int sum=num;\n while(sum>9){\n sum=0;\n while(num>9){\n int temp=num%10;\n sum+=temp;\n num=num/10;\n }\n if(sum+num<=9)return sum+num;\n num=sum+num;\n sum=num;\n }\nreturn 9;...
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
0
{ "code": "class Solution {\npublic:\n int addDigits(int num) {\n if (num == 0) {\n return 0;\n }\n return 1 + (num - 1) % 9;\n }\n};", "memory": "8100" }
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
0
{ "code": "class Solution {\npublic:\n int sum(int num){\n int sum = 0;\n while(num){\n sum+=num%10;\n num/=10;\n }\n return sum;\n }\n int addDigits(int num) {\n while(num/10){\n num = sum(num);\n }\n return num;\n }\n};", ...
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
0
{ "code": "class Solution {\npublic:\n int addDigits(int num) {\n if (num == 0) return 0;\n return 1 + (num - 1) % 9;\n }\n};", "memory": "8200" }
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
0
{ "code": "class Solution {\npublic:\n int addDigits(int num) {\n return (num - 1) % 9 + 1;\n }\n};", "memory": "8300" }
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
0
{ "code": "class Solution {\npublic:\n int addDigits(int num) {\n int k=num%9;\n if (num<10) {\n return num;\n }\n else if (k==0) {\n return 9;\n }\n else {\n return k;\n }\n }\n};", "memory": "8300" }
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
1
{ "code": "class Solution {\npublic:\n int ans1(int &num,int &ans){\n \n while(num>0){\n ans=ans+(num%10);\n num=num/10;\n \n \n }\n num=ans;\n ans=0;\n if(num/10==0)return num;\n else ans1(num,ans);\n \n \n...
258
<p>Given an integer <code>num</code>, repeatedly add all its digits until the result has only one digit, and return it.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> num = 38 <strong>Output:</strong> 2 <strong>Explanation:</strong> The process is 38 --&gt; 3 + 8 --...
1
{ "code": "class Solution {\npublic:\n int sum(int num){\n int a=0;\n while(num>0){\n int x=num%10;\n num=num/10;\n a=a+x;\n };\n return a;\n }\n int addDigits(int num) {\n int a=0;\n while(true){\n num=sum(num);\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "using ll=long long;\nclass Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n \n ll bm=0; // the rsult of bm only contain diff bit of two single num\n for(auto e: nums){\n bm^=e;\n }\n\n ll right_most_diff_bit = bm & (-bm); // extract one ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n long long int xorr = 0;\n for (int i = 0; i < nums.size(); i++)\n xorr = xorr ^ nums[i];\n\n // finding the rightmost bit\n // it is taking long long to avoid integer overflow\n long...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int n = nums.size();\n\n int xorr = 0;\n\n for(int num : nums) {\n xorr ^= num;\n }\n\n // finding first set bit\n int cnt = 0;\n\n while(xorr != 0) {\n if(x...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n long long ans=0;\n for(int i=0;i<nums.size();i++){\n ans^=nums[i];\n }\n long long diff= ans & ~(ans-1);\n long long ans1=0;\n long ans2=0;\n for(int i=0;i<nums.size();...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n \n int a=0,b=0, temp=0, cnt=0;\n for(int i=0;i<nums.size();i++){\n temp = temp ^ nums[i];\n }\n\n while((temp&1)!=1){\n cnt++;\n temp= temp>>1;\n }\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n long xorr = 0;\n for(auto ele: nums) xorr ^= ele;\n\n // you need a number which can separate the on the basis of bits;\n long diffBitNumber = (xorr & (xorr-1)) ^ xorr;\n\n int bucket1 = 0, buc...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int xorSum = 0;\n // XOR all numbers to get the XOR of the two unique numbers\n for (int num : nums) {\n xorSum ^= num;\n }\n\n // Get the rightmost set bit\n int mask=0;\n\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
0
{ "code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) \n {\n long long xorr = 0; \n for(auto it : nums) xorr = xorr ^ it;\n\n long long msb = (xorr & (xorr - 1)) ^ xorr;\n long long x = 0, y = 0; \n for(...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
1
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n long xo=0; int ans1=0,ans2=0;\n for(auto it:nums)\n {\n xo=xo^it;\n }\n int rightSet=(xo&(xo-1)^xo);\n for(auto it:nums)\n {\n if(rightSet&it)\n {...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
1
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int num = 0,index = -1;\n if(nums.size() == 2)return nums;\n for(int i = 0;i < nums.size();i++)num = num^nums[i];\n for(int i = 0;i < 32;i++){\n if(((num>>i)&1) == 1){index = i;break;}\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int i=0;\n int n=nums.size();\n sort(nums.begin(),nums.end());\n vector<int> ans;\n while(i<n){\n if(i+1<n && nums[i]==nums[i+1]){\n i=i+2;\n }\n else{\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int n=nums.size();\n long xor1=0;\n for(int i=0;i<n;i++){\n xor1=xor1^nums[i];\n }\n long rightmost=(xor1 & xor1-1)^xor1;\n long b1=0;\n long b2=0;\n for(int i=0...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int n=nums.size();\n if(n==2) return nums; \n vector<int>ans;\n sort(nums.begin(),nums.end());\n int i=0,j=1;\n while(j<n){\n if(nums[i]==nums[j]){\n i+=2;\n j+=2;\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n sort(nums.begin(),nums.end());\n int a=-1;\n for(int i=0;i<nums.size();i++){\n if(i==0 and nums[i]!=nums[i+1]){\n a=nums[i];\n } else if(i>0 and i<nums.size()-1 and nums[i]!=nums[i-1] and nums[i...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int k=1;\n vector<int>b;\n vector<int>c;\n sort(nums.begin(), nums.end());\n\n for (int i = 0; i < nums.size(); ) {\n if (i + 1 < nums.size() && nums[i] == n...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int k=1;\n vector<int>b;\n \n sort(nums.begin(), nums.end());\n\n for (int i = 0; i < nums.size(); ) {\n if (i + 1 < nums.size() && nums[i] == nums[i + 1]) {\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) \n {\n int a=0;//this is for a\n for(int i=0;i<nums.size();i++)\n {\n a=a^nums[i];//this is xor\n } \n int first_set_bit;\n int d=1;\n while(!(a&1)) //means until whe...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n vector<long> num;\n for(int n: nums){\n num.push_back((long)n);\n }\n long s = 0;\n for(long n: num){\n s = s ^ n;\n }\n long t = s ^ (s & (s - 1));\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n int getFirstSetBit(int n)\n {\n \n for(int i=0;i<32;i++){\n if(n&(1<<i)){\n return i;\n }\n \n }\n return 0;\n }\n int func(vector<int>nums){\n int res=0;\n for(int x:nums){\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());\nint get_rand(int a, int b)\n{\n return a + rng()%(b-a+1);\n};\n\nclass Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n int id = get_rand(0, (int)nums.size()-1);\n int qt_left = 0, qt_right = 0...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n set<int> tmp;\n for (int num : nums) {\n if (tmp.count(num)) tmp.erase(num);\n else tmp.insert(num);\n }\n vector<int> ans(tmp.begin(), tmp.end());\n return ans;\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n set<int> s;\n for (int i = 0; i < nums.size(); i++) {\n if (s.count(nums[i]))\n s.erase(nums[i]);\n else\n s.insert(nums[i]);\n }\n vector<int> res(s.begin(),s.end());\n return ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n vector<int>res;int i=0;\n while(i<nums.size()){\n int n=nums[i];\n nums.erase(nums.begin()+i);\n if(find(nums.begin(),nums.end(),n)==nums.end())\n res.push_back(n);\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n // brute force\n\n unordered_set<int> stt;\n for(int n: nums){\n if(stt.contains(n)) stt.erase(n);\n else stt.insert(n);\n }\n vector<int> ans;\n for(int n: stt){\n...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int> &nums) {\n\tunordered_set<int> visited;\n\t// store num with odd freq into set\n\tfor (auto &num: nums)\n\t\tif (visited.count(num))\n\t\t\tvisited.erase(num);\n\t\telse visited.insert(num);\n\t// return ans\n\treturn vector<int> (visited....
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n unordered_set<int> res;\n for (int num : nums) {\n if (res.find(num) == res.end()) {\n res.insert(num);\n } else {\n res.erase(num);\n }\n }\...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n unordered_set<int> res;\n for (int num : nums) {\n if (res.find(num) == res.end()) {\n res.insert(num);\n } else {\n res.erase(num);\n }\n }\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n map<int,int> m;\n vector<int> ans;\n for(int i=0;i<nums.size(); i++){\n m[nums[i]]++;\n }\n for(auto i:m){\n if(i.second==1){\n ans.push_back(i.first);\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n map<int,int> cnt;\n for(auto i:nums){\n if(cnt.find(i)!=cnt.end()){\n cnt[i]++;\n }\n else{\n cnt[i] = 1;\n }\n }\n vector<int...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
2
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n unordered_map<int, int> count_map;\n vector<int> ans;\n for (int i = 0; i < nums.size(); i++) {\n count_map[nums[i]]++;\n }\n\n for (auto it : count_map) {\n if (it.second...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
3
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n unordered_map <int,int> freq;\n for(auto it:nums){\n freq[it]++;\n }\n vector<int> ans;\n for(auto it:freq){\n if(it.second==1) ans.push_back(it.first);\n }\n ...
260
<p>Given an integer array <code>nums</code>, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in <strong>any order</strong>.</p> <p>You must write an&nbsp;algorithm that runs in linear runtime complexi...
3
{ "code": "class Solution {\npublic:\n vector<int> singleNumber(vector<int>& nums) {\n vector<int>ans;\n unordered_map<int, int> mp;\n for(auto ch: nums) {\n mp[ch]++;\n }\n\n for(auto& ch: mp) {\n if(ch.second == 1) {\n ans.push_back(ch.first...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n int wrd1=0,wrd2=0,i=0,j=0;\n int m =word1.size(),n=word2.size();\n while(wrd1 < m && wrd2 < n){\n if(word1[wrd1][i] != word2[wrd2][j]){\n return false;\n...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n \n int index1 = 0;\n int index2 = 0;\n int i = 0;\n int j = 0;\n\n while(index1<word1.size() && index2<word2.size())\n {\n if(word1[index1][...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n int w1=0;\n int w2=0;\n int i=0;\n int j=0;\n int m = word1.size();\n int n = word2.size();\n while(w1<m && w2<n ){\n if(word1[w1][i]!=word2...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n int w1=0;\n int w2=0;\n int i=0;\n int j=0;\n int m = word1.size();\n int n = word2.size();\n while(w1<m && w2<n ){\n if(word1[w1][i]!=word2...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) \n {\n string s1=\"\",s2=\"\";\n for(int i=0;i<word1.size();i++)\n {\n s1+=word1[i];\n } \n for(int i=0;i<word2.size();i++)\n {\n ...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string res1=\"\";\n for(int i=0;i<word1.size();i++)\n res1+=word1[i];\n\n string res2=\"\";\n for(int i=0;i<word2.size();i++)\n res2+=word2[i];\n cout<...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string str1=\"\",str2=\"\";\n int i=0,j=0;\n while(i<word1.size() || j<word2.size()){\n if(i<word1.size()){\n str1+=word1[i++];\n }\n ...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
0
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string str=\"\";\n string str1=\"\";\n \n for(int i=0;i<word1.size();i++){\n str+=word1[i];\n }\n for(int i=0;i<word2.size();i++){\n str1+=word2[i];\n ...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
1
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string result1 = \"\";\n string result2 = \"\";\n\n for(int i=0; i<word1.size(); i++){\n result1 += word1[i];\n }\n\n for(int i=0; i<word2.size(); i++){\n...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
1
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string s1 = \"\";\n string s2 = \"\";\n for(auto x : word1){\n for(auto y : x){\n s1+=y;\n }\n }\n for(auto x : word2){\n ...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
2
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string a;\n string b;\n for(auto i:word1){\n a+=i;\n }\n for(auto i:word2){\n b+=i;\n }\n \n return a==b;\n }\n};", "memo...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
2
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n int n1=word1.size();\n int n2=word2.size();\n string w1=\"\";\n string w2=\"\";\n for(int i=0;i<n1;i++){\n w1+=word1[i];\n }\n for(int i=0;i...
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
3
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string s1 = \"\", s2 = \"\";\n for(auto x : word1) s1 += x;\n for(auto x : word2) s2 += x;\n return s1 == s2;\n \n }\n};", "memory": "13900" }
1,781
<p>Given two string arrays <code>word1</code> and <code>word2</code>, return<em> </em><code>true</code><em> if the two arrays <strong>represent</strong> the same string, and </em><code>false</code><em> otherwise.</em></p> <p>A string is <strong>represented</strong> by an array if the array elements concatenated <stron...
3
{ "code": "class Solution {\npublic:\n bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {\n string a=\"\";\n string b= \"\";\n for(int i=0;i<word1.size();i++){\n a = a+word1[i];\n }\n for(int i=0;i<word2.size();i++){\n b = b+word2[i];\...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
0
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string ans(n, 'a');\n k-=n;\n for(int i=n-1; i>=0 && k; --i){\n int add = min(k, 25);\n ans[i] += add;\n k-=add;\n }\n return ans;\n }\n};", "memory": "22500" }
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
0
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string ans(n,'0');\n for(int i=n;i>0;i--)\n {\n int ch=min(26,k-i+1);\n ans[i-1]='a'+(ch-1);\n k-=ch;\n }\n return ans;\n }\n};", "memory": "22600" }
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
0
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) \n {\n string s(n, 'a');\n k -= n;\n\n if(k==0)return s;\n\n for(int i=n-1;i>=0;i--)\n {\n if(k==0)return s;\n\n if(k>=25)\n {\n k=k-25;\n ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
0
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string res(n, 'a');\n k -= n;\n int i = n-1;\n while (k > 0) {\n res[i] += min(25, k);\n k -= min(25, k);\n i--;\n }\n return res;\n }\n};", "memory": "2...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
0
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string res(n,'a');\n k-=n;\n for(int i = n-1 ; i >= 0 and k ; i--) {\n int x = min(25,k);\n res[i]+=x;\n k-=x;\n }\n return res;\n }\n};", "memory": "22800" }
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
1
{ "code": "class Solution {\n public:\n std::string getSmallestString(int n, int k) {\n std::string result(n, 'a');\n k -= n;\n\n while (k > 0) {\n const int increment = std::min(25, k);\n result[--n] += increment;\n k -= increment;\n }\n\n return result;\n }\n};\n", "memory": "22900...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
2
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string s=\"\";\n for(int i=0;i<n;i++)\n s+='a';\n k=k-n;\n for(int i=n-1;i>=0;i--)\n {\n if(k==0)\n break;\n else if(k<25)\n {\n ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
2
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string ans;\n while(n!=0)\n {\n int ch=k-(n-1)*26;\n if(ch<=0)\n {\n ans.push_back('a');\n n--;\n k--;\n }\n els...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
2
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string ans;\n while(n!=0)\n {\n int ch=k-(n-1)*26;\n if(ch<=0)\n {\n ans.push_back('a');\n n--;\n k--;\n }\n els...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n \n int x = (26 * n - k) / 25;\n n -= x;\n k -= x;\n string ans = string(x, 'a');\n while(k){\n int y = min(k, 26);\n k -= y;\n ans += 'a' + y - 1;\n }\...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n \n // void solve(int n , int k , string &ans, string temp)\n // {\n // if(n==0 && k==0)\n // {\n // if(ans.empty()) ans = temp;\n // else ans = min(ans,temp);\n // return;\n // }\n // if(n==0 && k != 0) return...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution\n{\npublic:\n string getSmallestString(int n, int k)\n {\n string result = \"\";\n int max = 26;\n\n while (k > 0 && n > 0)\n {\n if (k > n)\n {\n int quotient = k / max;\n int remainder = k % max;\n\n ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution\n{\npublic:\n string getSmallestString(int n, int k)\n {\n string result = \"\";\n int max = 26;\n\n while (k > 0 && n > 0)\n {\n if (k > n)\n {\n int quotient = k / max;\n int remainder = k % max;\n\n ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution\n{\npublic:\n string getSmallestString(int n, int k)\n {\n string result = \"\";\n int max = 26;\n\n while (k > 0 && n > 0)\n {\n if (k > n)\n {\n int quotient = k / max;\n int remainder = k % max;\n\n ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n k -= n;\n string cur = string(k / 25, 'z');\n if (k % 25 != 0){\n cur = string(1, 'a' + k % 25) + cur;\n }\n int l = cur.length();\n return string(n-l, 'a') + cur;\n }\n};", ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution\n{\npublic:\n string getSmallestString(int n, int k)\n {\n string result = \"\";\n int max = 26;\n\n while (k > 0 && n > 0)\n {\n if (k > n)\n {\n int quotient = k / max;\n int remainder = k % max;\n\n ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n\n string res = \"\";\n\n k -= n;\n int zs = k / 25;\n int rem = k % 25;\n\n \n res += string(max(n-zs-1, 0), 'a');\n\n if(n-zs-1 >= 0) res += ('a'+rem);\n\n res += string(zs, 'z...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\r\npublic:\r\n string getSmallestString(int n, int k) {\r\n int z = (k - n) / 25;\r\n int a = max(0, n-z-1);\r\n int rem = k - z * 26 - a;\r\n string ans(a, 'a');\r\n if (rem > 0) ans += (char)('a' + rem - 1);\r\n return ans + string(z, 'z');\r\...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) \n {\n int val=0;\n\n map<int,char>b;\n map<char,int>a;\n for(int i='a';i<='z';i++)\n {\n a[i]=val;\n val++;\n }\n\n for(auto i:a)\n {\n b[i.seco...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) \n {\n int val=0;\n\n map<int,char>b;\n map<char,int>a;\n for(int i='a';i<='z';i++)\n {\n a[i]=val;\n val++;\n }\n\n for(auto i:a)\n {\n b[i.seco...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string res = \"\";\n string getSmallestString(int n, int k) {\n if(n == 0) return res;\n for(int i = 1; i <= 26; i++) {\n if((n - 1) * 26 >= k - i) {\n char c = 'a' + i - 1;\n res += c;\n return getSmall...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution\n{\npublic:\n string getSmallestString(int n, int k)\n {\n deque<char> output;\n int t = n;\n \n for (int i = 0; i < n; i++)\n { \n char z = 'z';\n for (; z != 'a' - 1; z--)\n {\n int cheak = k - (z - ...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n \n int x = (26 * n - k) / 25;\n n -= x;\n k -= x;\n string ans = string(x, 'a');\n vector<char> vec;\n while(k){\n int y = min(k, 26);\n k -= y;\n vec....
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string ans=\"\";\n map<int,char>mp;\n char ch='a';\n for(int i=1;i<=26;i++){\n mp[i]=ch;\n ch++;\n }\n while(k-(n-1)>=26)\n {\n k=k-26;\n an...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n string ans = \"\", sans = \"\";\n int cnt = 0;\n for(int i = 0; i < n; i++){\n ans+='1';\n sans+='a';\n cnt++;\n }\n cout << \"sans \" << sans << endl;\n if(c...
1,782
<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code>b</code> is <code>2</code>, the numeric value of <code>c</code> is <code>3</code>, and...
3
{ "code": "class Solution {\npublic:\n string getSmallestString(int n, int k) {\n // represent k as sum of n numbers\n // range of numbers = [1,26]\n // lexicographically smallest array or list of\n // numbers possible\n\n // give all of them 1s\n \n vector<int> listOfN...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "class Solution {\npublic:\n ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {\n ListNode* temp1 = list1;\n ListNode* temp2 = list2;\n ListNode* tail1 = list1;\n for(int i=1; i<=b; i++) {\n tail1 = tail1->next;\n }\n for(int i=...
1,765
<p>You are given two linked lists: <code>list1</code> and <code>list2</code> of sizes <code>n</code> and <code>m</code> respectively.</p> <p>Remove <code>list1</code>&#39;s nodes from the <code>a<sup>th</sup></code> node to the <code>b<sup>th</sup></code> node, and put <code>list2</code> in their place.</p> <p>The bl...
0
{ "code": "/**\n * Definition for singly-linked list.\n * struct ListNode {\n * int val;\n * ListNode *next;\n * ListNode() : val(0), next(nullptr) {}\n * ListNode(int x) : val(x), next(nullptr) {}\n * ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n...