Not sure what to study next?

Get a personalised quant interview roadmap built around your upcoming interviews, strengths and weaknesses.

Takes a few minutes. Start with your target role and firms.

← Programming questions
Medium / PYTHON

Maximum Depth of an Indexed Binary Tree

trees · depth_first_search · stacks 22 minute study target

Not completed

Challenge

Find the maximum number of nodes on a root-to-leaf path. A root by itself has depth 1; an empty tree has depth 0. The tree is a flat list: nodes[i]=[value, left_index, right_index]. Child indices are zero-based or null (None in Python). The root is index 0. All nodes are reachable exactly once, no cycles or shared children exist, and indices do NOT imply positions in a complete binary tree.

Input and output contract

0 ≤ n ≤ 60,000; integer node values with absolute value ≤ 1,000,000. Very deep chains are valid: do not rely on Python’s default recursion limit. Input need not be breadth-first ordered.

All tests follow this contract. You do not need to validate malformed input. Return the requested result from tree_maximum_depth; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.

Target complexity: O(n) time; O(h) auxiliary stack space

Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.

Public examples

Example 1

Arguments

[[[10, 2, 1], [30, None, None], [20, None, 3], [40, None, None]]]

Expected return

3
Example 2

Arguments

[[]]

Expected return

0
Example 3

Arguments

[[[7, None, None]]]

Expected return

1
Hint

Put (node_index, depth) on an explicit stack. Only missing children are None; index 0 is not a missing-value marker.

The worked solution unlocks after completion, or with Premium access.

tree_maximum_depth.pyPython 3.12

Drafts are saved to your account, not to shared browser storage.

Sign in to submit code and save progress.

Results

Your results will appear here.

Hidden tests reveal only their pass/fail status, never their inputs or expected outputs. Runtime is observed wall time—not an inferred complexity class.

Join our Newsletter and Receive the Latest Updates!

Main Links

Trade Courses Assessments Interview Prep Contact Us

Social Media

Facebook Instagram YouTube

Legal

Terms and Conditions Privacy Policy Privacy settings

Talent Acquisition

Looking to hire exceptional quant talent?
See how we can help.

© 2026 EverythingQuant. All Rights Reserved.