Code Room
CodingMediumcod-g104
Subject QueuesLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A binary tree is given in level-order array form where null children are represented by the value None... but to keep inputs JSON-friendly, it is given as a flat list using -1 as the null sentinel (all real node values are non-negative). Index 0 is the root; for a node at index i its left child is at 2*i+1 and right at 2*i+2 within the dense array (missing children are -1). Return the right-side view: the list of values visible from the right at each depth, top to bottom. The array has 0 to 2000 entries and the root, if present, is never -1.

Implement
right_side_view(tree: list[int]) → list[int]
Examples
in[[1,2,3,-1,5,-1,4]]out[1,3,4]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.