r/LeetcodeChallenge • • 10h ago

STREAK🔥🔥🔥 LeetCode: 1315. Sum of Nodes with Even-Valued Grandparent

Post image
1 Upvotes

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


r/LeetcodeChallenge • • 13h ago

STREAK🔥🔥🔥 LeetCode: 1026. Maximum Difference Between Node and Ancestor

Post image
1 Upvotes

Every ancestor/descendant pair sits on one root-to-leaf path, so you never compare pairs. Carry the path's max and min down. The widest gap on a path is max minus min.

Check it at the leaves. Going down, the max never falls and the min never rises, so the gap is widest at the bottom of every path.

Two days ago we carried one value down the tree. Today it's two.

What's the most state you've carried down a recursion?

Day 89/365 of my LeetCode challenge: 1026. Maximum Difference Between Node and Ancestor. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-maximum-difference-between-node-ancestor-archit-agarwal-g6ibe

#LeetCode #DSA #BinaryTree #Golang


r/LeetcodeChallenge • • 23h ago

STREAK🔥🔥🔥 Day 13: kicked off Binary Search with 6 foundational boundary problems

Thumbnail reddit.com
1 Upvotes

r/LeetcodeChallenge • • 23h ago

STREAK🔥🔥🔥 Leetcode 1201 POTD(1-Dec-2026) | Ugly Number-III

Thumbnail
leetcode.com
1 Upvotes

An ugly number is a positive integer that is divisible by a, b, or c.

Given four integers n, a, b, and c, return the n``th ugly number.

 

Example 1:

Input:
 n = 3, a = 2, b = 3, c = 5
Output:
 4
Explanation:
 The ugly numbers are 2, 3, 4, 5, 6, 8, 9, 10... The 3
rd
 is 4.

Example 2:

Input:
 n = 4, a = 2, b = 3, c = 4
Output:
 6
Explanation:
 The ugly numbers are 2, 3, 4, 6, 8, 9, 10, 12... The 4
th
 is 6.

Example 3:

Input:
 n = 5, a = 2, b = 11, c = 13
Output:
 10
Explanation:
 The ugly numbers are 2, 4, 6, 8, 10, 11, 12, 13... The 5
th
 is 10.

 

Constraints:

  • 1 <= n, a, b, c <= 10``9
  • 1 <= a * b * c <= 10``18
  • It is guaranteed that the result will be in range [1, 2 * 10``9``].