Code RoomCount valid pipe boards
MediumPrep Room Coding #4946

Count valid pipe boards

CodingAlgorithms & data structuresMid–Senior~28 min

A puzzle game ships a board of pipe tiles and the level tool has to know how many finished boards exist. tile_rows gives the board one row at a time, every row the same width, and each entry is four characters reading a tile's open ends clockwise from the top, north then east then south then west, where 1 is an open end and 0 is a wall, so 0110 is open on the east and the south. A player may turn a tile to any of its four quarter turns. A board is finished when every open end meets an open end on the neighbouring tile and no open end points off the board. Two finished boards are the same when every square shows the same four characters, so turning a tile that reads the same after a quarter turn does not make a new board. Return how many finished boards exist. The board is at most 4 by 4.

Implement
count_pipe_layouts(tile_rows: list[list[str]]) → int
Examples
in[[["1100","1100"],["1100","1100"]]]out1
in[[["1000","1000"],["1000","1000"]]]out2
in[[["0000","0000"],["0000","0000"]]]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 28 min
InputExpectedGot
[[["1100","1100"],["1100","1100"]]]1not run yetsample
[[["1000","1000"],["1000","1000"]]]2not run yetsample
[[["0000","0000"],["0000","0000"]]]1not run yetsample