question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
delete-columns-to-make-sorted-iii
NOT LIS intution
not-lis-intution-by-shivral-9kpx
\n Add your space complexity here, e.g. O(n) \n\n# Code\n\nclass Solution:\n def minDeletionSize(self, strs: List[str]) -> int:\n strs=list(map(list,s
shivral
NORMAL
2023-04-28T06:43:26.467849+00:00
2023-04-28T06:43:26.467882+00:00
55
false
\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def minDeletionSize(self, strs: List[str]) -> int:\n strs=list(map(list,strs))\n n=len(strs[0])\n def check(i,last):\n if last==-1 or i>=n:\n return True\n for s in str...
0
0
['Python3']
0
delete-columns-to-make-sorted-iii
Python solution in 5 lines
python-solution-in-5-lines-by-metaphysic-b76q
Intuition\n Describe your first thoughts on how to solve this problem. \nThis problem is identical to the classic longest non-decreasing subsequence. \nThe prob
metaphysicalist
NORMAL
2023-04-16T19:58:31.281754+00:00
2023-04-16T19:58:31.281786+00:00
64
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem is identical to the classic longest non-decreasing subsequence. \nThe problem can be efficiently solved in binary search. \nDue to the small input size, the solution based on the slower DP algorithm can also be accepted. \nTh...
0
0
['Dynamic Programming', 'Python3']
0
delete-columns-to-make-sorted-iii
DP LIS (beats 100%)
dp-lis-beats-100-by-n1shadh-u4n4
Intuition\n- Use Longest Increasing subsequence concept.\n- Remember that this LIS must have the same index elements across all the strings. \n\n# Complexity\n-
N1shadh
NORMAL
2023-04-02T10:43:03.043402+00:00
2023-04-02T10:43:03.043437+00:00
98
false
# Intuition\n- Use Longest Increasing subsequence concept.\n- Remember that this LIS must have the same index elements across all the strings. \n\n# Complexity\n- Time complexity: O(n*m^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(m^2)\n<!-- Add your space complexity here, e.g. $$O...
0
0
['Dynamic Programming', 'Greedy', 'C++']
0
delete-columns-to-make-sorted-iii
c++ simple and explained dp solution tabulation technique
c-simple-and-explained-dp-solution-tabul-i1x6
Intuition\n Describe your first thoughts on how to solve this problem. \nI can consider a LIS only if it is made by same set of indices that\'swhy all strings
vedantnaudiyal
NORMAL
2023-03-13T12:20:43.284875+00:00
2023-03-13T12:20:43.284911+00:00
59
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nI can consider a LIS only if it is made by same set of indices that\'swhy all strings ith character must be greater than its prev character(jth which is being considered at a time from 0->i-1) to consider LIS of 1+ greater length than p...
0
0
['C++']
0
delete-columns-to-make-sorted-iii
Javascript - DP
javascript-dp-by-faustaleonardo-kh0l
Code\n\n/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function (strs) {\n const n = strs.length;\n const m = strs[0].length;
faustaleonardo
NORMAL
2023-02-22T00:44:07.448055+00:00
2023-02-22T00:44:15.551201+00:00
41
false
# Code\n```\n/**\n * @param {string[]} strs\n * @return {number}\n */\nvar minDeletionSize = function (strs) {\n const n = strs.length;\n const m = strs[0].length;\n const dp = new Array(m).fill(1);\n\n for (let colOne = 0; colOne < m; colOne++) {\n for (let colTwo = 0; colTwo < colOne; colTwo++) {\n for (l...
0
0
['Dynamic Programming', 'JavaScript']
0
delete-columns-to-make-sorted-iii
Best time complexity C++ solution
best-time-complexity-c-solution-by-85370-v3n2
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
8537046703
NORMAL
2023-02-20T18:31:41.529486+00:00
2023-02-20T18:31:41.529532+00:00
67
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Array', 'Math', 'String', 'C++']
0
delete-columns-to-make-sorted-iii
[golang] dp
golang-dp-by-vl4deee11-r9ey
\nvar mem [102][102]int\n\nfunc minDeletionSize(strs []string) int {\n\n\tfor i := 0; i < 102; i++ {\n\t\tfor j := 0; j < 102; j++ {\n\t\t\tmem[i][j] = -1\n\t\t
vl4deee11
NORMAL
2023-02-03T03:54:32.002072+00:00
2023-02-03T03:54:32.002106+00:00
17
false
```\nvar mem [102][102]int\n\nfunc minDeletionSize(strs []string) int {\n\n\tfor i := 0; i < 102; i++ {\n\t\tfor j := 0; j < 102; j++ {\n\t\t\tmem[i][j] = -1\n\t\t}\n\t}\n\tvar dp func(i, pi int) int\n\tdp = func(i, pi int) int {\n\t\tif i >= len(strs[0]) {\n\t\t\treturn 0\n\t\t}\n\t\tl := pi\n\t\tif pi == -1 {\n\t\t\t...
0
0
[]
0
delete-columns-to-make-sorted-iii
Same as LIS
same-as-lis-by-roboto7o32oo3-4l9h
Complexity\n- Time complexity: O(n^2*m)\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n int minDeletionSize(vector<string>& strs) {\n
roboto7o32oo3
NORMAL
2023-01-13T11:17:17.441196+00:00
2023-01-13T11:17:17.441236+00:00
79
false
# Complexity\n- Time complexity: $$O(n^2*m)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n int minDeletionSize(vector<string>& strs) {\n int m=strs.size(), n=strs[0].size();\n\n vector<int> dp(n, 1);\n\n for(int i=1; i<n; i++) {\n for(int j=0; j<i; j++) {\...
0
0
['Dynamic Programming', 'C++']
0
delete-columns-to-make-sorted-iii
Just a runnable solution
just-a-runnable-solution-by-ssrlive-hwcy
Code\n\nimpl Solution {\n pub fn min_deletion_size(strs: Vec<String>) -> i32 {\n let m = strs.len();\n let n = strs[0].len();\n let mut
ssrlive
NORMAL
2023-01-05T05:41:37.773881+00:00
2023-01-05T05:41:37.773931+00:00
43
false
# Code\n```\nimpl Solution {\n pub fn min_deletion_size(strs: Vec<String>) -> i32 {\n let m = strs.len();\n let n = strs[0].len();\n let mut res = n as i32 - 1;\n let mut dp = vec![1; n];\n for j in 0..n {\n for i in 0..j {\n let mut k = 0;\n ...
0
0
['Rust']
0
delete-columns-to-make-sorted-iii
C++, top-down DP approach
c-top-down-dp-approach-by-pavlot-w07y
\nclass Solution {\npublic:\n int minDeletionSize( vector<string>& strs ) {\n const int m = strs.size();\n const int n = strs[0].length();\
pavlot
NORMAL
2022-12-03T21:46:31.625999+00:00
2022-12-03T21:53:36.130016+00:00
116
false
```\nclass Solution {\npublic:\n int minDeletionSize( vector<string>& strs ) {\n const int m = strs.size();\n const int n = strs[0].length();\n\n std::vector<std::vector<int>> cache( n,std::vector<int>( n + 1,-1 ) );\n\n const std::function<int(int,int)> dfs = [&]( int idx, int pr...
0
0
['Dynamic Programming', 'C++']
0
delete-columns-to-make-sorted-iii
[C++] longest path in a graph
c-longest-path-in-a-graph-by-ivan-2727-n224
Build a graph where each vertex corresponds to an index and there is an edge between indices i and j if i < j and they are compatible, i.e. for all strings, s[i
ivan-2727
NORMAL
2022-09-27T22:39:00.130035+00:00
2022-09-27T22:39:00.130063+00:00
27
false
Build a graph where each vertex corresponds to an index and there is an edge between indices `i` and `j` if `i < j` and they are compatible, i.e. for all strings, `s[i] <= s[j]`. This is a directed acycling graph and each resulting string after deletion of minimum amount of indices will have the length of the longest p...
0
0
['Depth-First Search', 'Graph']
0
delete-columns-to-make-sorted-iii
C++ Dynamic programming solution | Beats 97%
c-dynamic-programming-solution-beats-97-7n0um
Subproblems: S(index)=Minimum length for strs[i][index:] for all i in [0,strs[0].size()-1]\n\nRelation: S(index)=min{next-index-1+S(next) where next belongs to
Diavolos
NORMAL
2022-09-13T07:23:41.607468+00:00
2022-09-13T07:24:15.745657+00:00
126
false
Subproblems: S(index)=Minimum length for strs[i][index:] for all i in [0,strs[0].size()-1]\n\nRelation: S(index)=min{next-index-1+S(next) **where** next **belongs to** [index+1:end) **such that** strs[i][next]>=strs[i][index] **for all** i **belongs to** [0,strs.size())}\nThe reason why I have added next-index-1 to the...
0
0
['Dynamic Programming', 'Memoization', 'C', 'C++']
0
delete-columns-to-make-sorted-iii
Python Recursive LIS: 96% time, 13% space
python-recursive-lis-96-time-13-space-by-06n6
```\nclass Solution:\n def minDeletionSize(self, strs: List[str]) -> int:\n n = len(strs[0])\n \n def checkRest(idx1, idx2):\n
hqz3
NORMAL
2022-09-09T03:16:38.039785+00:00
2022-09-09T03:16:38.039844+00:00
29
false
```\nclass Solution:\n def minDeletionSize(self, strs: List[str]) -> int:\n n = len(strs[0])\n \n def checkRest(idx1, idx2):\n for i in range(1, len(strs)):\n if not strs[i][idx1] <= strs[i][idx2]: return False\n return True\n \n @cache\...
0
0
['Python']
0
delete-columns-to-make-sorted-iii
simpe dp
simpe-dp-by-innsharsh-qnvn
\nclass Solution {\npublic:\n int dp[102][102];\n int solve(vector<string> &strs,int ind,int prev_ind){\n int n=strs.size();\n if(ind<0){\n
innsharsh
NORMAL
2022-09-07T05:39:27.591996+00:00
2022-09-07T05:39:27.592042+00:00
14
false
```\nclass Solution {\npublic:\n int dp[102][102];\n int solve(vector<string> &strs,int ind,int prev_ind){\n int n=strs.size();\n if(ind<0){\n return 0;\n }\n if(dp[ind][prev_ind+1]!=-1){\n return dp[ind][prev_ind+1];\n }\n if(prev_ind==-1){\n ...
0
0
['Dynamic Programming']
0
delete-columns-to-make-sorted-iii
✅CPP || Intuition + Comments || DFS
cpp-intuition-comments-dfs-by-ajinkyakam-hdcu
Intuition : For every index, iterate over all strings and find all valid character indexes. A valid character at index j for and index i (for j>i) is defined as
ajinkyakamble332
NORMAL
2022-08-26T07:06:20.046633+00:00
2022-08-26T07:06:20.046672+00:00
60
false
Intuition : For every index, iterate over all strings and find all valid character indexes. A valid character at index j for and index i (for j>i) is defined as char[j] >=char[i] for all strings. \n\nThis is the preprocesing to find all valid indexes. Now, our problem is reduced to find largest such valid subsequence.\...
0
0
[]
0
delete-columns-to-make-sorted-iii
✅ Cpp || Recursion || Dfs + memoization
cpp-recursion-dfs-memoization-by-ferocio-xi6n
\nclass Solution {\npublic:\n int n;\n unordered_map<int,int> memo;\n long long dfs(vector<set<int>> &adj,string &vis,int i){\n long long temp=0
ferociouscentaur
NORMAL
2022-08-26T06:31:28.224842+00:00
2022-08-26T06:31:28.224877+00:00
56
false
```\nclass Solution {\npublic:\n int n;\n unordered_map<int,int> memo;\n long long dfs(vector<set<int>> &adj,string &vis,int i){\n long long temp=0;\n \n if(memo.find(i)!=memo.end()) return memo[i];\n for(int j = i;j<n;j++){\n if(!vis[j]){\n vis[j] = 1;\n ...
0
0
['Depth-First Search', 'Recursion', 'Memoization']
0
delete-columns-to-make-sorted-iii
Easy Java Solution | LIS Variation | Dp
easy-java-solution-lis-variation-dp-by-_-7g6e
\n\t\n\tpublic int minDeletionSize(String[] strs) {\n\t int n = strs.length;\n int m = strs[0].length();\n int[] dp = new int[m];\n \n
_shashank_
NORMAL
2022-08-14T09:41:06.987171+00:00
2022-08-14T09:45:37.174405+00:00
91
false
\n\t\n\tpublic int minDeletionSize(String[] strs) {\n\t int n = strs.length;\n int m = strs[0].length();\n int[] dp = new int[m];\n \n int overallMax = 0;\n for(int i=0;i<m;i++){\n dp[i] = 1;\n for(int j=0;j<i;j++){\n \n if(isVali...
0
0
['Java']
0
delete-columns-to-make-sorted-iii
Python Longest Increasing Subsequence solution
python-longest-increasing-subsequence-so-bcxr
\n def minDeletionSize(self, strs: List[str]) -> int:\n m = len(strs[0])\n dp = [1]*m\n\t\t#dp[i] refers to the length of LIS beginning at i \n
vincent_great
NORMAL
2022-06-30T02:41:49.976866+00:00
2022-06-30T02:41:49.976895+00:00
80
false
```\n def minDeletionSize(self, strs: List[str]) -> int:\n m = len(strs[0])\n dp = [1]*m\n\t\t#dp[i] refers to the length of LIS beginning at i \n for i in range(m):\n for j in range(i+1, m):\n incresing = True\n for s in strs:\n if s[i...
0
0
[]
0
delete-columns-to-make-sorted-iii
Simple variation of Longest Increasing Subsequence problem
simple-variation-of-longest-increasing-s-62a3
\nclass Solution {\npublic:\n int minDeletionSize(vector<string>& strs) {\n \n int i, j, k, n = strs[0].size(), m = strs.size(), ans = 0;\n
kunalanand24154321
NORMAL
2022-05-26T19:00:59.632639+00:00
2022-05-26T19:00:59.632687+00:00
63
false
```\nclass Solution {\npublic:\n int minDeletionSize(vector<string>& strs) {\n \n int i, j, k, n = strs[0].size(), m = strs.size(), ans = 0;\n \n vector<int>dp(n+1);\n \n for(i = 0; i < n; i++) {\n dp[i] = 1;\n for (j = i - 1; j >= 0; j--) {\n ...
0
0
['Dynamic Programming']
0
delete-columns-to-make-sorted-iii
Top-Down DP
top-down-dp-by-unluckyguy-ubc8
\nclass Solution {\npublic:\n bool isGreater(vector<string> &strs, int prev, int curr){\n if(prev < 0){\n return true;\n }\n
UnLuckyGuy
NORMAL
2022-03-26T05:41:27.340651+00:00
2022-03-26T05:41:27.340681+00:00
96
false
```\nclass Solution {\npublic:\n bool isGreater(vector<string> &strs, int prev, int curr){\n if(prev < 0){\n return true;\n }\n int sz = strs.size();\n for(int i = 0; i < sz; i++){\n int num1 = strs[i][prev] - \'a\';\n int num2 = strs[i][curr] - \'a\';\n ...
0
0
[]
0
delete-columns-to-make-sorted-iii
c++(156ms 17%) bitset & dp
c156ms-17-bitset-dp-by-zx007pi-3llt
Runtime: 156 ms, faster than 17.04% of C++ online submissions for Delete Columns to Make Sorted III.\nMemory Usage: 23.5 MB, less than 17.05% of C++ online subm
zx007pi
NORMAL
2022-01-15T10:12:37.249191+00:00
2022-01-15T10:12:37.249222+00:00
104
false
Runtime: 156 ms, faster than 17.04% of C++ online submissions for Delete Columns to Make Sorted III.\nMemory Usage: 23.5 MB, less than 17.05% of C++ online submissions for Delete Columns to Make Sorted III.\n```\nclass Solution {\npublic:\n vector<bitset<100>>t;\n \n void fill_table(vector<string>& strs){\n for(a...
0
0
['C', 'C++']
0
delete-columns-to-make-sorted-iii
C++ || O(n^2*m) || Simple DP || Fast || Notes
c-on2m-simple-dp-fast-notes-by-aholtzman-74dg
\n// For every index in the string find the longest increasing substrings from 0 to the index (the check must be susseful for all the strings)\n// Find the long
aholtzman
NORMAL
2021-12-24T18:55:51.950976+00:00
2021-12-25T22:37:02.823125+00:00
124
false
```\n// For every index in the string find the longest increasing substrings from 0 to the index (the check must be susseful for all the strings)\n// Find the longest substring for all the indexes\n// The minimum deletion equel to string length minus the largest substring\n// Use the DP array to keep the max substring ...
0
0
[]
0
delete-columns-to-make-sorted-iii
Intuitive
intuitive-by-thinkinoriginal-ggx0
\nclass Solution {\npublic:\n int minDeletionSize(vector<string>& strs) {\n int slen = strs[0].size();\n vector<int> dp(slen, 1);\n int
thinkinoriginal
NORMAL
2021-10-15T15:52:27.243003+00:00
2021-10-15T15:52:27.243047+00:00
71
false
```\nclass Solution {\npublic:\n int minDeletionSize(vector<string>& strs) {\n int slen = strs[0].size();\n vector<int> dp(slen, 1);\n int res = 1;\n \n for (int i = 1; i < slen; i++) {\n for (int j = 0; j < i; j++) {\n\t\t \n\t\t // Bellow is the different from the o...
0
0
['C++']
0
delete-columns-to-make-sorted-iii
EASY C++ solution
easy-c-solution-by-aaditya-pal-0lu6
c++\nclass Solution {\npublic:\n vector<string>str;\n vector<vector<int>>dp;\n int findmax(int id,int prev){\n //Base case\n if(id>=str[0
aaditya-pal
NORMAL
2021-06-29T05:41:13.490721+00:00
2021-06-29T05:41:13.490763+00:00
138
false
```c++\nclass Solution {\npublic:\n vector<string>str;\n vector<vector<int>>dp;\n int findmax(int id,int prev){\n //Base case\n if(id>=str[0].size()){\n return 0;\n }\n //if id==0\n int ans = 0;\n if(prev==-1){\n ans = max(ans,1 + findmax(id+1,id)...
0
0
[]
0
delete-columns-to-make-sorted-iii
java 7ms solution
java-7ms-solution-by-shivam_gupta-7rqc
java code is:\n# \n\nclass Solution {\n public int minDeletionSize(String[] strs) {\n //0-current-delete,1-current-kept;\n int n=strs[0].length
shivam_gupta_
NORMAL
2021-05-20T03:38:08.592405+00:00
2021-05-20T03:38:08.592447+00:00
67
false
java code is:\n# \n```\nclass Solution {\n public int minDeletionSize(String[] strs) {\n //0-current-delete,1-current-kept;\n int n=strs[0].length();\n int dp[][]=new int[n+1][2];\n for(int i=1;i<=n;i++){\n dp[i][0]=1+Math.min(dp[i-1][0],dp[i-1][1]);\n int j,min=i-1;...
0
0
[]
0
delete-columns-to-make-sorted-iii
[C++] Solution DP
c-solution-dp-by-libbyxu-nce1
\tclass Solution {\n\tpublic:\n\t\tint minDeletionSize(vector& strs) {\n\n\t\t\tint n=strs[0].size(), m=strs.size();\n\t\t\tvectordp(n,1);\n\n\t\t\t//lambda fun
libbyxu
NORMAL
2021-05-16T21:52:28.730203+00:00
2021-05-16T21:52:28.730246+00:00
112
false
\tclass Solution {\n\tpublic:\n\t\tint minDeletionSize(vector<string>& strs) {\n\n\t\t\tint n=strs[0].size(), m=strs.size();\n\t\t\tvector<int>dp(n,1);\n\n\t\t\t//lambda function\n\t\t\tauto checkTowS=[&](int i, int j)->bool{\n\t\t\t\tfor(int k=0;k<m;++k)\n\t\t\t\t\tif(strs[k][i]<strs[k][j])return false;\n\t\t\t\tretur...
0
0
[]
0
delete-columns-to-make-sorted-iii
100% Efficient, T O(n*l*l) || S O(l), n = len of 'strs' & l = length of a word
100-efficient-t-onll-s-ol-n-len-of-strs-seubt
Intution for algo is instead of keeping count of deleted columns we keep count of max columns we can keep\n * we use int array dp which has default value \'1\'
harsh007kumar
NORMAL
2021-04-19T09:56:07.434021+00:00
2021-04-19T09:56:07.434053+00:00
85
false
* Intution for algo is instead of keeping count of deleted columns we keep count of max columns we can keep\n * we use int array dp which has default value \'1\' for each columns as surely we can atleast keep 1 column for all rows\n * \n * Now we check for a given columns C considering we keep it, can we keep the next ...
0
0
['Dynamic Programming']
0
count-nodes-with-the-highest-score
Python 3 | Graph, DFS, Post-order Traversal, O(N) | Explanation
python-3-graph-dfs-post-order-traversal-bayye
Explanation\n- Intuition: Maximum product of 3 branches, need to know how many nodes in each branch, use DFS to start with\n- Build graph\n- Find left, right, u
idontknoooo
NORMAL
2021-10-24T04:15:53.346632+00:00
2021-10-24T04:15:53.346685+00:00
8,547
false
### Explanation\n- Intuition: Maximum product of 3 branches, need to know how many nodes in each branch, use `DFS` to start with\n- Build graph\n- Find left, right, up (number of nodes) for each node\n\t- left: use recursion\n\t- right: use recursion\n\t- up: `n - 1 - left - right`\n- Calculate score store in a dictina...
110
4
['Depth-First Search', 'Graph', 'Python', 'Python3']
13
count-nodes-with-the-highest-score
DFS
dfs-by-votrubac-y3r9
The value of a node is the product of:\n1. number of nodes in the left subtree, \n2. number of nodes in the right subtree,\n3. number of all other nodes, exclud
votrubac
NORMAL
2021-10-24T04:00:40.284032+00:00
2021-10-24T18:11:34.864487+00:00
9,192
false
The value of a node is the product of:\n1. number of nodes in the left subtree, \n2. number of nodes in the right subtree,\n3. number of all other nodes, excluding the current one (n - left - right - 1)\n\nWe can just use DFS to count child nodes for (1) and (2), and we can then compute (3) as we know the total nubers ...
77
3
['C', 'Java']
9
count-nodes-with-the-highest-score
[JAVA] Simple DFS Solution generalised for any tree with detailed comments. T=O(V+E), S=O(V+E)
java-simple-dfs-solution-generalised-for-pnh2
\n/*\n This solution is generalised to perform for any tree, not only binary tree. \n To calculate score for each node, we need the number of nodes in the
pramitb
NORMAL
2021-10-24T04:03:39.398159+00:00
2021-10-24T04:05:36.382340+00:00
4,155
false
```\n/*\n This solution is generalised to perform for any tree, not only binary tree. \n To calculate score for each node, we need the number of nodes in the subtrees whose root is a child of the current node \n and also the number of nodes in the remaining tree excluding the subtree with root at the current n...
49
5
[]
5
count-nodes-with-the-highest-score
[C++] DFS || Easy Solution with comments
c-dfs-easy-solution-with-comments-by-man-wd07
\nclass Solution {\n int helper(int src,vector<vector<int>>& g,vector<int>& size){\n int ans = 1;\n for(auto child:g[src]){\n an
manishbishnoi897
NORMAL
2021-10-24T04:01:55.390152+00:00
2021-10-24T11:11:54.292800+00:00
3,705
false
```\nclass Solution {\n int helper(int src,vector<vector<int>>& g,vector<int>& size){\n int ans = 1;\n for(auto child:g[src]){\n ans += helper(child,g,size);\n }\n return size[src] = ans; \n }\n \n \npublic:\n int countHighestScoreNodes(vector<int>& parents) ...
38
1
[]
3
count-nodes-with-the-highest-score
[Python3] post-order dfs
python3-post-order-dfs-by-ye15-09sb
\n\nclass Solution:\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n tree = [[] for _ in parents]\n for i, x in enumerate(paren
ye15
NORMAL
2021-10-24T04:02:10.708908+00:00
2021-10-24T15:51:16.397653+00:00
2,391
false
\n```\nclass Solution:\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n tree = [[] for _ in parents]\n for i, x in enumerate(parents): \n if x >= 0: tree[x].append(i)\n \n freq = defaultdict(int)\n \n def fn(x): \n """Return coun...
23
3
['Python3']
5
count-nodes-with-the-highest-score
✅ C++ , Clean code | Graph + DFS | Easy Explanation with comments
c-clean-code-graph-dfs-easy-explanation-xduve
C++\n\nclass Solution {\npublic:\n \n \n // Steps : \n // 1 - For each node, you need to find the sizes of the subtrees rooted in each of its child
HustlerNitin
NORMAL
2021-11-24T22:00:45.707116+00:00
2022-11-13T13:44:37.334264+00:00
1,629
false
**C++**\n```\nclass Solution {\npublic:\n \n \n // Steps : \n // 1 - For each node, you need to find the sizes of the subtrees rooted in each of its children.\n \n // 2 - How to determine the number of nodes in the rest of the tree? \n\t// Can you subtract the size of the subtree rooted at the node f...
17
0
['C']
3
count-nodes-with-the-highest-score
Intuitive JAVA solution, faster than 100%
intuitive-java-solution-faster-than-100-oft88
I used the most straightforward way to solve this problem.\nIt can be divided into 3 steps.\n Construct tree by using the parents[] array.\n Find the highest sc
ironpotato
NORMAL
2021-10-24T07:06:15.698967+00:00
2021-10-24T19:08:24.359687+00:00
1,259
false
I used the most straightforward way to solve this problem.\nIt can be divided into 3 steps.\n* Construct tree by using the parents[] array.\n* Find the highest score\n* Count nodes with the highest score\n\n```\nclass Solution {\n long highest = 0;\n \n public int countHighestScoreNodes(int[] parents) {\n ...
17
0
['Recursion']
2
count-nodes-with-the-highest-score
C++ Post-order Traversal
c-post-order-traversal-by-lzl124631x-2f9f
See my latest update in repo LeetCode\n\n## Solution 1. Post-order Traversal\n\nPost-order traverse the tree. For each node, calculate its score by multiplying
lzl124631x
NORMAL
2021-10-24T04:01:35.458120+00:00
2021-10-24T04:01:35.458148+00:00
1,743
false
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Post-order Traversal\n\nPost-order traverse the tree. For each node, calculate its score by multiplying the node count of its left subtree, right subtree and nodes not in the current subtree (ignoring `0`). Count the nodes...
11
1
[]
0
count-nodes-with-the-highest-score
Java Solution | Subnodes Count | With Explanation
java-solution-subnodes-count-with-explan-aenu
Counts array is having the counts of subnodes for each node.\nNow removing a node , remaining can be easily get with product of subnodes of that node\'s subnode
surajthapliyal
NORMAL
2021-10-24T06:03:10.358974+00:00
2021-10-24T06:32:02.008478+00:00
681
false
Counts array is having the counts of subnodes for each node.\nNow removing a node , remaining can be easily get with product of subnodes of that node\'s subnodes and upper nodes (total - counts[node])\nIn case of parent we dont have any upper nodes so we dont do it when i==0.\nStore all products along with thier freque...
8
0
[]
0
count-nodes-with-the-highest-score
✔️ PYTHON || EXPLAINED || ;]
python-explained-by-karan_8082-9gme
UPVOTE IF HELPFuuL\n\nObservation : \nscore = number of above nodes * number of nodes of 1 child * number of nodes ofother child\n\nWe are provided with the par
karan_8082
NORMAL
2022-06-29T09:14:40.018016+00:00
2022-06-29T09:42:59.509025+00:00
744
false
**UPVOTE IF HELPFuuL**\n\n**Observation** : \nscore = ```number of above nodes * number of nodes of 1 child * number of nodes ofother child```\n\nWe are provided with the parents of nodes, For convenience we keep mapping of chilren of nodes.\n\n* First task : Create a dictionary to keep the children of nodes.\n* Second...
7
0
['Python3']
0
count-nodes-with-the-highest-score
Easy to understand C++ Solution | Post Order | DFS | O(n)
easy-to-understand-c-solution-post-order-nuym
Intuition\n Describe your first thoughts on how to solve this problem. \nWe are asked to count the nodes with highest score. \nScore of a node is nothing but pr
cstrasengan
NORMAL
2024-02-01T06:28:14.701133+00:00
2024-02-01T06:28:14.701157+00:00
780
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe are asked to count the nodes with highest score. \n**Score of a node** is nothing but product of number of nodes in the remaining forests after removing that node from the tree. \n\n**Important Observation**:\nWe can categorize the nod...
5
0
['C++']
0
count-nodes-with-the-highest-score
C++ simple dfs with explanation
c-simple-dfs-with-explanation-by-shyamab-towf
class Solution {\npublic:\n \n \n int dfs(vector adj[], int n,int i, vector&dp)\n {\n int ans=1;\n \n // ans+=adj[i].size();\n
shyamabhishek115
NORMAL
2021-12-06T19:18:08.632365+00:00
2021-12-06T19:18:08.632413+00:00
415
false
class Solution {\npublic:\n \n \n int dfs(vector<int> adj[], int n,int i, vector<int>&dp)\n {\n int ans=1;\n \n // ans+=adj[i].size();\n \n for(auto it:adj[i])\n {\n ans+= dfs(adj,n,it,dp);\n }\n \n return dp[i]=ans;\n }\n int count...
5
1
[]
1
count-nodes-with-the-highest-score
Easy Java Solution With Comments
easy-java-solution-with-comments-by-pava-endq
\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n //--build tree start--\n Node[] arr = new Node[parents.length];\n
pavankumarchaitanya
NORMAL
2021-10-24T04:01:20.834694+00:00
2021-10-24T04:01:20.834729+00:00
800
false
```\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n //--build tree start--\n Node[] arr = new Node[parents.length];\n for(int i = 0;i<parents.length;i++)\n arr[i] = new Node();\n \n for(int i = 1;i<parents.length;i++){\n arr[i].parent ...
5
0
[]
2
count-nodes-with-the-highest-score
Easy C++ Solution || DFS || GRAPH
easy-c-solution-dfs-graph-by-bleedin_mar-xe7k
Intuition\nSince TreeNode class is not previously declared so it is a hint we dont need that. It is just a simple problem of graph and selecting the maximum.\n\
bleedin_maroon
NORMAL
2023-09-09T20:42:22.265253+00:00
2023-09-09T20:42:22.265282+00:00
610
false
# Intuition\nSince TreeNode class is not previously declared so it is a hint we dont need that. It is just a simple problem of graph and selecting the maximum.\n\n# Approach\nCreate adjacency matrix and take the product of the components after disconnection. If its is max update max and reset count to 1, else update co...
4
0
['C++']
0
count-nodes-with-the-highest-score
[Python] DFS Solution with Dictionary, Straightforward, No Zip
python-dfs-solution-with-dictionary-stra-onu7
Runtime: 1816 ms, faster than 83.52% of Python3 online submissions for Count Nodes With the Highest Score.\nMemory Usage: 112.2 MB, less than 76.78% of Python3
bbshark
NORMAL
2022-10-22T02:37:45.316924+00:00
2022-10-22T02:37:45.316949+00:00
201
false
*Runtime: 1816 ms, faster than 83.52% of Python3 online submissions for Count Nodes With the Highest Score.\nMemory Usage: 112.2 MB, less than 76.78% of Python3 online submissions for Count Nodes With the Highest Score.*\n\nMy solution is never fancy but it must be straightforward and understandable (hopefully).\n1. Cr...
4
0
['Depth-First Search', 'Python', 'Python3']
1
count-nodes-with-the-highest-score
Java | O(n) | DFS | Concise
java-on-dfs-concise-by-tyro-fupr
\n\nclass Solution {\n long max = 0, res = 0;\n public int countHighestScoreNodes(int[] parents) {\n Map<Integer, List<Integer>> hm = new HashMap()
tyro
NORMAL
2021-10-24T12:05:22.193513+00:00
2021-12-18T00:20:39.052391+00:00
1,207
false
\n```\nclass Solution {\n long max = 0, res = 0;\n public int countHighestScoreNodes(int[] parents) {\n Map<Integer, List<Integer>> hm = new HashMap();\n for(int i = 0; i < parents.length; i++) { // build the tree\n hm.computeIfAbsent(parents[i], x ->new ArrayList<>()).add(i);\n ...
4
0
['Depth-First Search', 'Java']
1
count-nodes-with-the-highest-score
C++ post-order solution
c-post-order-solution-by-chejianchao-7yca
\nGet the number of nodes of L subtree and R subtree. and score = l * r * rest. (if l, r, rest == 0 then set to 1)\n\nclass Solution {\npublic:\n long long a
chejianchao
NORMAL
2021-10-24T04:00:51.211718+00:00
2021-10-24T16:06:06.920911+00:00
574
false
\nGet the number of nodes of L subtree and R subtree. and score = l * r * rest. (if l, r, rest == 0 then set to 1)\n```\nclass Solution {\npublic:\n long long ans = 0;\n long long cnt = 0;\n vector<vector<int> > adj;\n int n;\n long long dfs(int node) {\n long long l = 0, r = 0;\n if(adj[no...
4
0
[]
2
count-nodes-with-the-highest-score
Easy Solution || Explained Well || java
easy-solution-explained-well-java-by-amr-dayr
Objective\nFor each node, we want to calculate a score. This score is the product of the sizes of the subtrees of its children and the remaining nodes outside t
Amritanshu23
NORMAL
2024-05-19T07:35:30.186143+00:00
2024-05-19T07:35:30.186173+00:00
104
false
Objective\nFor each node, we want to calculate a score. This score is the product of the sizes of the subtrees of its children and the remaining nodes outside these subtrees. We need to find out how many nodes have the highest score.\n\nSteps to Solve the Problem\nCreate the Binary Tree:\n\nConvert the parents array in...
3
0
['Tree']
0
count-nodes-with-the-highest-score
simple java solution using hashmap
simple-java-solution-using-hashmap-by-ha-etxh
```\n// if you found my solution usefull please upvote it\nclass Solution \n{\n public HashMap hash;\n public int dfs(int i,List[] adj,int totalNodes)\n
Haswanth_kumar
NORMAL
2022-10-28T06:48:40.523976+00:00
2022-10-28T06:48:40.524019+00:00
296
false
```\n// if you found my solution usefull please upvote it\nclass Solution \n{\n public HashMap<Long,Integer> hash;\n public int dfs(int i,List<Integer>[] adj,int totalNodes)\n {\n int sumOfNodes=0;\n long product=1l;\n for(int curr : adj[i])\n {\n int currNodes=dfs(curr,a...
3
0
['Java']
0
count-nodes-with-the-highest-score
cpp easy solution using recursion
cpp-easy-solution-using-recursion-by-san-36ri
```\nclass treeNode{\n public:\n treeNode left,right;\n int val;\n \n treeNode(int val){\n this->val=val;\n left=right=NULL
Sanket_Jadhav
NORMAL
2022-09-06T13:43:10.451752+00:00
2022-09-06T13:43:10.451790+00:00
654
false
```\nclass treeNode{\n public:\n treeNode* left,*right;\n int val;\n \n treeNode(int val){\n this->val=val;\n left=right=NULL;\n }\n};\n\nclass Solution {\npublic:\n unordered_map<long long int,int>ans;\n int func(treeNode* root,int n){\n if(!root)return 0;\n ...
3
0
['C++']
0
count-nodes-with-the-highest-score
Calculate subtree size at every node
calculate-subtree-size-at-every-node-by-ggtzv
Calculate subtree size at every node.\nThen, score of a node = (product of size of subtree from every child) * (size of FULL tree - size of subtree at node).\n\
srhd_dhrs
NORMAL
2021-11-03T07:02:23.898378+00:00
2021-11-03T07:06:23.367935+00:00
2,346
false
**Calculate subtree size at every node.**\nThen, score of a node = (product of size of subtree from every child) * (size of FULL tree - size of subtree at node).\n\n```\nclass Solution {\npublic:\n int getSize(int cur, vector<int> children[], int subSize[]) {\n subSize[cur] = 1;\n \n for(auto c ...
3
0
[]
0
count-nodes-with-the-highest-score
Subtree size | Adjacency List
subtree-size-adjacency-list-by-esh_war12-oe6j
Intuition\n Describe your first thoughts on how to solve this problem. \nScore is product of subtree sizes so we should have a easier way to find subtree size w
esh_war12
NORMAL
2024-07-08T10:02:19.529794+00:00
2024-07-08T10:02:19.529827+00:00
351
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nScore is product of subtree sizes so we should have a easier way to find subtree size when each of node is removed in constant time.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFind subtree size of each node. (...
2
0
['C++']
1
count-nodes-with-the-highest-score
C++ Simple DFS On Binary Tree
c-simple-dfs-on-binary-tree-by-rishabhsi-9mhh
\nclass Solution {\npublic:\n long long N;\n long long maxi;\n long long count;\n int dfs(vector<vector<int>>& g, int src){\n \n int l
Rishabhsinghal12
NORMAL
2023-01-11T18:11:07.147904+00:00
2023-01-11T18:11:07.147950+00:00
861
false
```\nclass Solution {\npublic:\n long long N;\n long long maxi;\n long long count;\n int dfs(vector<vector<int>>& g, int src){\n \n int l = 0,r = 0;\n \n if(g[src].size() > 0){\n l = dfs(g,g[src][0]);\n }\n \n if(g[src].size() > 1){\n r ...
2
0
['Depth-First Search', 'C', 'Binary Tree', 'C++']
0
count-nodes-with-the-highest-score
✔ Python3 Solution | DFS | O(n)
python3-solution-dfs-on-by-satyam2001-ln0u
Complexity\n- Time complexity: O(n)\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n
satyam2001
NORMAL
2023-01-01T07:53:17.705749+00:00
2023-01-01T07:53:17.705791+00:00
934
false
# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nclass Solution:\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n n = len(parents)\n scores = [1] * n\n graph = [[] for _ in range(n)]\n for e, i in enumerate(parents):\n if e...
2
0
['Python3']
0
count-nodes-with-the-highest-score
2 DFS | C++
2-dfs-c-by-tusharbhart-au0e
\nclass Solution {\n int dfs1(int node, int pre, vector<int> adj[], vector<int> &cnt) {\n int c = 1;\n for(int ad : adj[node]) {\n i
TusharBhart
NORMAL
2022-12-23T10:04:50.412303+00:00
2022-12-23T10:04:50.412339+00:00
901
false
```\nclass Solution {\n int dfs1(int node, int pre, vector<int> adj[], vector<int> &cnt) {\n int c = 1;\n for(int ad : adj[node]) {\n if(ad == pre) continue;\n c += dfs1(ad, node, adj, cnt);\n }\n return cnt[node] = c;\n }\n void dfs2(int node, int pre, vector<...
2
0
['Depth-First Search', 'C++']
0
count-nodes-with-the-highest-score
✅ EZ Python || DFS
ez-python-dfs-by-0xsapra-q1lr
\nclass Node:\n \n \n def __init__(self, n):\n self.n = n\n self.left = None\n self.right = None\n\nclass Solution:\n def count
0xsapra
NORMAL
2022-10-18T18:12:52.455500+00:00
2022-10-18T18:12:52.455540+00:00
481
false
```\nclass Node:\n \n \n def __init__(self, n):\n self.n = n\n self.left = None\n self.right = None\n\nclass Solution:\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n \n MAX_COUNT = 0\n MAX_NUM = -inf\n TOTAL = len(parents)\n \n ...
2
0
['Depth-First Search', 'Python']
0
count-nodes-with-the-highest-score
JAVA SOLUTION || HASHMAP || DFS || DP || EASY TO UNDERSTAND
java-solution-hashmap-dfs-dp-easy-to-und-3s2t
\nclass Solution {\n public int countHighestScoreNodes(int[] parents) \n {\n int total_nodes=parents.length;\n \n //stores parent nod
29nidhishah
NORMAL
2022-09-03T12:11:02.375193+00:00
2022-09-03T12:11:02.375234+00:00
753
false
```\nclass Solution {\n public int countHighestScoreNodes(int[] parents) \n {\n int total_nodes=parents.length;\n \n //stores parent node---> child nodes\n Map<Integer,List<Integer>> parent_child=new HashMap<>();\n for(int i=0;i<total_nodes;i++)\n {\n if(!paren...
2
0
['Dynamic Programming', 'Depth-First Search', 'Java']
1
count-nodes-with-the-highest-score
C++ solution using binary tree creation & then dfs for finding answer
c-solution-using-binary-tree-creation-th-m4vw
struct TreeNode\n {\n TreeNode left =NULL;\n TreeNode right=NULL ;\n int val;\n int totalcount=0;\n };\n
KR_SK_01_In
NORMAL
2022-03-07T17:34:32.068324+00:00
2022-03-07T17:35:49.017269+00:00
165
false
struct TreeNode\n {\n TreeNode* left =NULL;\n TreeNode* right=NULL ;\n int val;\n int totalcount=0;\n };\n \n int func(TreeNode* root , int n)\n {\n if(root==NULL)\n {\n return 0;\n }\n ...
2
0
['C', 'Binary Tree', 'C++']
0
count-nodes-with-the-highest-score
Dynamic Programming On Graphs
dynamic-programming-on-graphs-by-tamande-qlaa
I used dp on trees to solve this problem.\nThe concept is simple. \nFirst you calculate size of each subtree for every node. Here dp on trees is applied for tha
tamandeeps
NORMAL
2022-03-01T10:58:23.227310+00:00
2022-03-01T10:58:23.227337+00:00
188
false
I used dp on trees to solve this problem.\nThe concept is simple. \nFirst you calculate size of each subtree for every node. Here dp on trees is applied for that. Size of subtrees added and +1 to get total size of that current node.\nTo calculate score for current node, you subtract size of root node subtracted with si...
2
0
['Dynamic Programming', 'Tree', 'Depth-First Search', 'Graph']
0
count-nodes-with-the-highest-score
C++ DFS solution
c-dfs-solution-by-dan_zhixu-htpk
DFS solution. The first one uses a few maps to manage the countings. The second solution uses global variable and does the comparison in the DFS. \n\nSolution 1
dan_zhixu
NORMAL
2021-10-30T06:33:13.556172+00:00
2021-10-30T07:13:11.024945+00:00
193
false
DFS solution. The first one uses a few maps to manage the countings. The second solution uses global variable and does the comparison in the DFS. \n\nSolution 1\n```\nclass Solution {\npublic:\n int countHighestScoreNodes(vector<int>& parents) {\n \n unordered_map<int, vector<int>> graph;\n \n ...
2
1
[]
0
count-nodes-with-the-highest-score
c++ solution
c-solution-by-dilipsuthar60-xaf8
\nclass Solution {\npublic:\n vector<vector<int>>dp;\n void find(int x,int p,vector<int>&sub)\n {\n for(auto it:dp[x])\n {\n i
dilipsuthar17
NORMAL
2021-10-30T06:10:11.627656+00:00
2021-10-30T06:11:53.446262+00:00
315
false
```\nclass Solution {\npublic:\n vector<vector<int>>dp;\n void find(int x,int p,vector<int>&sub)\n {\n for(auto it:dp[x])\n {\n if(it!=p)\n {\n find(it,x,sub);\n sub[x]+=sub[it];\n }\n }\n \n }\n int countHighestScor...
2
0
['Depth-First Search', 'C', 'C++']
0
count-nodes-with-the-highest-score
[Python] Simple DFS Solution with explanation
python-simple-dfs-solution-with-explanat-y35r
for each node, when we remove it, we have the following parts:\n1. child subtree if any\n2. parent subtree if any\n\nwe use dfs to count the number of node in e
nightybear
NORMAL
2021-10-30T02:46:43.413614+00:00
2021-10-30T02:46:43.413645+00:00
534
false
for each node, when we remove it, we have the following parts:\n1. child subtree if any\n2. parent subtree if any\n\nwe use dfs to count the number of node in each child subtree (no.1) and calculate the number of node in the parent subtree by `N - sum(child_subtree) - 1(node itself)`. We use `memo` to aovid duplicated ...
2
0
['Depth-First Search', 'Python', 'Python3']
0
count-nodes-with-the-highest-score
Golang postorder-traversal solution
golang-postorder-traversal-solution-by-t-8r74
go\ntype cs struct {\n\tchildren []int\n\tsummary int\n}\n\nfunc countHighestScoreNodes(parents []int) int {\n\tmagic := make([]*cs, len(parents))\n\tfor i :=
tjucoder
NORMAL
2021-10-24T17:10:01.650213+00:00
2021-10-24T17:10:01.650258+00:00
91
false
```go\ntype cs struct {\n\tchildren []int\n\tsummary int\n}\n\nfunc countHighestScoreNodes(parents []int) int {\n\tmagic := make([]*cs, len(parents))\n\tfor i := range magic {\n\t\tmagic[i] = &cs{\n\t\t\tchildren: make([]int, 0, 2),\n\t\t\tsummary: 1,\n\t\t}\n\t}\n\tfor i := 1; i < len(parents); i++ {\n\t\tmagic[pare...
2
0
['Go']
0
count-nodes-with-the-highest-score
javascript dfs 372ms
javascript-dfs-372ms-by-henrychen222-tl8d
\nconst initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };\n\nlet g, n, res, cnt;\nconst countHighestScoreNodes = (
henrychen222
NORMAL
2021-10-24T04:54:46.451842+00:00
2021-10-24T05:02:15.226196+00:00
223
false
```\nconst initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };\n\nlet g, n, res, cnt;\nconst countHighestScoreNodes = (parents) => {\n res = -1, cnt = 0, n = parents.length, g = initializeGraph(n);\n for (let i = 0; i < n; i++) {\n if (parents[i] == -1) continue;...
2
0
['Depth-First Search', 'JavaScript']
1
count-nodes-with-the-highest-score
c# post-order dfs 100% 100%
c-post-order-dfs-100-100-by-canran-0byz
\npublic class Solution {\n \n int dfs(int[,] leaves, int[,] nums, int node)\n {\n int left = leaves[node, 0] == -1? 0: dfs(leaves, nums, leaves
canran
NORMAL
2021-10-24T04:31:51.694359+00:00
2021-10-24T04:34:03.034854+00:00
120
false
```\npublic class Solution {\n \n int dfs(int[,] leaves, int[,] nums, int node)\n {\n int left = leaves[node, 0] == -1? 0: dfs(leaves, nums, leaves[node, 0]);\n int right = leaves[node, 1] == -1? 0: dfs(leaves, nums, leaves[node, 1]);\n nums[node, 0] = left;\n nums[node, 1] = right;...
2
0
['Depth-First Search']
1
count-nodes-with-the-highest-score
O(n) solution using simple tree traversal (C++) with explanation comments
on-solution-using-simple-tree-traversal-p34dl
\nclass Solution {\npublic:\n\n// first form a tree data structure to build your tree later in the q.\n\n struct TreeNode\n {\n int val;\n T
pizza_slice
NORMAL
2021-10-24T04:10:01.523034+00:00
2021-10-24T04:10:01.523065+00:00
102
false
```\nclass Solution {\npublic:\n\n// first form a tree data structure to build your tree later in the q.\n\n struct TreeNode\n {\n int val;\n TreeNode *left=NULL;\n TreeNode *right=NULL;\n };\n \n map<int,long long> score;\n long long maxScore=0;\n \n\t// use this function to r...
2
0
[]
0
count-nodes-with-the-highest-score
C++ | DP on Tree | Easy solution | DFS
c-dp-on-tree-easy-solution-dfs-by-chanda-v675
Calculate size of subtree for each node using DFS\n Now we have to remove each vertex i* , there might be three possibility-\n 1. we remove leaf node\n
chandanagrawal23
NORMAL
2021-10-24T04:06:24.290507+00:00
2021-10-24T04:11:04.541576+00:00
515
false
* Calculate size of subtree for each node using DFS\n* Now we have to remove each vertex **i** , there might be three possibility-\n 1. we remove leaf node\n 2. we remove node having one child\n 3. we remove node having two child \n```\nclass Solution {\npublic:\n int countHighestScoreNodes...
2
0
['Dynamic Programming', 'Tree', 'Depth-First Search', 'C']
2
count-nodes-with-the-highest-score
(C++) 2049. Count Nodes With the Highest Score
c-2049-count-nodes-with-the-highest-scor-dum9
\n\nclass Solution {\npublic:\n int countHighestScoreNodes(vector<int>& parents) {\n int n = parents.size(); \n vector<vector<int>> tree(n); \n
qeetcode
NORMAL
2021-10-24T04:06:07.673611+00:00
2021-10-25T02:32:14.665483+00:00
268
false
\n```\nclass Solution {\npublic:\n int countHighestScoreNodes(vector<int>& parents) {\n int n = parents.size(); \n vector<vector<int>> tree(n); \n for (int i = 0; i < n; ++i) \n if (parents[i] >= 0) tree[parents[i]].push_back(i); \n \n map<long, int> freq; \n \n ...
2
0
['C']
1
count-nodes-with-the-highest-score
BFS Solution | Intuitive | Topological Sort Version
bfs-solution-intuitive-topological-sort-w782z
IntuitionStart with leaf nodes. As they dont have any out degree.Approach Start with leaf node. Count the children of nodes as u move above using topo sort algo
I_Hacker
NORMAL
2025-03-31T19:51:49.427397+00:00
2025-04-09T04:13:32.505968+00:00
49
false
# Intuition Start with leaf nodes. As they dont have any out degree. # Approach 1. Start with leaf node. 2. Count the children of nodes as u move above using topo sort algorithm with outdegree as O. 3. As you have count of children, just need to prod = (count of left children) * (count of right children) * (number of...
1
0
['Breadth-First Search', 'Topological Sort', 'Binary Tree', 'C++']
0
count-nodes-with-the-highest-score
Simple C++ Solution || (Using DFS) ✅✅
simple-c-solution-using-dfs-by-abhi242-nliv
Code\n\nclass Solution {\npublic:\n map<long long,int> mp;\n int dfs(vector<int> adj[],int node,int n){\n int ans=0;\n int i=0;\n int
Abhi242
NORMAL
2024-08-02T14:00:11.260500+00:00
2024-08-02T14:00:11.260527+00:00
71
false
# Code\n```\nclass Solution {\npublic:\n map<long long,int> mp;\n int dfs(vector<int> adj[],int node,int n){\n int ans=0;\n int i=0;\n int sum1=0;\n int sum2=0;\n for(int a:adj[node]){\n if(i==0){\n sum1=(1+dfs(adj,a,n));\n }else{\n ...
1
0
['Depth-First Search', 'Binary Tree', 'C++']
0
count-nodes-with-the-highest-score
Easy Solution, simulation of recursion using queue
easy-solution-simulation-of-recursion-us-w9lf
Intuition\n Describe your first thoughts on how to solve this problem. \nIf the input was given in the form of TreeNode then the obvious way is to use postorder
mp_aka_sh
NORMAL
2024-07-25T07:05:18.213102+00:00
2024-07-25T07:05:18.213124+00:00
45
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf the input was given in the form of TreeNode then the obvious way is to use postorder traversal. That is, a node receives number of left nodes from left child node and similary from right, then we can just multiply them with the remaini...
1
0
['Depth-First Search', 'Queue', 'Binary Tree', 'C++']
0
count-nodes-with-the-highest-score
Python - Recursive Post Order Traversal (DFS) Solution ✅
python-recursive-post-order-traversal-df-35b1
The idea is to first count how many nodes each node has on its left and right. This information will be helpful when we have to get the score of a node.\n\n\n\n
itsarvindhere
NORMAL
2024-06-13T06:05:38.382799+00:00
2024-06-13T06:06:33.470607+00:00
67
false
The idea is to first count how many nodes each node has on its left and right. This information will be helpful when we have to get the score of a node.\n\n![image](https://assets.leetcode.com/users/images/a86378d4-465d-4924-b240-db3026555930_1718258635.5966825.png)\n\nIf you look at the above example, whenever we remo...
1
0
['Tree', 'Depth-First Search', 'Binary Tree', 'Python', 'Python3']
0
count-nodes-with-the-highest-score
Explaned well || fully commented || java || using HashMap || Creating tree
explaned-well-fully-commented-java-using-o1g7
Intuition\n Describe your first thoughts on how to solve this problem. \nAs the parents value is given in the array where parents[i] is the parent of i. \nparen
codingWithAman
NORMAL
2024-05-22T16:05:24.367201+00:00
2024-05-22T16:54:31.384024+00:00
228
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs the parents value is given in the array where parents[i] is the parent of i. \nparents =[-1,3,1,0,3]\nIn this case parent of 3 has two child, i.e, 1 and 4 as 3 is coming twice in the array at index 1 and 4. Parent 1 has 2 as the child ...
1
0
['Java']
0
count-nodes-with-the-highest-score
Java with comments
java-with-comments-by-endlessjourney-0so6
Code\n\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n int N = parents.length;\n\n // Initialize adjacency list and su
endlessjourney
NORMAL
2024-01-22T00:44:52.293175+00:00
2024-01-22T00:44:52.293215+00:00
275
false
# Code\n```\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n int N = parents.length;\n\n // Initialize adjacency list and subtree sizes array\n List<List<Integer>> al = new ArrayList<>();\n for (int i = 0; i < N; i++) {\n al.add(new ArrayList<>());\n ...
1
0
['Java']
1
count-nodes-with-the-highest-score
c# recursive solution
c-recursive-solution-by-sree_lakshmi-n3al
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
sree_lakshmi
NORMAL
2024-01-20T01:15:26.390626+00:00
2024-01-20T01:15:26.390668+00:00
33
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
0
['C#']
0
count-nodes-with-the-highest-score
C++ | Single DFS O(n) | Easy Explanation
c-single-dfs-on-easy-explanation-by-adit-4adl
\n# Approach\n Describe your approach to solving the problem. \n1. Need the sizes of all the subtrees (subordinate as well as above one) to calculate each node\
AdityaGiri
NORMAL
2023-07-18T18:43:59.067702+00:00
2023-07-18T20:20:17.202208+00:00
53
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Need the sizes of all the subtrees (subordinate as well as above one) to calculate each node\'s score.\n\n2. Calculate sizes of left & right subordinate subtree as we run the dfs function for the current node.\n\n3. Now to get the size of above t...
1
0
['Tree', 'Depth-First Search', 'Binary Tree', 'C++']
0
count-nodes-with-the-highest-score
Python Easy Recursive Solution
python-easy-recursive-solution-by-sparsh-gi3k
Code\n\nclass Solution:\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n\n sizes = [[0]*2 for _ in range(len(parents))]\n dic =
sparshlodha04
NORMAL
2022-12-10T07:03:06.094195+00:00
2022-12-10T07:03:47.248155+00:00
1,076
false
## Code\n```\nclass Solution:\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n\n sizes = [[0]*2 for _ in range(len(parents))]\n dic = defaultdict(list)\n\n def rec(root):\n\n if not dic[root]:\n return 1\n\n if len(dic[root]) == 1:\n ...
1
0
['Python3']
0
count-nodes-with-the-highest-score
Java Solution || HashTables || DFS || O(n) time
java-solution-hashtables-dfs-on-time-by-kooi3
```java\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n int n = parents.length; // no. of nodes\n \n //for stor
nishant7372
NORMAL
2022-10-31T07:11:06.047526+00:00
2022-10-31T07:19:36.847192+00:00
140
false
```java\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n int n = parents.length; // no. of nodes\n \n //for storing left and right child of each node\n ArrayList<Integer>[] a = new ArrayList[n];\n \n for(int i=0;i<n;i++)\n a[i]=new ArrayLis...
1
0
[]
0
count-nodes-with-the-highest-score
Python (Simple DFS)
python-simple-dfs-by-rnotappl-zxyl
\n def countHighestScoreNodes(self, parents):\n dict1 = defaultdict(list)\n \n for node, parent in enumerate(parents):\n dict
rnotappl
NORMAL
2022-08-25T14:10:05.394212+00:00
2022-08-25T14:10:05.394252+00:00
73
false
\n def countHighestScoreNodes(self, parents):\n dict1 = defaultdict(list)\n \n for node, parent in enumerate(parents):\n dict1[parent].append(node)\n \n n, dict2 = len(parents), defaultdict(int)\n \n def dfs(node):\n product, total = 1, 0\n ...
1
0
[]
0
count-nodes-with-the-highest-score
[Java] 35ms DFS, 95% + explanations
java-35ms-dfs-95-explanations-by-stefane-ad41
\nclass Solution {\n /** Algorithm/Theory\n 1. An efficient first step is to build the tree. This way, we can post-order traverse it and determine the
StefanelStan
NORMAL
2022-06-28T00:42:06.357783+00:00
2022-06-28T21:18:33.949794+00:00
564
false
```\nclass Solution {\n /** Algorithm/Theory\n 1. An efficient first step is to build the tree. This way, we can post-order traverse it and determine the product of non-empty subtrees\n 2. Use a simple Node[] array to map node order/value to Node content.\n set node[0] to be the parent.\n ...
1
0
['Depth-First Search', 'Java']
0
count-nodes-with-the-highest-score
Simple Java Solution (DFS, Build Tree)
simple-java-solution-dfs-build-tree-by-m-ss9k
```\nclass Solution {\n static class TreeNode {\n int val;\n TreeNode left,right;\n TreeNode() {\n \n }\n TreeN
mokshteng
NORMAL
2022-06-08T06:35:37.820410+00:00
2022-06-08T06:35:37.820447+00:00
78
false
```\nclass Solution {\n static class TreeNode {\n int val;\n TreeNode left,right;\n TreeNode() {\n \n }\n TreeNode(int val) {\n this.val=val;\n }\n }\n public int countHighestScoreNodes(int[] parents) {\n int n=parents.length;\n Hash...
1
0
[]
0
count-nodes-with-the-highest-score
Two dfs O(n)
two-dfs-on-by-mayankmodi041998-954a
\nclass Solution {\npublic:\n vector<vector<int>>adj;\n vector<long long int>counter;\n long long int res=0;\n int countt=0;\n void dfs(int src)\
mayankmodi041998
NORMAL
2022-05-24T14:45:46.408781+00:00
2022-05-24T14:45:46.408826+00:00
30
false
```\nclass Solution {\npublic:\n vector<vector<int>>adj;\n vector<long long int>counter;\n long long int res=0;\n int countt=0;\n void dfs(int src)\n {\n for(int i=0;i<adj[src].size();i++)\n {\n int u=adj[src][i];\n dfs(u);\n counter[src]+=counter[u];\n ...
1
0
[]
0
count-nodes-with-the-highest-score
C++ Easy Postorder Traversal (85% time beat)
c-easy-postorder-traversal-85-time-beat-okind
LOGIC : \n\nSimply get the count of left nodes and right nodes recursively and get the remaining nodes(after removing the current nodes by doing n-(l+r)-1. Now
SHUBHAMBRODY26
NORMAL
2022-03-29T06:33:54.476516+00:00
2022-03-29T06:33:54.476555+00:00
202
false
**LOGIC : **\n\nSimply get the count of left nodes and right nodes recursively and get the remaining nodes(after removing the current nodes by doing n-(l+r)-1. Now we multiply them and check if it is same as our current multiplication or greater than. If equal, we just increase the counter and if greater, we update our...
1
0
['Depth-First Search', 'Recursion']
0
count-nodes-with-the-highest-score
Easy and simple code || C++ || DFS || O(N) solution
easy-and-simple-code-c-dfs-on-solution-b-uucn
Step-1 We build a undirected graph using parent array.\nStep -2 For each node we need the count of left and right subtree size so ans for a node will be ( left
utsav___gupta
NORMAL
2022-03-11T05:51:21.666189+00:00
2022-03-11T05:54:19.073692+00:00
177
false
**Step-1** We build a undirected graph using parent array.\n**Step -2** For each node we need the count of left and right subtree size so ans for a node will be ( **left subtree size * right subtree size * (total nodes -left subtree size -right subtree size**) to get this we will make a dfs call with the root which wi...
1
0
['Depth-First Search', 'C']
0
count-nodes-with-the-highest-score
Java - O(N) space and time solution
java-on-space-and-time-solution-by-pathe-89gb
A cut score is multiplication of no of leftChildren, no of rightChidren and remaning nodes (Total nodes-leftChildren-rightChildren-1).\nBelow is Java Code for t
pathey
NORMAL
2022-03-06T23:34:23.824840+00:00
2022-03-06T23:34:23.824871+00:00
96
false
A cut score is multiplication of no of leftChildren, no of rightChidren and remaning nodes (Total nodes-leftChildren-rightChildren-1).\nBelow is Java Code for the solution with comments.\n\n```\n//TreeNode \nclass TreeNode\n{\n int val;\n TreeNode left;\n TreeNode right;\n int leftChilds=0;\n int rightCh...
1
0
['Depth-First Search', 'Binary Tree']
0
count-nodes-with-the-highest-score
Count Nodes With the Highest Score | C++ | SubTree Size + Maths | DFS
count-nodes-with-the-highest-score-c-sub-yhnc
\nclass Solution {\npublic:\n int countHighestScoreNodes(vector<int>& p) {\n int n = p.size();\n vector<int> tree[n], subTreeSize(n, 0), vis(n,
renu_apk
NORMAL
2022-01-12T07:59:51.092532+00:00
2022-01-12T08:01:07.100768+00:00
83
false
```\nclass Solution {\npublic:\n int countHighestScoreNodes(vector<int>& p) {\n int n = p.size();\n vector<int> tree[n], subTreeSize(n, 0), vis(n, 0);\n for(int i = 0; i < n; i++){\n if(p[i] != -1){\n tree[p[i]].push_back(i);\n }\n }\n \n ...
1
0
[]
0
count-nodes-with-the-highest-score
Java solution fail. what's wrong?
java-solution-fail-whats-wrong-by-pvp-vm8b
\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n HashMap<Integer, TreeNode> treeMap = new HashMap<Integer, TreeNode>();\n
pvp
NORMAL
2021-12-15T13:46:09.845082+00:00
2021-12-15T13:46:09.845105+00:00
100
false
```\nclass Solution {\n public int countHighestScoreNodes(int[] parents) {\n HashMap<Integer, TreeNode> treeMap = new HashMap<Integer, TreeNode>();\n for (int i = 0; i < parents.length; i++) {\n TreeNode node;\n if (!treeMap.containsKey(i)) {\n node = new TreeNode(i...
1
0
[]
2
count-nodes-with-the-highest-score
Java build tree and dfs
java-build-tree-and-dfs-by-nadabao-c9co
I really like this question, very suitable for real interview.\nTesting tree building, dfs, corner case, etc\n\n\nclass Solution {\n long max = 0;\n long
nadabao
NORMAL
2021-11-13T06:06:32.238394+00:00
2021-11-13T06:07:38.287681+00:00
181
false
I really like this question, very suitable for real interview.\nTesting tree building, dfs, corner case, etc\n\n```\nclass Solution {\n long max = 0;\n long cnt = 0;\n public int countHighestScoreNodes(int[] parents) {\n TreeNode root = buildTree(parents); \n dfs(root, parents.length);\n r...
1
0
[]
0
count-nodes-with-the-highest-score
Should be intuitive
should-be-intuitive-by-liqiangc-7mz4
\tint dfs(const vector >& g, int i, long& maxScore, long& res){\n long score = 1, sum = 0;\n for(int x : g[i]){\n int cnt = dfs(g, x, m
liqiangc
NORMAL
2021-10-30T00:10:43.918976+00:00
2021-11-13T15:45:20.524962+00:00
71
false
\tint dfs(const vector<vector<int> >& g, int i, long& maxScore, long& res){\n long score = 1, sum = 0;\n for(int x : g[i]){\n int cnt = dfs(g, x, maxScore, res);\n score *= cnt;\n sum += cnt;\n }\n score *= g.size()-sum-(i!=0);\n if(score>maxScore) max...
1
0
[]
1
count-nodes-with-the-highest-score
DSS based Solution || C++
dss-based-solution-c-by-sj4u-w0t9
\n\n\n\n#define ll long long\nclass Solution {\npublic:\n \n struct Node\n{\n Node* left;\n Node* right;\n int val;\n ll count;//to store coun
SJ4u
NORMAL
2021-10-25T11:16:49.244339+00:00
2021-10-25T11:16:49.244413+00:00
92
false
```\n\n\n\n#define ll long long\nclass Solution {\npublic:\n \n struct Node\n{\n Node* left;\n Node* right;\n int val;\n ll count;//to store count(left)+count(right)\n Node(int c)\n {\n left=NULL;\n right=NULL;\n count=0;\n val=c;\n }\n};\n\n \n \n //norma...
1
0
['Depth-First Search', 'C']
1
count-nodes-with-the-highest-score
DFS solution Python
dfs-solution-python-by-jinghuayao-bovz
\nclass Solution:\n """\n Deleting a node can yield at most 3 branches\n """\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n
jinghuayao
NORMAL
2021-10-24T23:06:32.776605+00:00
2021-10-24T23:06:32.776649+00:00
75
false
```\nclass Solution:\n """\n Deleting a node can yield at most 3 branches\n """\n def countHighestScoreNodes(self, parents: List[int]) -> int:\n \n # build a graph representation\n graph = collections.defaultdict(set)\n for node, parent in enumerate(parents):\n graph[p...
1
0
[]
0
count-nodes-with-the-highest-score
[JAVA] Easy + Clear Explanation + Clean Code O(N)
java-easy-clear-explanation-clean-code-o-0594
As shown in the image Below :\nwe Just need to find the No of Nodes in Left Sub-Tree , Right SubTree and the parent SubTree \nand multiply them to find the prod
embrane
NORMAL
2021-10-24T14:34:05.703913+00:00
2021-10-24T14:34:05.703952+00:00
622
false
As shown in the image Below :\nwe Just need to find the No of Nodes in Left Sub-Tree , Right SubTree and the parent SubTree \nand multiply them to find the product generated if we remove the current Node \n**Steps** :\n1. DFS to find the No of Nodes in each subTree \n2. no for i in Range 0 to N-1 cal the Above Product...
1
8
['Dynamic Programming', 'Tree', 'Depth-First Search', 'Java']
0
count-nodes-with-the-highest-score
C++ DFS; Will work for n-ary tree also; Separate score and size count;
c-dfs-will-work-for-n-ary-tree-also-sepa-v4bo
I separate the computation of the score for each node from the computation of the size of the node. This code will also work for a N-ary tree.\n\n\nclass Soluti
equine
NORMAL
2021-10-24T08:08:33.134881+00:00
2021-10-24T13:33:12.520870+00:00
123
false
I separate the computation of the score for each node from the computation of the size of the node. This code will also work for a N-ary tree.\n\n```\nclass Solution {\npublic:\n int dfs(int u, vector<vector<int>>& graph,vector<int>& numNodes) {\n numNodes[u] = 1;\n for (int v : graph[u]) {\n ...
1
0
['Depth-First Search', 'C']
0
count-nodes-with-the-highest-score
[Python] DFS
python-dfs-by-waywardcc-vm8u
\nclass Solution(object):\n def countHighestScoreNodes(self, parents):\n """\n :type parents: List[int]\n :rtype: int\n """\n
waywardcc
NORMAL
2021-10-24T05:59:37.792636+00:00
2021-10-24T05:59:37.792686+00:00
83
false
```\nclass Solution(object):\n def countHighestScoreNodes(self, parents):\n """\n :type parents: List[int]\n :rtype: int\n """\n hmap = collections.defaultdict(list)\n n = len(parents)\n for i in range(n):\n if parents[i] != -1:\n hmap[parent...
1
0
[]
0
count-nodes-with-the-highest-score
C++ Easy Solution Using DFS
c-easy-solution-using-dfs-by-saiteja_bal-h81h
\nclass Solution {\npublic:\n int countHighestScoreNodes(vector<int>& p) {\n int n=p.size();\n vector<vector<int>> child(n);\n \n
saiteja_balla0413
NORMAL
2021-10-24T05:07:29.532271+00:00
2021-10-24T05:11:33.285915+00:00
176
false
```\nclass Solution {\npublic:\n int countHighestScoreNodes(vector<int>& p) {\n int n=p.size();\n vector<vector<int>> child(n);\n \n for(int i=1;i<n;i++)\n {\n child[p[i]].push_back(i);\n }\n int cnt=0;\n long long maxi=0;\n solve(0,child,n,ma...
1
0
['C']
1
count-nodes-with-the-highest-score
Java | DFS
java-dfs-by-shubham242k-vvrv
\nclass Solution {\n int n;\n ArrayList<Integer>[] tree;\n long[] res;\n public int countHighestScoreNodes(int[] parents) {\n n = parents.len
shubham242k
NORMAL
2021-10-24T04:21:18.256371+00:00
2021-10-24T04:22:14.405783+00:00
96
false
```\nclass Solution {\n int n;\n ArrayList<Integer>[] tree;\n long[] res;\n public int countHighestScoreNodes(int[] parents) {\n n = parents.length;\n tree = new ArrayList[n];\n for(int i = 0 ; i < n ; i++)tree[i] = new ArrayList<>();\n \n for(int i = 1 ; i < n ; i++){\n ...
1
0
[]
0
count-nodes-with-the-highest-score
[Python] DFS count nodes - 1,2,3 edges
python-dfs-count-nodes-123-edges-by-coco-9516
User DFS to count all nodes for the tree.\nThen iterate through all nodes. There are 3 cases after removing a node:\n- it has 1 edge: n-1\n- it has 2 edges: chi
coco987
NORMAL
2021-10-24T04:07:42.414018+00:00
2021-10-24T04:07:42.414048+00:00
86
false
User DFS to count all nodes for the tree.\nThen iterate through all nodes. There are 3 cases after removing a node:\n- it has 1 edge: n-1\n- it has 2 edges: child_count * (n - 1 - child_count)\n- it has 3 edges: L_count * R_count * (n-1-L_count-R_count)\n\nNote: root 0 is a special case. Treat it seperately.\n\n```\ncl...
1
0
[]
0
count-nodes-with-the-highest-score
🎨 The ART of Dynamic Programming
the-art-of-dynamic-programming-by-clayto-8ffu
\uD83C\uDFA8 The ART of Dynamic Programming: let cnt[i] be the count of nodes for each ith subtree, then we can use deductive reasoning to calculate the cardina
claytonjwong
NORMAL
2021-10-24T04:00:35.959289+00:00
2022-12-26T17:01:05.144743+00:00
336
false
[\uD83C\uDFA8 The ART of Dynamic Programming:](https://leetcode.com/discuss/general-discussion/712010/The-ART-of-Dynamic-Programming-An-Intuitive-Approach%3A-from-Apprentice-to-Master) let `cnt[i]` be the count of nodes for each `i`<sup>th</sup> subtree, then we can use deductive reasoning to calculate the cardinality ...
1
1
[]
0
count-nodes-with-the-highest-score
Simple Java solution with Approach and Proper comments
simple-java-solution-with-approach-and-p-l34g
IntuitionWe need to build the Tree and as mentioned in the problem remove each Node and see how many subtrees remnaining key point in this problem is how to fin
user5958h
NORMAL
2025-04-06T13:11:13.693505+00:00
2025-04-06T13:11:13.693505+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> We need to build the Tree and as mentioned in the problem remove each Node and see how many subtrees remnaining key point in this problem is how to find the parent level nodes ``` 5 4. 3 1...
0
0
['Java']
0
count-nodes-with-the-highest-score
Simple Java solution with Approach and Proper comments
simple-java-solution-with-approach-and-p-8a57
IntuitionWe need to build the Tree and as mentioned in the problem remove each Node and see how many subtrees remnaining key point in this problem is how to fin
user5958h
NORMAL
2025-04-06T13:11:10.796268+00:00
2025-04-06T13:11:10.796268+00:00
12
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> We need to build the Tree and as mentioned in the problem remove each Node and see how many subtrees remnaining key point in this problem is how to find the parent level nodes ``` 5 4. 3 1...
0
0
['Java']
0
count-nodes-with-the-highest-score
Java simple solution beats 90%. With Explanations
java-simple-solution-beats-90-with-expla-1jd7
IntuitionThe intuition is if we have a size aware binary tree then we can calculate the score of each node in constant time(linear overall). Once we remove a no
cutkey
NORMAL
2025-04-04T05:59:34.925258+00:00
2025-04-06T16:51:41.399658+00:00
12
false
# Intuition The intuition is if we have a size aware binary tree then we can calculate the score of each node in constant time(linear overall). Once we remove a node then the size of the tree with remaining nodes is root.size - node.size. The left and right nodes of the node that are removed will have sizes left.size a...
0
0
['Java']
0
count-nodes-with-the-highest-score
Fast Python approach using two DFS's
fast-python-approach-using-two-dfss-by-y-o9ia
IntuitionNotice the problem requires an operation on each node, meaning DFS is applicable. Next, for each node, we need to know the size of the subtrees it is c
yunbo2016
NORMAL
2025-03-11T02:43:20.399462+00:00
2025-03-11T02:43:20.399462+00:00
7
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> Notice the problem requires an operation on each node, meaning DFS is applicable. Next, for each node, we need to know the size of the subtrees it is connected to. This information can also be calcualted with a DFS. # Approach <!-- Descri...
0
0
['Python3']
0
count-nodes-with-the-highest-score
Java
java-by-najmamd-sqoy
IntuitionApproachComplexity Time complexity: Space complexity: Code
NajmaMd
NORMAL
2025-03-05T17:37:26.331714+00:00
2025-03-05T17:37:26.331714+00:00
8
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0