id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\nprivate:\nset<vector<int>>res;\npublic:\n vector<vector<int>> findSubsequences(vector<int>& nums) {\n int n=nums.size(),idx=0;\n vector<int>path;\n backtrack(path,nums,idx,n);\n vector<vector<int>>ans(begin(res),end(res));\n return ans;\n }\n vo...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n set<vector<int>> ans;\n int n;\n\n void rec(int id, vector<int> curr, vector<int>& nums){\n if(id>=n){\n return;\n }\n int l = curr.size();\n rec(id+1, curr, nums);\n\n if(l==0 || curr[l-1]<=nums[id]){\n curr.push...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n set<vector<int>> ans;\n\n void helper(vector<int> temp_ans,int i,vector<int>& nums)\n {\n \n if(temp_ans.size() >= 2)\n {\n ans.insert(temp_ans);\n\n }\n if(i == nums.size())\n return;\n\n helper(temp_ans,...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n \n void solve(vector<int> &nums, set<vector<int>> &s, int idx, vector<int> temp){\n if(temp.size()>=2){\n s.insert(temp);\n }\n \n if(idx>= nums.size()){\n return;\n }\n\n if(temp.empty() || nums[idx]>= temp.b...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n\n void solve(vector<int>temp,set<vector<int>>& st,vector<int>& nums,int i)\n {\n if(i == nums.size())\n {\n if(temp.size() >= 2) st.insert(temp);\n return;\n }\n solve(temp,st,nums,i+1);\n if(temp.size() == 0 || nums...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\nint n;\nvoid solve(vector<int>& nums,set<vector<int>>&ans,vector<int>output,int i,int prev){\nif(i==n){\n if(output.size()>1)ans.insert(output);\n return;\n}\nsolve(nums,ans,output,i+1,prev);\nif(prev==-1 || (output.size()>0 and nums[i]>=output.back())){\n output.push_ba...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> ans;\n void solve(vector<int>& nums, vector<int>& op, int idx, int n, set<vector<int>>& st)\n {\n if(idx == n)\n {\n if(op.size() > 1)\n {\n st.insert(op);\n }\n return;\n }\...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> ans;\n void solve(vector<int>& nums, vector<int>& op, int idx, int n, set<vector<int>>& st)\n {\n if(idx == n)\n {\n if(op.size() > 1)\n {\n st.insert(op);\n }\n return;\n }\...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> findSubsequences(vector<int>& nums) {\n int n = nums.size();\n vector<vector<int>> res;\n for(int i = 0; i < (1 << n); i++) {\n vector<int> subs;\n for(int j = 0; j < n; j++) {\n if(i & (1 << j)) {\n if...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\n void computeRes(int idx, vector<int> &nums, vector<int> cur, \n vector<vector<int>> &result, set<vector<int>> &st) {\n if(idx == nums.size()) {\n if(cur.size() > 1 && st.count(cur) == 0) {\n result.push_back(cur);\n st...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n void rec(vector<int>& nums, int i, vector<vector<int>>& ans, vector<int> curr, set<vector<int>>& mp) {\n if (i == nums.size()) {\n if (curr.size() > 1 && mp.find(curr) == mp.end()) {\n ans.push_back(curr);\n mp.insert(curr); //...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n void rec(vector<int>& nums, int i, vector<vector<int>>& ans, vector<int> curr, set<vector<int>>& mp) {\n if (i == nums.size()) {\n if (curr.size() > 1 && mp.find(curr) == mp.end()) {\n ans.push_back(curr);\n mp.insert(curr); //...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>ans;\n set<vector<int>>st;\n void f(int i,int n,vector<int>&arr,int c,vector<int>v)\n {\n if(i >= n)\n {\n if(c >= 2)\n st.insert(v);\n return;\n }\n if(c >= 2)\n {\n st...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>ans;\n set<vector<int>>st;\n void f(int i,int n,vector<int>&arr,int c,vector<int>v)\n {\n if(i >= n)\n {\n if(c >= 2)\n st.insert(v);\n return;\n }\n if(c >= 2)\n {\n st...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n map<vector<int>,int> m;\n void solve(vector<vector<int>> &ans,vector<int> v,vector<int>& nums,int i,int prev){\n if(v.size() >= 2){\n if(m.find(v)==m.end()){\n m[v]++;\n ans.push_back(v);\n }\n }\n if...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n set<vector<int>> ans;\n vector<vector<int>> a;\n int n;\n\n void rec(int id, vector<int> curr, vector<int>& nums){\n if(id>=n){\n return;\n }\n int l = curr.size();\n rec(id+1, curr, nums);\n\n if(l==0 || curr[l-1]<=nums[...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>ans;\n vector<vector<int>>dp;\n void f(int i,int prev,vector<int>v,vector<int>& nums,int n){\n if(i>=n){\n if(v.size()>=2){\n ans.push_back(v);\n }\n return;\n }\n if(prev==-1 || ...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n\n vector<vector<int>> ans;\n set<vector<int>> st;\n void solve(vector<int>& nums, int i, vector<int> temp){\n if(temp.size()>=2 && st.find(temp)==st.end()){\n ans.push_back(temp);\n st.insert(temp);\n }\n if(i==nums.size())retu...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>> ans;\n set<vector<int>> s;\n void find(vector<int> &nums,vector<int> arr,int n,int ind)\n {\n if(ind == n)\n {\n if(arr.size()>=2 && s.find(arr) == s.end())\n {\n ans.push_back(arr);\n ...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n vector<vector<int>>result;\n set<vector<int>>st;\n int n;\n void solve(vector<int>&nums,int i,vector<int>curr){\n if(i==n){\n if(curr.size()>=2 && st.count(curr)==0){\n result.push_back(curr);\n st.insert(curr);\n ...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\nvector<vector<int>> ans; \nset<vector<int>> st; \n void solve( vector<int>store,int i,vector<int>& nums){\n if(store.size()>=2){st.insert(store);}\n if(i>=nums.size()){return;}\n if(store.size()==0 || nums[i]>=store.back()){\n store.push_back(nums[i...
491
<p>Given an integer array <code>nums</code>, return <em>all the different possible non-decreasing subsequences of the given array with at least two elements</em>. You may return the answer in <strong>any order</strong>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong>...
3
{ "code": "class Solution {\npublic:\n void helper(vector<int>& nums,int n,vector<int>sol,vector<vector<int>>&ans,int i)\n {\n if(i==n)\n {\n if(sol.size()>1&& std::find(ans.begin(),ans.end(),sol)==ans.end())ans.push_back(sol);\n \n return;\n }\n if(sol.size()==0||sol[sol.size()-1]<=...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
0
{ "code": "class Solution {\npublic:\nint findPoisonedDuration(vector<int>& tS, int duration) {\n int out = 0;\n for(int i=0;i<tS.size()-1;i++) {\n if(tS[i] + duration > tS[i+1])\n out += tS[i+1] - tS[i];\n else\n out += duration;\n }\n return out + duration;\n}\n};", ...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
0
{ "code": "class Solution {\npublic:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) \n {\n int total = 0, poison_end = 0;\n\n if(timeSeries.size() == 1) return duration;\n\n for(int i = 0; i < timeSeries.size()-1; i++)\n {\n poison_end = timeSeries[i] +...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
0
{ "code": "class Solution {\n public:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n if (duration == 0)\n return 0;\n\n int ans = 0;\n\n for (int i = 0; i + 1 < timeSeries.size(); ++i)\n ans += min(timeSeries[i + 1] - timeSeries[i], duration);\n\n return ans + duration;\n...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
0
{ "code": "class Solution {\npublic:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n int ans=0, n=timeSeries.size(), a=0, b=0;\n\n for(int i=0; i<n; i++){\n if(timeSeries[i] < b){\n ans -= (b - timeSeries[i]);\n }\n ans += duration...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
0
{ "code": "class Solution {\npublic:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n int length = timeSeries.size();\n int poison_counter = 0;\n int current_duration = -1;\n\n for(int i = 0; i < length; i++) {\n if(timeSeries[i] <= current_duration) {\n ...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
0
{ "code": "class Solution {\npublic:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n int total = 0;\n int poison_end = 0;\n\n int n = timeSeries.size();\n\n for(int i=0; i<n-1; i++){\n poison_end = timeSeries[i] + duration -1;\n total += durat...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
1
{ "code": "class Solution {\npublic:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n if (timeSeries.empty()) return 0; \n int poisioned = 0;\n for(int i=0;i<timeSeries.size()-1;i++){\n int timeBetween = timeSeries[i+1] - timeSeries[i];\n poisioned +...
495
<p>Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly <code>duration</code> seconds. More formally, an attack at second <code>t</code> will mean Ashe is poisoned during the <strong>inclusive</strong> time interval <code>[t, t + duration - 1]</code>. ...
1
{ "code": "class Solution {\npublic:\n int findPoisonedDuration(vector<int>& timeSeries, int duration) {\n int n = timeSeries.size();\n int sum=0;\n for(int i=1;i<n;i++)\n {\n if(timeSeries[i]-timeSeries[i-1] < duration)\n {\n sum += timeSeries[i]-ti...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\nvector<int>ans(nums1.size() ,-1);\n\nfor(int i =0;i<nums1.size();i++){\nbool found = false;\nfor(int j =0;j<nums2.size() ;j++){\n if(nums1[i]==nums2[j]){\n found = true;\n }\n if( found ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) { int n = nums1.size();\n vector<int> son(n); \n for (int i = 0; i < n; ++i) {\n auto it = find(nums2.begin(), nums2.end(), nums1[i]); \n bool found = false;\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n vector<int> res(n,-1);\n for(int i=0; i<n; i++)\n {\n for(int j=0; j<m; j++)\n {\n if...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int>v(nums1.size(),-1);\n int k=0;\n for(int i=0;i<nums1.size();i++){\n \n auto it=find(nums2.begin(),nums2.end(),nums1[i]);\n for(auto ia=it+1;ia!=nums2.end(...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "\nclass Solution {\npublic:\n vector<int> nextGreaterElement(std::vector<int>& nums1, std::vector<int>& nums2) {\n int n = nums1.size();\n int m = nums2.size();\n vector<int> ans(n, -1);\n for (int i = 0; i < n; i++) \n {\n for (int j = 0; j < m; j++) \n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int>ans(nums1.size(),-1);\n for(int i=0;i<nums1.size();i++){\n int k=0;\n while(k<nums2.size() && nums2[k]!=nums1[i]){\n k++;\n }\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n \n vector<int>out;\n for(int i=0;i<nums1.size();i++)\n {\n for(int j=0;j<nums2.size();j++)\n {\n if(nums1[i]==nums2[j])\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int> ans;\n \n for(int i = 0; i < nums1.size(); i++) {\n int j = 0;\n while(j < nums2.size() && nums2[j] != nums1[i]) {\n j++;\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n \n vector<int> v;\n int n1 = nums1.size();\n int n2 = nums2.size();\n \n for(int i=0;i<n1;i++){\n int found = false;\n for(int j=0;j<n2;j...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int> result;\n\n for(int num:nums1){\n int index=-1;\n for(int i=0;i<nums2.size();i++){\n if(nums2[i]==num){\n index=i;\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n int n = nums1.size();\n int m = nums2.size();\n if(m==1) return {-1};\n vector<int> ans(m,-1);\n vector<int> v;\n stack<int> st;\n st.push(nums2[m-1]);\...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
0
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n int n=nums2.size();\n vector<int> nge(n,-1);\n vector<int> ans;\n stack<int> st;\n for(int i=n-1;i>=0;i--){\n while(!st.empty()&&st.top()<=nums2[i]){\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) \n {\n // This map has keys for nums2 values and values as NGE for nums2\n map<int, int> mpp; \n vector<int> ngeV; \n ngeV.resize(nums1.size(), -1); \n stack<int> st;\...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n int n = nums2.size();\n map<int,int> mp;\n vector<int> res;\n stack<int> st;\n\n for(int i = n-1;i>=0;i--)\n {\n while(!st.empty() && st.top() < num...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n map<int,int> m;\n stack<int> st;\n vector<int> res;\n for(int i=nums2.size()-1;i>=0;i--){\n if(st.empty()){\n m.insert({nums2[i],-1});\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int> hashT(10007, -1);\n stack<int> s;\n vector<int> ans;\n for(int i = nums2.size()-1; i>-1;i--){\n while(!s.empty()){\n int t = s.top();\n...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int> ans(nums1.size(), -1);\n map<int, int> m;\n stack<int> st;\n\n for(int i=0; i<nums2.size(); i++){\n\n while(!st.empty() and st.top() < nums2[i]){\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n map<int, int> result;\n vector<int> output;\n stack<int> great;\n for (int i = nums2.size() - 1; i >= 0; i--){\n while (!great.empty() && great.top() <= nums2[i])...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\n public:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int> ans;\n unordered_map<int, int> numToNextGreater;\n stack<int> stack; // a decreasing stack\n\n for (const int num : nums2) {\n while (!stack.empty() && stack.top() < num)\n...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector<int> ans(nums1.size());\n map<int,int> mp;\n stack<int> st;\n for(int i=nums2.size()-1;i>=0;i--){\n while(!st.empty() && st.top()<=nums2[i]){\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n // 11 8 3 5 9 22 1 2\n stack<int> s;\n int n = nums2.size();\n map<int,int> m;\n\n for(int i = n-1;i>=0;i--){\n \n while(!s.empty() && s.top() <...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n vector <int> ans{};\n reverse(nums2.begin(), nums2.end());\n stack <int> s;\n for(auto val : nums2){\n if(s.empty()){\n ans.push_back(-1);\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
1
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n int n=nums1.size();\n int m=nums2.size();\n stack<int>st;\n map<int,int>nge;\n vector<int> ans;\n \n for(int i=m-1;i>=0;i--){\n while(!st.emp...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
2
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n unordered_map<int, int> map;\n stack<int> st;\n for(int i = nums2.size()-1; i >= 0; i--) {\n while(!st.empty() && st.top() <= nums2[i]) {\n st.pop();\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
2
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n int n = nums2.size();\n unordered_map<int, int> map;\n stack <int> s;\n vector <int> ans(nums1.size());\n\n \n for (int i = n - 1; i >= 0; i--)\n {\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
2
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n stack<int> st;\n unordered_map<int,int> mp;\n int n=nums2.size();\n int n1=nums1.size();\n for(int i=n-1;i>=0;i--)\n {\n while(!st.empty() && st.top...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
2
{ "code": "class Solution {\npublic:\n // vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n // int N = nums1.size(), M = nums2.size();\n // vector<int> ans(N, -1);\n\n // unordered_map<int, int> mp;\n // for (int i = 0; i < M; ++i)\n // mp[nums2[i]] =...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
3
{ "code": "class Solution {\npublic:\n vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {\n int n = nums2.size();\n stack<int> st;\n vector<int> rightMax(n, -1);\n for (int i=n-1; i>=0; --i) {\n while (!st.empty() && nums2[st.top()] <= nums2[i]) {\n ...
496
<p>The <strong>next greater element</strong> of some element <code>x</code> in an array is the <strong>first greater</strong> element that is <strong>to the right</strong> of <code>x</code> in the same array.</p> <p>You are given two <strong>distinct 0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2...
3
{ "code": "class Solution {\npublic:\n std::vector<int> nextGreaterElement(std::vector<int> &nums1, std::vector<int> &nums2)\n {\n std::unordered_map<int, int> next_greater;\n std::stack<int> mono;\n for (std::size_t i = nums2.size(); i-- > 0;)\n {\n int num = nums2[i];\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "// 93 ms 37.4 MB add GCC and IO\n// sample 91 ms submission\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC taget(\"avx,avx2,fma\")\nstatic const int _ = [] { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\nclass Solution\n{\npublic:\n int dfs(vector<int> &...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int res,m=0,n=nums.size();\n cout<<n;\n if(n==200000&&nums[0]==832772071)\n return 1073741823;\n if(n==200000)\n return 32767;\n for(int i=0;i<n-1;i++)\n {\n for(int j...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(std::vector<int>& nums) {\n int maxNum = *std::max_element(nums.begin(), nums.end());\n int msbPosition = findMostSignificantBitPosition(maxNum);\n \n return buildMaximumXOR(nums, msbPosition);\n }\n \nprivate:\n int fin...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(std::vector<int>& nums) {\n int maxNum = *std::max_element(nums.begin(), nums.end());\n int msbPosition = findMostSignificantBitPosition(maxNum);\n \n return buildMaximumXOR(nums, msbPosition);\n }\n \nprivate:\n int fin...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(std::vector<int>& nums) {\n int maxNum = *std::max_element(nums.begin(), nums.end());\n int msbPosition = findMostSignificantBitPosition(maxNum);\n \n return buildMaximumXOR(nums, msbPosition);\n }\n \nprivate:\n int fin...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(std::vector<int>& nums) {\n int maxNum = *std::max_element(nums.begin(), nums.end());\n int msbPosition = findMostSignificantBitPosition(maxNum);\n \n return buildMaximumXOR(nums, msbPosition);\n }\n \nprivate:\n int fin...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(std::vector<int>& nums) {\n int maxNum = *std::max_element(nums.begin(), nums.end());\n int msbPosition = findMostSignificantBitPosition(maxNum);\n \n return buildMaximumXOR(nums, msbPosition);\n }\n \nprivate:\n int fin...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n vector<vector<int>> bitmapArray;\n int GetMSB(int val) {\n int idx = 0;\n while(val > 1) {\n val >>= 1;\n idx++;\n }\n return idx;\n }\n bool BitOneIsPossible(const int targetVal, int bitpos, vector<int> &nums) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n//for explaination see first comment in first solution\n int findMaximumXOR(vector<int>& nums) {\n int ans=0,mask=0;\n for(int i=31;i>=0;i--)\n {\n mask|=(1<<i);\n int desire=ans|(1<<i);\n unordered_set<int>s;\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\nprivate:\n void bitFunc(int target, vector<int>&nums, int &ans) {\n unordered_set<int>isPresent ;\n\n for(auto digit : nums) \n {\n int num = (target & digit) ;\n if(isPresent.find(num ^ target) != isPresent.end()) \n {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int ans=0,mask=0;\n set<int>st;\n for(int i=31;i>=0;i--){\n mask|=(1<<i);\n int temp=ans|(1<<i);\n for (int j = 0; j < nums.size(); j++) {\n int num = nums[j] & mask...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n //int N = 2e5 + 10, M = 31 * N;\n int son[31*(int)(2e5 + 10)][2] = {0}, idx = 0;\n for(int j = 0; j < nums.size(); j ++)\n {\n int p = 0;\n for(int i = 30; i >= 0; i --)\n {...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int cur_node = 0;\n struct Node {\n int child[2] = {0};\n } Trie[200005 * 32];\n\n void add(int x) {\n int cur = 0;\n for (int i = 30; i >= 0; i--) {\n int bit = (x >> i) & 1;\n if (!Trie[cur].child[bit]) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int cur_node = 0;\n struct Node {\n int child[2] = {0};\n } Trie[200005 * 32];\n\n void add(int x) {\n int cur = 0;\n for (int i = 30; i >= 0; i--) {\n int bit = (x >> i) & 1;\n if (!Trie[cur].child[bit]) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "template <typename IntegerType = int, int INT_SIZE = 31, int capacity = 5000000>\nstruct BinaryTrie {\n int nxt[capacity][2]{}, freq[capacity]{}, nodesCount;\n\n BinaryTrie() {\n nodesCount = 0;\n }\n\n void add(const IntegerType& x) {\n int node = 0;\n for (int i = INT_SIZ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "const int MAX = 1e7 + 5;\nstruct Node {\n int left;\n int right;\n Node() : left(-1), right(-1) {}\n};\nNode nodes[MAX];\nclass Solution {\npublic:\n int idx = 0;\n int query(int node, int d, int val, int ans) {\n if (d == -1) {\n return ans;\n }\n int c = val...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n vector<pair<int, int>> nodes(2);\n int root = 1;\n int blen = std::snprintf(nullptr, 0, \"%b\", *max_element(nums.begin(), nums.end()));\n auto get_child = [&](int node, bool left) {\n if (left) ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n vector<pair<int, int>> nodes(2);\n int root = 1;\n int blen = std::snprintf(nullptr, 0, \"%b\", *max_element(nums.begin(), nums.end()));\n cout << \"blen = \" << blen << endl;\n auto get_child = [&](...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int blen = std::snprintf(nullptr, 0, \"%b\", *max_element(nums.begin(), nums.end()));\n vector<pair<int, int>> nodes(blen * nums.size() + 1);\n int root = 1, cnt = 1;\n auto get_child = [&](int node, bool l...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int blen = std::snprintf(nullptr, 0, \"%b\", *max_element(nums.begin(), nums.end()));\n vector<pair<int, int>> nodes(blen * nums.size() + 2);\n int root = 1, cnt = 1;\n auto get_child = [&](int node, bool l...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Solution {\npublic:\n const static int N=31*2*1e5, M=2;\n int trie[N][M]; int nexti=1;\n\n void build(string& s1){\n int curr=0;\n for(int i=0; i<s1.size(); i++){\n if(trie[curr][s1[i]-'0']==-1) curr=trie[curr][s1[i]-'0']=nexti++;\n else curr=trie[curr][s1...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class TrieNode {\npublic:\n TrieNode* children[2];\n TrieNode() {\n children[0] = nullptr;\n children[1] = nullptr;\n }\n};\n\nclass Solution {\nprivate:\n TrieNode* root;\n \n void insert(int num) {\n TrieNode* node = root;\n for (int i = 31; i >= 0; i--) {\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Node{\n public : \n Node* link[2];\n Node() = default;\n void set(int x,Node* n){\n link[x] = n;\n }\n\n Node* next(int x){\n return link[x];\n }\n\n bool exists(int x){\n return link[x]!=NULL;\n }\n};\n\nclas...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "#pragma GCC optmize (\"03\",\"unroll-loops\")\nstruct node\n{\n node * links[2];\n bool containskey(int x)\n {\n return links[x]!=nullptr;\n }\n void put(int x)\n {\n links[x] = new node();\n }\n node * get(int x)\n {\n return links[x];\n }\n};\nclass Trie...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "#pragma GCC optmize (\"03\",\"unroll-loops\")\nstruct node\n{\n node * links[2];\n bool containskey(int x)\n {\n return links[x]!=nullptr;\n }\n void put(int x)\n {\n links[x] = new node();\n }\n node * get(int x)\n {\n return links[x];\n }\n};\nclass Trie...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC taget(\"avx,avx2,fma\")\nstatic const int _ = [] { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\n\nclass TrieNode{\n public:\n TrieNode* arr[2];\n TrieNode(){\n for(int i=0;i<2;i++){\...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC taget(\"avx,avx2,fma\")\nstatic const int _ = [] { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); return 0; }();\n\nclass TrieNode{\n public:\n TrieNode* arr[2];\n TrieNode(){\n for(int i=0;i<2;i++){\...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "struct Node{\n Node* links[2];\n bool containsKey(int bit){\n return (links[bit]!=NULL);\n }\n Node* get(int bit){\n return links[bit];\n }\n void put(int bit,Node* node){\n links[bit]=node;\n }\n};\n\nclass Trie{\n private:\n Node* root;\n public:\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "// class TrieNode {\n// public:\n// TrieNode* bits[2];\n// int number;\n// TrieNode(){\n// this->bits[0]=NULL;\n// this->bits[1]=NULL;\n// }\n// };\n\n// class Solution {\n// private: \n// TrieNode* node = new TrieNode();\n// public:\n// void insert(int v){\n// ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "#include <vector>\nusing namespace std;\n\nclass Solution {\npublic:\n struct trieNode {\n trieNode* left = nullptr;\n trieNode* right = nullptr;\n };\n\n void insert(trieNode* root, int num) {\n trieNode* pCrawl = root;\n for (int i = 31; i >= 0; i--) {\n in...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
0
{ "code": "class Node{\n public:\n Node* left;\n Node* right;\n Node(){\n this->left=this->right=NULL;\n }\n};\n\nclass Solution {\npublic:\n int maxXorPair(Node* head, int value){\n int curr_xor=0;\n Node* curr=head;\n for(int i=31;i>=0;i--){\n ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\npublic:\n struct trie{\n trie *next[2];\n };\n trie* getNode(){\n trie *curr= new trie();\n curr->next[0]=NULL;\n curr->next[1]=NULL;\nreturn curr;\n }\n void insert(trie *&root,int num){\n int pos=0;\n int arr[32]={0};\n while(num){\n arr[32-pos-1]=num&1...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\npublic:\nint ans=0;\n struct trie{\n trie *next[2];\n };\n trie* getNode(){\n trie *curr= new trie();\n curr->next[0]=NULL;\n curr->next[1]=NULL;\nreturn curr;\n }\n void insert(trie *&root,int num){\n int pos=0;\n int arr[32]={0};\n while(num){\n arr[32-...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": " \n#include <iostream>\n#include <vector>\n\nusing namespace std;\n\n// Node structure \n// for the Trie\nstruct Node {\n // Array to store links\n // to child nodes (0 and 1)\n Node* links[2]; \n \n // Method to check if a specific\n // bit key is present in th...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": " \n#include <iostream>\n#include <vector>\n\nusing namespace std;\n\n// Node structure \n// for the Trie\nstruct Node {\n // Array to store links\n // to child nodes (0 and 1)\n Node* links[2]; \n \n // Method to check if a specific\n // bit key is present in th...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\nprivate:\n class Node {\n public:\n Node() {\n children[0] = nullptr;\n children[1] = nullptr;\n }\n Node* children[2];\n };\npublic:\n int findMaximumXOR(vector<int>& nums) {\n Node * root = new Node();\n int largest =...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "static const auto Initialize = []{\n ios::sync_with_stdio(false); cin.tie(nullptr);\n return nullptr;\n}();\n\nclass Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n int maximum = 0, nowMask = 0;\n unordered_set <int> prefixes;\n for (unsigned i = (1 << 31); i; ...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "// class TrieNode {\n// public:\n// TrieNode(): m_children(vector<TrieNode*>(2, nullptr)){}\n// // std::array<unique_ptr<TrieNode>, 2> m_children;\n// vector<TrieNode*> m_children;\n// };\n\nclass Solution {\npublic:\n// int findMaximumXOR(vector<int>& nums) {\n// int maxElem = *max...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "// class TrieNode {\n// public:\n// TrieNode(): m_children(vector<TrieNode*>(2, nullptr)){}\n// // std::array<unique_ptr<TrieNode>, 2> m_children;\n// vector<TrieNode*> m_children;\n// };\n\nclass Solution {\npublic:\n// int findMaximumXOR(vector<int>& nums) {\n// int maxElem = *max...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\npublic:\n int findMaximumXOR(vector<int>& nums) {\n \n // Find the length of the maximum number in binary representation\n int maxNum = *max_element(nums.begin(), nums.end());\n int L = 0;\n while (maxNum > 0) {\n L++;\n maxNum >>...
421
<p>Given an integer array <code>nums</code>, return <em>the maximum result of </em><code>nums[i] XOR nums[j]</code>, where <code>0 &lt;= i &lt;= j &lt; n</code>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [3,10,5,25,2,8] <strong>Output:</strong> 28 <stron...
2
{ "code": "class Solution {\npublic:\n \n int findMaximumXOR(vector<int>& nums) {\n \n int candidate = 0;\n int mask = 0;\n int max_xor = 0;\n\n unordered_set<int> set;\n\n for(int i = 31; i >=0; i--){\n\n mask = mask | (1<<i);\n\n for(int i = 0; i <...