Find Largest Value in Each Tree Row
MediumTreeslevel order
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given the root of a binary tree, return a list whose i-th entry is the largest value found on row i of the tree (the root is row 0).
Return the entries from the top row down. An empty tree yields [].
Examples
Input: root = [1,3,2,5,3,null,9]
Output: [1,3,9]
Rows are [1], [3,2] and [5,3,9].
Input: root = [1,2,3]
Output: [1,3]
Rows are [1] and [2,3].
Constraints
- 0 <= number of nodes <= 10^4
- -2^31 <= Node.val <= 2^31 - 1
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.