r/LeetcodeChallenge • u/StatisticianNo2104 • 10h 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


