2026 April 18 Problems

14 views
Skip to first unread message

daryl...@gmail.com

unread,
Apr 18, 2026, 12:55:01 PM (2 days ago) Apr 18
to leetcode-meetup
Feel free to work on any of the problems you want; we'll have people present their solutions at 11:30.

Please post your solutions to this thread so others can use this as a reference.

Medium and hard problems are carried over from last week.


3607. Power Grid Maintenance Medium 56.2%



We will have a different Zoom meeting that Bhupathi is providing this week:

Here is the meeting url:

Full details:

Topic: Leet Code meeting
Time: Mar 28, 2026 10:00 AM Pacific Time (US and Canada)
        Every week on Sat, 110 occurrence(s)
Please download and import the following iCalendar (.ics) files to your calendar system.
Weekly: https://us05web.zoom.us/meeting/tZYocuqgqzMuH9IuHUphHIiZ_4T4IndJLToX/ics?icsToken=DJFc88pL6-me_TneLwAALAAAAA70ShjYgLH6RfEnqUm5LK03v2OgtbXujwlKXRMVgIVWCY9aONPJMCycMlkhyPZ3XSrMVVgXDSYlGF_r7DAwMDAwMQ&meetingMasterEventId=MGJmt5lJTd6mPygcS0hiAQ
Join Zoom Meeting
https://us05web.zoom.us/j/82553858456?pwd=fnK5Vb0CcfFpv0lnouILjeEs2z2Khc.1

Meeting ID: 825 5385 8456
Passcode: 182596

Anuj Patnaik

unread,
Apr 18, 2026, 1:05:34 PM (2 days ago) Apr 18
to leetcode-meetup
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def sumEvenGrandparent(self, root: Optional[TreeNode]) -> int:
sum_ = 0
if(root == None):
return 0
else:
if root.val % 2 == 0:
if root.left != None:
if root.left.left != None:
sum_+= root.left.left.val
if root.left.right != None:
sum_+= root.left.right.val
if root.right != None:
if root.right.left != None:
sum_+= root.right.left.val
if root.right.right != None:
sum_ += root.right.right.val
left_sum = Solution.sumEvenGrandparent(self, root.left)
right_sum = Solution.sumEvenGrandparent(self, root.right)
return left_sum + sum_ + right_sum



Bhupathi Kakarlapudi

unread,
Apr 18, 2026, 2:34:21 PM (2 days ago) Apr 18
to leetcod...@googlegroups.com
class Solution:
def sumEvenGrandparent(self, root: Optional[TreeNode]) -> int:
if not root:
return 0
total = 0
# stack entries: (node, parent_val, grandparent_val)
stack = [(root, None, None)]
while stack:
node, parent, grandparent = stack.pop()
if grandparent is not None and grandparent % 2 == 0:
total += node.val
# Push children with updated parent/grandparent context
if node.right:
stack.append((node.right, node.val, parent))
if node.left:
stack.append((node.left, node.val, parent))
return total

--
whatspp group: http://whatsapp.techbayarea.us/
---
You received this message because you are subscribed to the Google Groups "leetcode-meetup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leetcode-meet...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/leetcode-meetup/19354b91-617d-49bb-ba3b-8d34a54c1510n%40googlegroups.com.

Rudy W

unread,
Apr 18, 2026, 7:04:45 PM (2 days ago) Apr 18
to leetcod...@googlegroups.com
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def sumEvenGrandparent(self, root: Optional[TreeNode]) -> int:
# intuition: traverse the tree using dfs
# while keeping track of parent and grandparent

if not root:
return 0

sum = 0
# p : parent
# gp : grandparent
def dfs(root, p, gp):
nonlocal sum

if not root:
return
# check if grand parent is not None
# and its value is even
if gp and gp.val % 2 == 0:
sum += root.val

# before traversing down to root's child(s),
# update the parent and grandparent nodes
gp = p # the grandparent is now the parent of current node
p = root # and the parent is current node

dfs(root.left, p, gp)
dfs(root.right, p, gp)
# start from the root node, it has no parent and no grandparent
# so both will be None values
dfs(root, None, None)

return sum


Reply all
Reply to author
Forward
0 new messages