2025 October 4 Problems

50 views
Skip to first unread message

daryl...@gmail.com

unread,
Oct 4, 2025, 12:46:45 PM (4 days ago) Oct 4
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.




Please download and import the following iCalendar (.ics) files to your calendar system.

Anuj Patnaik

unread,
Oct 4, 2025, 1:02:51 PM (4 days ago) Oct 4
to leetcode-meetup
"""
# Definition for a Node.
class Node:
def __init__(self, val: Optional[int] = None, children: Optional[List['Node']] = None):
self.val = val
self.children = children
"""

class Solution:
def maxDepth(self, root: 'Node') -> int:
curr = root
stack = [(root, 1)]
max_depth = 0
while len(stack) > 0 and curr != None:
top_elem = stack.pop()
curr = top_elem[0]
depth = top_elem[1]
max_depth = max(max_depth, depth)
for i in curr.children:
stack.append((i, depth + 1))
return max_depth

FloM

unread,
Oct 4, 2025, 1:12:13 PM (4 days ago) Oct 4
to leetcode-meetup
Time: O(n) Mem:(lg(n)) where n is number of nodes.

class Solution {
public:

int maxDepth(Node* root) {
if (root == nullptr)
{
return 0;
}
int max = 0;
for(Node* child : root->children)
{
max = std::max(max, maxDepth(child));
}
return max + 1;
}
};

Eli Manzo

unread,
Oct 4, 2025, 1:12:56 PM (4 days ago) Oct 4
to leetcode-meetup
Won't be able to make it to today's session

time:o(n)
space:o(n)
class Solution: def maxDepth(self, root: 'Node') -> int: res = 0 if not root: return res for child in root.children: res = max(res, self.maxDepth(child)) return res + 1

On Saturday, October 4, 2025 at 10:02:51 AM UTC-7 patnai...@gmail.com wrote:

Joshua Tanaka

unread,
Oct 4, 2025, 1:47:54 PM (4 days ago) Oct 4
to leetcode-meetup
class Solution {
    public int maxDepth(Node root) {
        if(root == null) return 0;
        return depthRecurr(root);
    }

    public int depthRecurr(Node node){
        int max = 0;
        if(node.children.size() == 0) return 1;
        for(int i = 0; i < node.children.size(); i ++){
            int checkNode = depthRecurr(node.children.get(i));
            if (checkNode > max){
                max = checkNode;
            }
        }
        return max + 1;
    }
}

On Saturday, October 4, 2025 at 9:46:45 AM UTC-7 daryl...@gmail.com wrote:

Kevin Burleigh

unread,
Oct 4, 2025, 2:06:41 PM (4 days ago) Oct 4
to leetcode-meetup
Just thought I'd show an example using python's map() function...

## Time: O(nodes)
## Space: O(nodes)
class Solution:
def maxDepth(self, root: 'Node') -> int:
def max_depth(node):
if node is None:
return 0
if len(node.children) == 0:
return 1
return 1 + max(map(max_depth, node.children))
return max_depth(root)


Jerry Nguyen

unread,
Oct 4, 2025, 2:15:47 PM (4 days ago) Oct 4
to leetcode-meetup
# O(n) time complexity
# O(n) space complexity
class Solution:
def maxDepth(self, root: 'Node') -> int:
if not root:
return 0

if not root.children:
return 1

depth = 0
for curr in root.children:
depth = max(depth, self.maxDepth(curr))

return depth + 1

Anuj Patnaik

unread,
Oct 4, 2025, 2:56:30 PM (4 days ago) Oct 4
to leetcode-meetup
Revised Solution for Easy
"""
# Definition for a Node.
class Node:
def __init__(self, val: Optional[int] = None, children: Optional[List['Node']] = None):
self.val = val
self.children = children
"""

class Solution:
def maxDepth(self, root: 'Node') -> int:
if root == None:
return 0
stack = [(root, 1)]
max_depth = 0
while len(stack) > 0:
top_elem = stack.pop()
curr = top_elem[0]
depth = top_elem[1]
max_depth = max(max_depth, depth)
for i in curr.children:
stack.append((i, depth + 1))
return max_depth



vinay

unread,
1:22 AM (2 hours ago) 1:22 AM
to leetcod...@googlegroups.com


Time o(N)
space worst case (skewed tree): o(N)
space average case: o(long(n))
class Solution {

    public int maxDepth(Node root) {
        if(root == null){
            return 0;
        }
       
        if(root.children.isEmpty()){
            return 1;
        }

        int height = 0;
        for(Node child : root.children){
            height = Math.max(height, 1 + maxDepth(child));
        }

        return height;
    }
}

--
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/538de7a7-4f26-4c64-9d1c-0e039108095dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages