id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,925 | <p>You are given an array <code>nums</code> that consists of non-negative integers. Let us define <code>rev(x)</code> as the reverse of the non-negative integer <code>x</code>. For example, <code>rev(123) = 321</code>, and <code>rev(120) = 21</code>. A pair of indices <code>(i, j)</code> is <strong>nice</strong> if it ... | 3 | {
"code": "class Solution {\npublic:\n int factorial(int n){\n if(n == 0 || n == 1) return 1;\n int fact = 1;\n for(int i = 2;i<=n;i++){\n fact *= i;\n }\n return fact;\n }\n int combination(int freq, int n){\n return factorial(freq)/(factorial(n)*factoria... |
1,925 | <p>You are given an array <code>nums</code> that consists of non-negative integers. Let us define <code>rev(x)</code> as the reverse of the non-negative integer <code>x</code>. For example, <code>rev(123) = 321</code>, and <code>rev(120) = 21</code>. A pair of indices <code>(i, j)</code> is <strong>nice</strong> if it ... | 3 | {
"code": "class Solution {\npublic:\n int factorial(int n){\n if(n == 0 || n == 1) return 1;\n int fact = 1;\n for(int i = 2;i<=n;i++){\n fact *= i;\n }\n return fact;\n }\n int combination(int freq, int n){\n return factorial(freq)/(factorial(n)*factoria... |
1,925 | <p>You are given an array <code>nums</code> that consists of non-negative integers. Let us define <code>rev(x)</code> as the reverse of the non-negative integer <code>x</code>. For example, <code>rev(123) = 321</code>, and <code>rev(120) = 21</code>. A pair of indices <code>(i, j)</code> is <strong>nice</strong> if it ... | 3 | {
"code": "class Solution {\npublic:\n int reverse(int n){\n int r = 0;\n while(n > 0){\n int dig = n%10;\n r = r*10 + dig;\n n /= 10;\n }\n return r;\n }\n\n int countNicePairs(vector<int>& nums) {\n int n = nums.size();\n vector<int... |
1,925 | <p>You are given an array <code>nums</code> that consists of non-negative integers. Let us define <code>rev(x)</code> as the reverse of the non-negative integer <code>x</code>. For example, <code>rev(123) = 321</code>, and <code>rev(120) = 21</code>. A pair of indices <code>(i, j)</code> is <strong>nice</strong> if it ... | 3 | {
"code": "class Solution {\npublic:\nint mod=1e9+7;\nint rev(int n){\n string s = to_string(n);\n reverse(s.begin(),s.end());\n int i=0;\n while(i<s.length()){\n if(s[i]!=0)break;\n i++;\n }\n s = s.substr(i);\n return stoi(s);\n}\n int countNicePairs(vector<int>& nums) {\n ... |
1,925 | <p>You are given an array <code>nums</code> that consists of non-negative integers. Let us define <code>rev(x)</code> as the reverse of the non-negative integer <code>x</code>. For example, <code>rev(123) = 321</code>, and <code>rev(120) = 21</code>. A pair of indices <code>(i, j)</code> is <strong>nice</strong> if it ... | 3 | {
"code": "class Solution {\npublic:\n\n long long findRev(long long val)\n {\n long long ans = 0;\n while(val > 0)\n {\n ans = ans * 10 + val % 10;\n val /= 10;\n }\n\n return ans;\n }\n\n int countNicePairs(vector<int>& nums) {\n \n ... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 1 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "class Solution {\npublic:\n int fun(TreeNode* root) //function to return it's value if exist or return 0\n {\n return root?root->val:0; \n }\n int sumEvenGrandparent(TreeNode* root) {\n if(!root) return 0; //returns 0 if root is NULL\n queue<TreeNode*> q;\n q.pus... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "class Solution {\npublic:\n int sumEvenGrandparent(TreeNode* root) {\n\n int sum = 0 ;\n\n vector<TreeNode*> v; \n\n helper(root,v) ;\n\n cout<<v.size()<<endl ;\n\n for(int i = 0 ; i<v.size() ; i++){\n helper2(v[i],sum);\n }\n\n return sum ;\n... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "static auto _ = []() {\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n return nullptr;\n}();\n\n\nclass Solution {\npublic:\n int sumEvenGrandparent(TreeNode* root) {\n\n int sum = 0 ;\n\n vector<TreeNode*> v; \n\n helper(root,v) ;\n\n for(int i = 0 ; i<v.size() ; i+... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "class Solution {\npublic:\n int grandsum(TreeNode* node){\n int ans = 0;\n if(node -> left){\n TreeNode* temp = node -> left;\n if(temp -> left) ans += temp -> left -> val;\n if(temp -> right) ans += temp -> right -> val;\n }\n if(node -> righ... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,243 | <p>Given the <code>root</code> of a binary tree, return <em>the sum of values of nodes with an <strong>even-valued grandparent</strong></em>. If there are no nodes with an <strong>even-valued grandparent</strong>, return <code>0</code>.</p>
<p>A <strong>grandparent</strong> of a node is the parent of its parent if it ... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,441 | <p>Given 3 positives numbers <code>a</code>, <code>b</code> and <code>c</code>. Return the minimum flips required in some bits of <code>a</code> and <code>b</code> to make ( <code>a</code> OR <code>b</code> == <code>c</code> ). (bitwise OR operation).<br />
Flip operation consists of change <strong... | 1 | {
"code": "class Solution {\npublic:\n int minFlips(int a, int b, int c) {\n int flips=0;\n while(a!=0 || b!=0 || c!=0){\n if((c&1)==1){\n if((a&1)==0 && (b&1)==0){\n flips++;\n }\n }\n else{\n if((a&1)==... |
1,441 | <p>Given 3 positives numbers <code>a</code>, <code>b</code> and <code>c</code>. Return the minimum flips required in some bits of <code>a</code> and <code>b</code> to make ( <code>a</code> OR <code>b</code> == <code>c</code> ). (bitwise OR operation).<br />
Flip operation consists of change <strong... | 1 | {
"code": "class Solution {\npublic:\n int minFlips(int a, int b, int c) {\n int flip=0;\n while(a or b or c){\n if(c&1){\n if(!(a&1) and !(b&1)){\n flip++;\n }\n }\n else{\n if(a&1){\n ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\npublic:\n\n int find(int A[],int X)\n{\n int i=A[X];\n while(i!=A[i]){\n i=A[i];\n }\n return i;\n}\nvoid unionSet(int A[],int X,int Z)\n{\n\tint a=find(A,X);\n\tint b=find(A,Z);\n\tA[a]=b;}\n int makeConnected(int n, vector<vector<int>>& connection... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\npublic:\n /*void dfs(int start,vector<vector<int>>& connections,vector<bool> &visited){\n visited[start]=true;\n for(int i=0;i<connections.size();i++){\n if(connections[i][0]==start && visited[connections[i][1]]==false){\n //visited[connections[i... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\npublic:\n int find(int x, vector<int>& par) {\n \t\treturn par[x] == x ? x : find(par[x], par);\n \t}\n int makeConnected(int n, vector<vector<int>>& edges) {\n vector<int>par(n, 0);\n \t\tfor (int i = 0; i <n; i++)\n \t\t\tpar[i] = i;\n int ans=0;\n \t\tfor (int i = 0... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "\nclass Solution {\npublic:\n int makeConnected(int n, vector<vector<int>>& connections) {\n int m = connections.size();\n if (m < n - 1) return -1;\n \n vector<int> parent(n);\n for (int i = 0; i < n; i++) parent[i] = i;\n \n function<int(int)> find = [&... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\n\n class Disjointset{\n vector<int>parent, size;\n public:\n Disjointset(int n){\n parent.resize(n+1, 0);\n size.resize(n+1, 1);\n for(int i=0; i<=n; i++){\n parent[i]=i;\n }\n }\n int findUpa... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\npublic:\n\n int par(int node, vector<int> &parent){\n if(node == parent[node]){\n return node;\n }\n return parent[node] = par(parent[node],parent);\n }\n\n void unionSize(int node1, int node2, vector<int> &par, vector<int> &siz){\n int par1... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\npublic:\n Solution(){\n ios_base::sync_with_stdio(false);\n cin.tie(NULL); cout.tie(NULL);\n }\n int makeConnected(int n, vector<vector<int>>& connections) {\n int len = connections.size();\n if (len < n-1) return -1;\n\n vector<int> froot(n), s... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class DisSet{\n public:\n vector<int> parent,size;\n DisSet(int n){\n size.resize(n+1,1);\n parent.resize(n+1);\n for(int i=0;i<=n;i++){\n parent[i]=i;\n }\n }\n int findParent(int node){\n if(parent[node]==node) return node;\n return pare... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class DisJointSet{\n public:\n \n vector<int> rank,size,parent;\n \n DisJointSet(int n){\n rank.resize(n,0);\n size.resize(n,1);\n parent.resize(n);\n \n for(int i=0;i<n;i++){\n parent[i]=i;\n }\n }\n \n int findParent(int i){\n ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\npublic:\n vector<int> rank, par;\n Solution(){}\n Solution(int n){\n rank = vector<int> (n, 1);\n for(int i=0; i<n; i++) par.push_back(i);\n }\n\n int find(int x){\n if(par[x] == x) return x;\n return par[x] = find(par[x]);\n }\n\n void uni... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class DSU{\n public:\n vector<int> rank,par,size;\n int len=0;\n DSU(int n){\n rank.resize(n,1);\n size.resize(n,1);\n par.resize(n);\n for(int i=0;i<n;i++){\n par[i]=i;\n }\n len=n;\n }\n \n int find(int x){\n if(par[x]==x) ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class disjointSet{\n private:\n vector<int> rank, parent, size;\n public:\n disjointSet(int n){\n rank.resize(n+1);\n size.resize(n+1);\n parent.resize(n+1);\n for(int i=0; i<=n; ++i){\n rank[i]=0;\n size[i]=1;\n ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class DSU{\n\npublic:\n \n int n;\n vector<int> parent;\n vector<int> size;\n\n void make(int n)\n {\n \n for(int i=0; i<n; i++)\n {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int find(int n)\n {\n if(parent[n]... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 0 | {
"code": "class Solution {\n class UF{\n public:\n vector<int> parent;\n vector<int> rank;\n vector<int> edges;\n UF(int n){\n for(int i = 0; i < n; i++){\n parent.push_back(i);\n rank.push_back(1);\n }\n }\n\n in... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class DSU{\n\npublic:\n \n int n;\n vector<int> parent;\n vector<int> size;\n\n void make(int n)\n {\n \n for(int i=0; i<n; i++)\n {\n parent.push_back(i);\n size.push_back(1);\n }\n }\n\n int find(int n)\n {\n if(parent[n]... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n std::vector<int> p;\n std::vector<int> s;\n\n int leader(int v) {\n return (p[v] == v) ? v : p[v] = leader(p[v]);\n }\n\n bool unite(int a, int b) {\n a = leader(a);\n b = leader(b);\n if (a == b) {\n return false;\n }... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\n class disjoint {\n vector<int> size,parent;\n public:\n disjoint(int n){\n size.resize(n+1);\n parent.resize(n+1);\n for(int i=0;i<=n;i++){\n parent[i]=i;\n size[i]=1;\n }\n }\n int findpar(int u){\n if(u==parent[... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n std::vector<int> p;\n std::vector<int> s;\n\n int leader(int v) {\n return (p[v] == v) ? v : p[v] = leader(p[v]);\n }\n\n bool unite(int a, int b) {\n a = leader(a);\n b = leader(b);\n if (a == b) {\n return false;\n }... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n\n vector<int>parent;\n vector<int>size;\n\n int findPar(int a)\n {\n if(a==parent[a])return a;\n return parent[a]=findPar(parent[a]);\n }\n\n void DSU(int a,int b)\n {\n a=findPar(a);\n b=findPar(b);\n\n if(a==b)return;\n\n... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n vector<int> v;\n int Find(int x){\n if(v[x] == x) return x;\n return Find(v[x]);\n }\n void Union(int x, int y){\n int f1 = Find(x), f2 = Find(y);\n if(f1 == f2) return;\n v[f2] = f1;\n }\n int makeConnected(int n, vector<vect... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n int find(int a[], int x){\n while(x!=a[x]) x = a[x];\n return a[x];\n }\n\n void union_find(int a[], int x, int y){\n int X = find(a,x);\n int Y = find(a,y);\n if(X!=Y)\n a[X] = Y; \n }\n\n int makeConnected(int n, vector<... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n\n int findUp(int node,int par[])\n {\n if(node==par[node])\n return node;\n else\n return par[node]=findUp(par[par[node]],par);\n }\n int cnt_extra=0;\n void makeUnion(int u,int v,int par[],int size[])\n {\n int ulpu=findUp(u,... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n vector<int>parents;\n int find(int x){\n if(parents[x]==x)\n return x;\n parents[x]=find(parents[x]);\n return parents[x]; \n }\n int makeConnected(int n, vector<vector<int>>& connections) {\n int len= connections.size();\n\n ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\n vector<int>parent;\n\n int find(int x){\n if(parent[x]==x){\n return x;\n }\n return parent[x]=find(parent[x]);\n }\n void unionPar(int x,int y){\n int parx=find(x);\n int pary=find(y);\n parent[parx]=pary;\n }\n\npublic... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class disjoint{\n public:\n vector<int>parent,size;\n \n disjoint(int n){\n parent.resize(n);\n for(int i=0;i<n;i++)parent[i]=i;\n size.resize(n,1);\n }\n \n int findParent(int u){\n if(parent[u]==u)return u;\n return parent[u]=findParent(parent[u]);\... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class DisjointSet {\n vector<int> size;\n vector<int> parent;\n\n public:\n DisjointSet(int n) {\n size.resize(n+1);\n parent.resize(n+1);\n for(int i=0; i<=n; i++) {\n parent[i]=i;\n size[i]=1;\n }\n }\n ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class Solution {\npublic:\n\n class Disjointset{\n public:\n vector<int> rank, parent;\n \n Disjointset(int n){\n rank.resize(n, 0);\n parent.resize(n);\n\n for(int i = 0; i<n; i++) parent[i] = i;\n }\n\n ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 1 | {
"code": "class DisjointSet {\npublic:\n vector<int> size, parent;\n\n DisjointSet(int n) {\n size.resize(n + 1);\n parent.resize(n + 1);\n for (int i = 0; i <= n; i++) {\n parent[i] = i;\n size[i] = 1;\n }\n }\n\n int findUPar(int node) {\n if (no... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 2 | {
"code": "class DisjointSet{\n \n public:\n vector<int> rank,parent,size;\n DisjointSet(int n){\n rank.resize(n+1,0);\n parent.resize(n+1,0);\n size.resize(n+1,0);\n for(int i=0;i<=n;i++){\n parent[i]=i;\n size[i]=1;\n }\n }\n int findUPar(in... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 2 | {
"code": "class DisjointSet {\npublic:\n vector<int> rank, parent, size;\n DisjointSet(int n) {\n rank.resize(n + 1, 0);\n parent.resize(n + 1);\n size.resize(n + 1);\n for (int i = 0; i <= n; i++) {\n parent[i] = i;\n size[i] = 1;\n }\n }\n\n int ... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 2 | {
"code": "class DisjointSet\n{\n public:\n vector<int> size, parent, rank;\n\n DisjointSet(int n)\n {\n size.resize(n, 1);\n rank.resize(n, 0);\n parent.resize(n);\n for(int i = 0; i < n; i++) parent[i] = i;\n }\n\n int findParent(int node)\n {\n if(node == par... |
1,442 | <p>There are <code>n</code> computers numbered from <code>0</code> to <code>n - 1</code> connected by ethernet cables <code>connections</code> forming a network where <code>connections[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> represents a connection between computers <code>a<sub>i</sub></code> and <code>b<sub>i</sub>... | 2 | {
"code": "class DisjointSet\n{\n public:\n vector<int> size, parent, rank;\n\n DisjointSet(int n)\n {\n size.resize(n, 1);\n rank.resize(n, 0);\n parent.resize(n);\n for(int i = 0; i < n; i++) parent[i] = i;\n }\n\n int findParent(int node)\n {\n if(node == par... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.