MEDIUMasked at 2 companies

Find Largest Value in Each Tree Row

A medium-tier problem at 66% community acceptance, tagged with Tree, Depth-First Search, Breadth-First Search. Reported in interviews at LinkedIn and 1 others.

Founder's read

You're asked to find the largest value in each row of a binary tree. LinkedIn and Apple both ask this. It sounds simple until you realize you need to track which nodes belong to which depth level, and level-order traversal isn't always the first thing people think of. The naive depth-first approach works but feels clunky. You either nail the clean BFS solution in two minutes or you fumble the level tracking and burn time debugging. This is one of those problems where the "correct" approach clicks fast if you've seen the pattern, and stalls if you haven't. If this hits your live OA and you blank on the structure, StealthCoder surfaces a working solution invisibly.

Companies asking
2
Difficulty
MEDIUM
Acceptance
66%

Companies that ask "Find Largest Value in Each Tree Row"

If this hits your live OA

Find Largest Value in Each Tree Row is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.

Get StealthCoder
What this means

The trap is trying to force DFS with some messy level-tracking logic. Yes, it works, but you'll probably get the order wrong or pass depth as a parameter and lose your mind trying to aggregate by level. BFS is the clean answer: queue up the root, process one level at a time, track the max as you go, push the next level to the queue. At each iteration, you know exactly which nodes belong to the current row, so finding the max is one pass through the queue. The gotcha: if you DFS, you need to either recursively build a map of depth to values (extra space, extra thinking) or use a result list and carefully manage indices. BFS sidesteps all that. This appears frequently in company reports and has a 66% acceptance rate, which means half the people who attempt it don't nail it first try. If you're going DFS, pre-think your level-tracking logic. If you're doing BFS, make sure you're actually processing level by level, not just dumping nodes.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find Largest Value in Each Tree Row recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Largest Value in Each Tree Row interview FAQ

Is this problem asking for DFS or BFS?+

Both work, but BFS is cleaner. You queue nodes level by level, so at each iteration you know exactly which nodes represent the current row. Track the max as you dequeue. DFS requires explicit level tracking via recursion depth or a separate map, adding cognitive overhead.

How do I track which nodes belong to which level in DFS?+

Pass depth as a parameter to your recursive function. Maintain a result list or map indexed by depth. On each call, update the max value for that depth. It works, but you'll do more bookkeeping than BFS. Common mistake: forgetting to initialize the result at a new depth level.

What's the time and space complexity?+

Time is O(n) because you visit every node once. Space is O(w) where w is the maximum width of the tree (the largest level has w nodes). In a worst-case skewed tree, that's O(n). Both BFS and DFS hit these bounds.

Is this still asked at Apple and LinkedIn?+

Yes. Both companies report it in hiring loops. The 66% acceptance rate suggests it's a solid problem that screens for basic tree traversal chops. If you miss the BFS pattern, you'll code something that works but feels inefficient, which interviewers notice.

What if the tree is null or has one node?+

If the tree is null, return an empty list. If it's one node, return a list containing that node's value. These are edge cases your code should handle without special logic. BFS naturally handles them; DFS too if you test before submitting.

Want the actual problem statement? View "Find Largest Value in Each Tree Row" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.