Code RoomWidget layout count
MediumPrep Room Coding #4911

Widget layout count

CodingAlgorithms & data structuresMid–Senior~30 min

A dashboard editor drops widgets onto a fixed canvas. The canvas is panel_rows tall and panel_cols wide, and widget i covers a solid rectangle tile_widths[i] columns across and tile_heights[i] rows down. Widgets never rotate, never overlap, never hang off the canvas, and a saved layout places every widget and leaves no cell bare. Two layouts are the same layout when every cell carries a widget of the same size in both, because the editor stores sizes rather than widget identities and equal sized widgets are interchangeable. Return how many different layouts exist. Return 0 when the widget areas do not add up to the canvas area. A canvas with no cells and no widgets has exactly one layout, the empty one, so return 1 there. There are at most 8 widgets and at most 24 cells.

Implement
count_panel_tilings(panel_rows: int, panel_cols: int, tile_widths: list[int], tile_heights: list[int]) → int
Examples
in[2,3,[1,2],[2,2]]out2
in[2,4,[1,1,2,2],[2,2,1,1]]out3
in[2,2,[1,1,1,1],[1,1,1,1]]out1
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 30 min
InputExpectedGot
[2,3,[1,2],[2,2]]2not run yetsample
[2,4,[1,1,2,2],[2,2,1,1]]3not run yetsample
[2,2,[1,1,1,1],[1,1,1,1]]1not run yetsample