Code RoomBinary tree right side view
MediumPrep Room Coding #201

Binary tree right side view

CodingAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
[[1,2,3,-1,5,-1,4]][1,3,4]not run yetsample