Code RoomRoof cell shading
EasyPrep Room Coding #4843

Roof cell shading

CodingAlgorithms & data structuresEntry–Mid~15 min

A solar contractor models late afternoon shading on a flat roof. The roof arrives as a rectangular grid of cells, and heights[r][c] holds the height in centimetres of whatever stands on that cell, with 0 for bare deck and no negative values. The sun sits low on one side, so light crosses the roof in straight lines from the side named by light_from: 'W' runs it left to right along each row, 'E' right to left along each row, 'N' top to bottom down each column, and 'S' bottom to top up each column. A cell is shaded when some cell the light already passed on that same line stands strictly taller than it. Equal height clears. Return every shaded cell as a [row, column] pair, sorted by row and then by column. Every row has the same width.

Implement
shaded_panel_cells(heights: list[list[int]], light_from: str) → list[list[int]]
Examples
in[[[3,1,2],[1,4,4]],"W"]out[[0,1],[0,2]]
in[[[3,1,2],[1,4,4]],"E"]out[[0,1],[1,0]]
in[[[2,2],[1,3]],"N"]out[[1,0]]
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 15 min
InputExpectedGot
[[[3,1,2],[1,4,4]],"W"][[0,1],[0,2]]not run yetsample
[[[3,1,2],[1,4,4]],"E"][[0,1],[1,0]]not run yetsample
[[[2,2],[1,3]],"N"][[1,0]]not run yetsample