r/LeetcodeChallenge • u/StatisticianNo2104 • 2d ago
STREAK🔥🔥🔥 LeetCode: 1315. Sum of Nodes with Even-Valued Grandparent
Tree nodes can't see their grandparents. The recursion can, because it just walked through them. Each call takes (parent, grandparent) and passes (itself, parent) to its children: a two-node window sliding down the tree.
Check the grandparent's value at each node. Nil for "none" means the root and its children need no special case.
Third day running of passing state down instead of up.
Would you have stored parent pointers instead?
Day 90/365 of my LeetCode challenge: 1315. Sum of Nodes with Even-Valued Grandparent. Problem link and full breakdown in today's newsletter.
https://www.linkedin.com/pulse/leetcode-sum-nodes-even-valued-grandparent-archit-agarwal-oe5re
#LeetCode #DSA #BinaryTree #Golang
1
u/nian2326076 1d ago
Storing parent pointers can simplify certain cases in your recursion challenges, but it also complicates memory management. For improving your skills in data structures and algorithms, you can use PracHub to practice specific technical interview questions and get comfortable explaining your solutions.