id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\nvoid solve(vector<int>&nums,int i,vector<int>&currSubset,vector<vector<int>>& subsets){\nif(i==nums.size()){\n subsets.push_back(currSubset);\n return;\n}\ncurrSubset.push_back(nums[i]);\nsolve(nums,i+1,currSubset,subsets);\ncurrSubset.pop_back();\nsolve(nums,i+1,currSubset... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void getAllSubsets(vector<int>& nums, vector<vector<int>>& subSets,\n vector<int>& subSet, int index) {\n if (nums.size() <= index) {\n subSets.push_back(subSet);\n return;\n }\n subSet.push_back(nums[index]);\n... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void getAllSubsets(vector<int>& nums, vector<vector<int>>& subSets,\n vector<int>& subSet, int index) {\n if (nums.size() <= index) {\n subSets.push_back(subSet);\n return;\n }\n subSet.push_back(nums[index]);\n... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void helper(int i, vector<int>& nums,vector<int>& subset, vector<vector<int>>&subsets){\n if(i>=nums.size()){\n subsets.push_back(subset);\n return;\n }\n //with\n subset.push_back(nums[i]);\n helper(i+1,nums,subset,sub... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n vector<int>res;\n void subset(vector<int>&nums,vector<int>output,int i){\n int ans=0;\n for(int n:output){\n ans ^= n;\n \n\n }\n res.push_back(ans);\n for(int j=i;j<nums.size();j++){\n output.push_back(nu... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void calculate(vector<int>&nums,int index, vector<int>&v,vector<vector<int>>&v1)\n {\n if(index==nums.size())\n {\n v1.push_back(v);\n return;\n }\n \n // pickup case\n v.push_back(nums[index]);\n \n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int sum = 0;\n void backtrack(int curIndex, vector<int>nums, int curXOR){\n int N = nums.size();\n for(int i = 0 ; i < 2; i++){\n curXOR = i == 0 ? curXOR : curXOR ^nums[curIndex];\n if(curIndex == N - 1){\n this->sum = t... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int sum = 0;\n void backtrack(int curIndex, vector<int>nums, int curXOR){\n int N = nums.size();\n for(int i = 0 ; i < 2; i++){\n curXOR = i == 0 ? curXOR : curXOR ^nums[curIndex];\n if(curIndex == N - 1){\n int tempsum =... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int sum = 0;\n void backtrack(int curIndex, vector<int>nums, int curXOR){\n int N = nums.size();\n for(int i = 0 ; i < 2; i++){\n curXOR = i == 0 ? curXOR : curXOR ^nums[curIndex];\n if(curIndex == N - 1){\n this->sum = t... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int result;\n\n void helper(int sum,vector<int> nums,int i)\n {\n if(i==nums.size()-1)\n {\n result+= sum + (sum^nums[i]);\n return;\n }\n\n helper(sum^nums[i],nums,i+1);\n helper(sum,nums,i+1);\n }\n\n\n in... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n vector<int> arr;\n int rs = 0;\n int xor_fun(vector<int> arr) {\n int rs = 0;\n for(auto it: arr) rs^=it;\n return rs;\n }\n\n void back(int idx, vector<int> nums) {\n rs+=xor_fun(arr);\n for(int i = idx ; i <nums.size(); i++){\n... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int ans=0;\n int xorOfArray(vector<int>arr)\n{\n int xor_arr = 0;\n for (int i = 0; i < arr.size(); i++) {\n xor_arr = xor_arr ^ arr[i];\n }\n return xor_arr;\n}\n void subset(vector<int>&nums,vector<int> currVec,int index){\n ans+=xorOfArray(c... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\n private:\n vector<vector<int>> ans;\n void rec(vector<int> &nums, int i, vector<int> &ds) {\n \n if(i==nums.size()){\n ans.push_back(ds);\n return;\n }\n rec(nums, i + 1, ds); \n ds.push_back(nums[i]); \n rec(nums, i + 1, ds); \n ds.pop_ba... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\nprivate:\n void findsubsets(vector<int>& nums, vector<vector<int>>& subsets, int i, vector<int>& subset) {\n if (i == nums.size()) {\n subsets.push_back(subset);\n return;\n }\n findsubsets(nums, subsets, i + 1, subset);\n subset.push_b... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\n private:\n vector<vector<int>> ans;\n void rec(vector<int> &nums, int i, vector<int> &ds) {\n \n if(i==nums.size()){\n ans.push_back(ds);\n return;\n }\n rec(nums, i + 1, ds); \n ds.push_back(nums[i]); \n rec(nums, i + 1, ds); \n ds.pop_ba... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n \n void Calculate(std::vector<std::vector<int>> &res, int &fres)\n {\n int result = 0;\n for(auto subsets: res)\n {\n int t = 0;\n for(int num: subsets)\n {\n\n t ^= num;\n }\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\n void calc(int ind,vector<int>& v1,vector<vector<int>>& res,vector<int>& nums){\n int n=nums.size();\n res.push_back(v1);\n\n for(int i=ind;i<n;i++){\n v1.push_back(nums[i]);\n calc(i+1,v1,res,nums);\n v1.pop_back();\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void subsets(vector<int>& nums, int ind, vector<int>& v, vector<vector<int>>& ans)\n {\n if(ind >= nums.size()) \n {\n ans.push_back(v);\n return;\n }\n\n v.push_back(nums[ind]);\n subsets(nums, ind+1, v, ans);\n\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void findAllSubset(int idx,vector<int>&nums,vector<vector<int>>&allSubset,vector<int>&result)\n {\n if(idx == nums.size())\n {\n allSubset.push_back(result);\n return;\n }\n // take\n result.push_back(nums[idx]);\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int sum = 0;\n for(int i=0;i<(1<<n);i++){\n vector<int> temp;\n for(int j=0;j<n;j++){\n if(i&(1<<j)){\n temp.push_back(nums[j]);\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int ans = 0;\n int totalSubsets = 1 << n;\n vector<vector<int>> subsets;\n for (int mask = 0; mask < totalSubsets; ++mask) {\n vector<int> subset;\n for (in... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n\n int sum=0;\n\n for(int i=0 ;i<(1<<nums.size());i++)\n {\n vector<int>v;\n for(int j=0;j<nums.size();j++)\n {\n if((i>>j)&1)\n {\n v.push... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": " void generateSubsets(vector<int>& nums, int index, vector<int>& currentSubset, vector<vector<int>>& allSubsets) {\n // Base case: if we've considered all elements\n if (index == nums.size()) {\n allSubsets.push_back(currentSubset);\n return;\n }\n\n // Include the current element... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\n\n\n\n\n void comb(vector<int> &a, vector<int> &temp, int i,vector<vector<int>> & ans){\n if (i<0){\n ans.push_back(temp);\n return;\n }\n comb(a,temp,i-1,ans);\n temp.push_back(a[i]);\n comb(a,temp,i-1,ans);\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\n public:\n int compute(const vector<int> &p){\n int xor_c=0;\n for(auto x:p){\n xor_c=xor_c^(x);\n }\n return xor_c;\n }\n public:\n void subset(int idx,vector<int>& nums,vector<vector<int>>&ans,vector<int>&v){\n\n if(idx==nums.... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void XORSum(int idx,vector<int> &ds,int &res,vector<int> nums){\n \n if(idx == nums.size()){\n if(ds.size() != 0){\n int x = ds[0];\n for(int i = 1; i <ds.size(); i++){\n x ^= ds[i];\n }\... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\nprivate:\n int ans = 0;\n void rec(vector<int> nums,int index,int prev_xor){\n if(index == nums.size()){\n ans += prev_xor;\n return;\n }\n rec(nums,index+1,prev_xor^(nums[index]));\n rec(nums,index+1,prev_xor);\n return ;\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\n int solve(vector<int>nums , int i , int Xor){\n if(i==nums.size()){\n return Xor;\n }\n int include = solve(nums , i+1 , nums[i]^Xor);\n int exclude = solve(nums , i+1 , Xor);\n\n return (include+exclude);\n }\n\n int subs... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\n void recursiveHelper(vector<int> nums, int xorSum, int& finalSum, int index, int n)\n {\n if(index>=n)\n {\n finalSum+=xorSum;\n return;\n }\n\n xorSum=xorSum^nums[index];\n recursiveHelper(nums, xorSum, finalSum, ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void subset(int idx,vector<int> & ds,vector<int>nums,int n,vector<int>&ans){\n if(idx==n){\n int sum=0;\n for(auto it:ds){\n sum^=it;\n }\n ans.push_back(sum);\n return;\n }\n\n subset(... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void solve(vector<int>nums,vector<int>&xors,int start,vector<int>&ans){\n if(start == nums.size()){\n int s = 0;\n for(int i=0;i<ans.size();i++){\n s = s^ans[i];\n }\n xors.push_back(s);\n return... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\n vector<int> res;\n vector<int> curr;\npublic:\n int calcXORsum(vector<int>&arr){\n int sum = 0;\n for(int i=0; i<arr.size(); i++){\n sum ^= arr[i];\n }\n return sum;\n }\n\n int subsetXORSum(vector<int>& nums) {\n int tot = 0;\... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<vector<int>>result={{}};\n int sum=0;\n \n for(auto num:nums)\n {\n int n=result.size();\n for(int i=0;i<n;i++)\n {\n vector<int>subset=result[i];... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<vector<int>> subsets(1);\n for(int num : nums) {\n size_t subsets_size = subsets.size();\n for(size_t i = 0; i < subsets_size; ++i) {\n vector<int> tmp = subsets[i];\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "void createSubsets(int index, std::vector<int> subset, std::vector<std::vector<int>>& subsets, const std::vector<int>& nums)\n{\n\tsubset.push_back(nums[index]);\n\tsubsets.push_back(subset);\n\tfor (int i = index + 1; i < nums.size(); i++)\n\t{\n\t\tcreateSubsets(i, subset, subsets, nums);\n\t}\n}\n\nclas... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n vector<vector<int>> result;\n\n void solve(vector<int>& nums, int i, vector<int>& temp) {\n if(i >= nums.size()) {\n result.push_back(temp);\n return;\n }\n\n temp.push_back(nums[i]);\n solve(nums, i+1, temp);\n temp... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\n void dfs(int index, int n, vector<int> nums, vector<vector<int>> &v, vector<int> &aux){\n v.push_back(aux);\n\n for(int i=index;i<n;i++){\n aux.push_back(nums[i]);\n dfs(i+1,n,nums,v,aux);\n aux.pop_back();\n }\n\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int XORcount(vector<int> subset) {\n int XOR = subset[0];\n for (int i = 1; i < subset.size(); i++)\n XOR = XOR ^ subset[i];\n return XOR;\n }\n void SubsetCount(vector<int> nums, vector<int>& subset,\n vector<vector<i... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int XORcount(vector<int> subset) {\n int XOR = subset[0];\n for (int i = 1; i < subset.size(); i++)\n XOR = XOR ^ subset[i];\n return XOR;\n }\n void SubsetCount(vector<int> nums, vector<int>& subset,\n vector<vector<i... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int ans=0;\n f(nums,{}, 0, ans);\n return ans;\n }\n\n void f(vector<int>& nums, vector<int> temp, int i, int &ans){\n if(i==nums.size()){\n int tempx = 0;\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int sum;\n \n\n void subsets(int pos, vector<int>& nums, vector<int> temp, int xorr){\n\n //base case\n if(pos >= nums.size()){\n sum += xorr;\n return;\n }\n\n //take\n temp.push_back(nums[pos]);\n \n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\nvoid subsetsum(vector<int>&nums,vector<int>ref,int ind,int &sum){\n if(ind == nums.size()){\n int x = 0;\n for(int i = 0; i < ref.size(); i++){\n x^=ref[i];\n }\n sum += x;\n return;\n }\n subsetsum(nums,ref,ind+1,sum);\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int getXOR(vector<int>& subset) {\n if (subset.empty()) return 0;\n \n int res = subset[0];\n\n for (int i = 1; i < subset.size(); ++i) {\n res = res xor subset[i];\n }\n\n return res;\n }\n\n void backtrack(vector<in... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n\nvoid subsetsum(vector<int>&nums,vector<int>ref,int ind,int &sum){\n if(ind == nums.size()){\n int x = 0;\n for(int i = 0; i < ref.size(); i++){\n x^=ref[i];\n }\n sum += x;\n return;\n }\n subsetsum(nums,ref,ind+1,sum);\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\n void f(int ind,int n,vector<int>temp , vector<int> &ans,vector<int> &nums){\n if(ind==n){\n int xor_arr= 0;\n for(int i=0;i<temp.size();i++){\n xor_arr = xor_arr^temp[i];\n }\n ans.push_back(xor_arr);\n retur... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\nprivate:\n void solve(vector<int>& nums, int index, vector<int> output, vector<int>& ans){\n // base case\n if(index >= nums.size()){\n int x = 0;\n for(int i = 0; i < output.size(); i++){\n x = x ^ output[i];\n }\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void subsetXORSumRecursion(vector<int>& nums,int index,vector<int> curr,vector<int>& xorSum){\n //Base Case\n if(index>=nums.size()){\n int xor_value = 0;\n if(curr.size()!=0){\n \n for(auto a: curr){\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int subsets = 1<<n;\n vector<vector<int>> powerset;\n\n for(int i = 0 ; i < subsets; i++)\n {\n vector<int> someset;\n for(int k = 0; k < n ; k++)\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<vector<int>> result;\n for (int i = 0; i < pow(2, nums.size()); i++) {\n vector<int> v;\n result.push_back(v);\n }\n int x = pow(2, nums.size()) / 2;\n for (int i : nums) {... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n vector<vector<int>> temp;\n int size = nums.size();\n for (int i = 0; i < (1 << size); i++) {\n vector<int> subset;\n for (int j = 0; j < size; j++) {\n if (i & (1 << j)) {\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& arr) {\n int totalSum = 0; // To hold the sum of XOR values of all subsets\n vector<vector<int>> subsets = {{}}; // Start with the empty subset\n\n // Iterate over each element in the array\n for (int i = 0; i < arr.size(); ++i)... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n if(nums.size() == 0)\n return 0;\n int n = nums.size();\n vector<vector<int>>v;\n for (int i = 0; i < (1 << n); i++) {\n vector<int>temp;\n for (int j = 0; j < n; j++) {\n ... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n void findSubsets(vector<vector<int>>& subsets, vector<int>& nums){\n int n = nums.size();\n int maxPossibilities = (1<< n);\n for(int i=0; i< maxPossibilities; i++){\n vector<int> list;\n for(int j=0; j< n; j++){\n //i... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution\n{\npublic:\n int subsetXORSum(vector<int> &nums)\n {\n int n = nums.size();\n vector<vector<int>> subsets;\n\n for (int i = 0; i < (1 << n); ++i)\n {\n vector<int> subset;\n for (int j = 0; j < n; ++j)\n {\n i... |
1,993 | <p>The <strong>XOR total</strong> of an array is defined as the bitwise <code>XOR</code> of<strong> all its elements</strong>, or <code>0</code> if the array is<strong> empty</strong>.</p>
<ul>
<li>For example, the <strong>XOR total</strong> of the array <code>[2,5,6]</code> is <code>2 XOR 5 XOR 6 = 1</code>.</li>
</... | 3 | {
"code": "class Solution {\npublic:\n int subsetXORSum(vector<int>& nums) {\n int n = nums.size();\n int subsetcount = 1<<n;\n vector<vector<int>> allsubsets;\n for(int i=0; i<subsetcount; i++){\n vector<int> subset;\n for(int j=0; j<n; j++){\n if((... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "using P2I = pair<int, int>;\nclass Solution {\npublic:\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n int n = vals.size();\n int parent[n];\n int count[n];\n for(int i=0; i<n; i++){\n parent[i] = -1;\n count[i] = 1;\n }... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "using P2I = pair<int, int>;\nclass Solution {\npublic:\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n int n = vals.size();\n int parent[n];\n int count[n];\n for(int i=0; i<n; i++){\n parent[i] = -1;\n count[i] = 1;\n }... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n int par[30007];\n int mx[30007];\n int frq[30007];\n \n int find(int u){\n if(u==par[u]) return u;\n return par[u]=find(par[u]);\n }\n \n /*\n Hard Problem :(\n */\n \n int numberOfGoodPaths(vector<int>& v, vector<vector<int>>& e)... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DSU {\npublic:\n vector<int> parent;\n vector<pair<int, int>>m; //{maxVal, count of maxVal}\n DSU(vector<int> &vals) : parent(vals.size()), m(vals.size()) {\n for(int i = 0; i < vals.size(); i++) {\n parent[i] = i;\n m[i] = {vals[i], 1};\n }\n }\n\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DSU {\npublic:\n vector<int> parent;\n vector<pair<int, int>>m; //{maxVal, count of maxVal}\n DSU(vector<int> &vals) : parent(vals.size()), m(vals.size()) {\n for(int i = 0; i < vals.size(); i++) {\n parent[i] = i;\n m[i] = {vals[i], 1};\n }\n }\n\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n // dsu\n vector<int> root;\n int get(int x) {\n return x == root[x] ? x : (root[x] = get(root[x]));\n }\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n // each node is a good path\n int n = vals.size(), ans = n;\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet{\n public:\n vector<int>parent,ranks;\n\n DisjointSet(int n){\n for(int i=0;i<=n;i++){\n parent.push_back(i);\n ranks.push_back(1);\n }\n }\n int getUltParent(int node){\n if(node==parent[node])return node;\n return parent[n... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet{\n public:\n vector<int>parent,ranks;\n\n DisjointSet(int n){\n for(int i=0;i<=n;i++){\n parent.push_back(i);\n ranks.push_back(1);\n }\n }\n int getUltParent(int node){\n if(node==parent[node])return node;\n return parent[n... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": " class Solution {\npublic:\n struct UnionFind {\n UnionFind(int n) : parent(n, 0) {\n for (int i = 0; i < n; i++) {\n parent[i] = i;\n }\n }\n int Find(int x) {\n int temp = x;\n while (parent[temp] != temp) {\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n struct UnionFind {\n UnionFind(int n) : parent(n, 0) {\n for (int i = 0; i < n; i++) {\n parent[i] = i;\n }\n }\n int Find(int x) {\n int temp = x;\n while (parent[temp] != temp) {\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n\tint find(vector<int>& root,int i) {\n\t\t//if(i==root[i]) return i;\n\t\t//root[i]=find(root,root[i]);\n\t\twhile(root[i] != i){\n root[i] = root[root[i]];\n i = root[i];\n }\n return i;\n\t}\n\tint numberOfGoodPaths(vector<int>& vals, vector... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n\tint find(vector<int>& y,int i) {\n\t\tif(i==y[i]) return i;\n\t\ty[i]=find(y,y[i]);\n\t\treturn y[i];\n\t}\n\tint numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n int n = vals.size(),m=edges.size(),ans=0;\n\t\tvector<vector<int>> x(n);\n\t\tvector<int... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n\tint find(vector<int>& y,int i) {\n\t\tif(i==y[i]) return i;\n\t\ty[i]=find(y,y[i]);\n\t\treturn y[i];\n\t}\n\tint numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n int n = vals.size(),m=edges.size(),ans=0;\n\t\tvector<vector<int>> x(n);\n\t\tvector<int... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n inline int\n numberOfGoodPaths(std::vector<int>& vals,\n const std::vector<std::vector<int>>& edges) noexcept {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n vals_ = std::move(... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n inline int\n numberOfGoodPaths(std::vector<int>& vals,\n const std::vector<std::vector<int>>& edges) noexcept {\n std::ios_base::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n vals_ = std::move(... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\nint par[100001], siize[100001];\nint find(int a) {\n\tif (par[a] == a) return a;\n\treturn par[a] = find(par[a]);\n}\n\n int numberOfGoodPaths(vector<int>& val, vector<vector<int>>& edges) {\n vector<vector<int>>v;\n int n=val.size();\n for(int i=0;i<val.s... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n int comb(int i) {\n return i * (i - 1) / 2;\n }\n int find(vector<int>& parent, int cur) {\n if (parent[cur] == -1) return cur;\n int rs = find(parent, parent[cur]);\n parent[cur] = rs;\n return rs;\n }\n int unionf(vector<int>& ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n\n int g[30000];\n int f(int x) {\n return g[x] = (g[x] == x ? x : f(g[x]));\n }\n\n void uni(int x, int y) {\n int fx = f(x);\n int fy = f(y);\n g[fx] = fy;\n }\n\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges)... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n const int n = vals.size();\n vector<vector<int>> tree(n);\n\n for (auto& e: edges) {\n tree[e[0]].push_back(e[1]);\n tree[e[1]].push_back(e[0]);\n }\n\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n\tint find(vector<int>& parent,int i) {\n\t\tif(i == parent[i]) \n return i;\n\t\treturn parent[i]=find(parent ,parent[i]);\n\t}\n\tint numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n int n = vals.size();\n int ans = 0;\n\t\tvector<ve... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "auto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n const int n = vals.size();\n vector<vector<int>> tree(n);\n\n for (auto&... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#ifdef LC_LOCAL\n#include \"parser.hpp\"\n#else\n#define dbg(...)\n#endif\n\n// ----- CHANGE FOR PROBLEM -----\ntemplate <invocable<int, int> F>\nstruct union_find {\n vector<int> par, size;\n F f;\n union_find(int n, F f) : par(n), size(n, 1), f(f) {\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "auto init = []()\n{ \n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n return 'c';\n}();\nclass Solution {\npublic:\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n const int n = vals.size();\n vector<vector<int>> tree(n);\n\n for (auto&... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n int findp(vector<int>& parent, int a) {\n if ( parent[a] == a ) return a;\n return parent[a] = findp(parent, parent[a]);\n }\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n int n = vals.size();\n vector<int> parent(... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n\t\tconst int n = vals.size();\n\t\tvector<vector<int>> g(n);\n\n\t\tfor (auto& e: edges) {\n\t\t\tg[e[0]].push_back(e[1]);\n\t\t\tg[e[1]].push_back(e[0]);\n\t\t}\n\n\t\tvector<int> ids(n), size(n), fa(n)... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n int find(vector<int> &parent, int idx){\n if(parent[idx]!=idx){\n parent[idx]=find(parent, parent[idx]);\n }\n return parent[idx];\n }\n \n void unions(vector<int>& parent, vector<int>& rank, int idx1, int idx2, int &ans, vector<int>& ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DSU {\n private:\n vector<int> parent;\n vector<int> rank;\n public:\n DSU(int n) {\n parent.resize(n);\n rank.resize(n);\n for(int i = 0; i<n; i++) {\n parent[i] = i;\n rank[i] = 1;\n }\n }\n\n int getParent(int node) {\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n int find_lab(int u, vector<int> &lab) {\n return (u == lab[u] ? u : lab[u] = find_lab(lab[u], lab));\n }\n int ans = 0;\n void unite(int mxv, int u, int v, vector<int> &sz, vector<int> &mx, vector<int> &lab, vector<int> &vals) {\n int paru = find_lab(u,... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\npublic:\n DisjointSet(int n): parent(n, -1), size(n, 1) {}\n\n void add(int x) {\n if (parent[x] < 0) parent[x] = x;\n }\n\n int root(int x) {\n if (parent[x] == x) return x;\n return parent[x] = root(parent[x]);\n }\n\n void merge(int x, int y) {... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class dsu{\n public:\n vector<int>par,siz;\n dsu(int n){\n par.resize(n);\n siz.resize(n,1);\n for(int i=0;i<n;i++) par[i]=i;\n } \n int findUpar(int u)\n {\n if(par[u]==u) return u;\n return par[u]=findUpar(par[u]);\n }\n void unio(int u,int v)\... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\n\npublic:\n DisjointSet(int n) {\n parent.resize(n, -1);\n count.resize(n, -1);\n \n }\n\n int Union(int v1, int v2) {\n int p1 = SearhAndCompress(v1);\n int p2 = SearhAndCompress(v2);\n if (p1 == p2) {\n return p1;\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\n\npublic:\n DisjointSet(int n) {\n parent.resize(n, -1);\n count.resize(n, -1);\n \n }\n\n int Union(int v1, int v2) {\n int p1 = SearhAndCompress(v1);\n int p2 = SearhAndCompress(v2);\n if (p1 == p2) {\n return p1;\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\n\npublic:\n DisjointSet(int n) {\n parent.resize(n, -1);\n count.resize(n, -1);\n \n }\n\n int Union(int v1, int v2) {\n int p1 = SearhAndCompress(v1);\n int p2 = SearhAndCompress(v2);\n if (p1 == p2) {\n return p1;\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": " class Solution {\n\tpublic:\n\t\tint find(vector<int>& parent,int a) //Finds parent of a\n\t\t{\n\t\t\tif(a==parent[a])\n\t\t\t\treturn a;\n\t\t\tparent[a]=find(parent,parent[a]);\n\t\t\treturn parent[a];\n\n\t\t}\n\t\tint numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n sor... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class Solution {\npublic:\n\n int find(vector<int> & parent,int a){\n if(parent[a] == a) return a;\n parent[a] = find(parent, parent[a]);\n return parent[a];\n }\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n sort(edges.begin(),edges.end(),[... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\npublic:\n DisjointSet(int n): parent(n, -1), size(n, 1) {}\n\n void add(int x) {\n if (parent[x] < 0) parent[x] = x;\n }\n\n int root(int x) {\n if (parent[x] == x) return x;\n return parent[x] = root(parent[x]);\n }\n\n void merge(int x, int y) {... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\npublic:\n DisjointSet(int n): parent(n, -1), size(n, 1) {}\n\n void add(int x) {\n if (parent[x] < 0) parent[x] = x;\n }\n\n int root(int x) {\n if (parent[x] == x) return x;\n return parent[x] = root(parent[x]);\n }\n\n void merge(int x, int y) {... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\npublic:\n DisjointSet(int n): parent(n, -1), size(n) {}\n\n void add(int x) {\n parent[x] = x;\n size[x] = 1;\n }\n\n int root(int x) {\n if (parent[x] == x) return x;\n return parent[x] = root(parent[x]);\n }\n\n void merge(int x, int y) {... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 0 | {
"code": "class DisjointSet {\npublic:\n DisjointSet(int n): parent(n, -1), size(n) {}\n\n void add(int x) {\n parent[x] = x;\n size[x] = 1;\n }\n\n int root(int x) {\n if (parent[x] == x) return x;\n return parent[x] = root(parent[x]);\n }\n\n void merge(int x, int y) {... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 1 | {
"code": "class DisjointSet {\n\npublic:\n DisjointSet(int label) : label(label), parent(nullptr), count(1) {\n }\n\n void* Union(DisjointSet* other) {\n DisjointSet* p1 = this->SearhAndCompress();\n DisjointSet* p2 = other->SearhAndCompress();\n if (p1 == p2) {\n return p1;\... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 1 | {
"code": "class DisjointSet {\n\npublic:\n DisjointSet(int label) : label(label), parent(nullptr), count(1) {\n }\n\n void* Union(DisjointSet* other) {\n DisjointSet* p1 = this->SearhAndCompress();\n DisjointSet* p2 = other->SearhAndCompress();\n if (p1 == p2) {\n return p1;\... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 1 | {
"code": "class Solution {\npublic:\n struct DSU{\n vector<int> parent;\n vector<int> size;\n\n DSU(int n){\n for(int i = 0; i < n; i++){\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int get_parent(int u){\n ... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 1 | {
"code": "class Solution {\npublic:\n int numberOfGoodPaths(vector<int>& vals, vector<vector<int>>& edges) {\n \n int n = vals.size();\n vector<int> par(n),sz(n);\n vector<map<int,int>> freq(n);\n\n auto cmp = [&](vector<int> &a,vector<int> &b){\n return max(vals[a[0]... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 1 | {
"code": "class DisjointSet {\n\npublic:\n DisjointSet(int label) : label(label), parent(nullptr), count(1) {\n }\n\n void* Union(DisjointSet* other) {\n DisjointSet* p1 = this->SearhAndCompress();\n DisjointSet* p2 = other->SearhAndCompress();\n if (p1 == p2) {\n return p1;\... |
2,505 | <p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>vals</code> of length <code>n</code> where <code>vals[... | 1 | {
"code": "class DisjointSet {\n\npublic:\n DisjointSet(int label) : label(label), parent(nullptr), count(1) {\n }\n\n void* Union(DisjointSet* other) {\n DisjointSet* p1 = this->SearhAndCompress();\n DisjointSet* p2 = other->SearhAndCompress();\n if (p1 == p2) {\n return p1;\... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.