Quant Memo
Coding/●●●●

Trace a pattern through a grid of tiles

You have a grid of single-character tiles. Decide whether a target pattern can be traced as a path of orthogonally adjacent tiles (up/down/left/right), where each tile is used at most once per path.

grid = [["A","B","C"],
        ["S","F","D"],
        ["A","D","E"]]
pattern = "ABFDE"  ->  True     # (0,0)->(0,1)->(1,1)->(2,1)->(2,2)

Return whether the pattern exists as a non-self-intersecting path in the grid.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions