Roof cell shading
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.
shaded_panel_cells(heights: list[list[int]], light_from: str) → list[list[int]][[[3,1,2],[1,4,4]],"W"]out[[0,1],[0,2]][[[3,1,2],[1,4,4]],"E"]out[[0,1],[1,0]][[[2,2],[1,3]],"N"]out[[1,0]]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.
[[[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