You are given a grid where each cell contains a "street" type (1-6). Each type represents a specific connection (e.g., Type 1 connects Left and Right, Type 2 connects Top and Bottom). You start at the top-left and want to know if there's a path to the bottom-right. Crucially, two adjacent cells only connect if both streets "point" to each other.
Robinhood and other tech companies ask this to test your ability to handle complex conditional logic within a graph traversal. It’s not just about "can I move there?", but "do the pieces fit together?". It evaluates your skills in BFS, DFS, or Union Find and your ability to model connectivity rules cleanly.
The primary pattern is Graph Traversal (BFS or DFS). You treat the grid as a graph where each cell is a node. An edge exists between and if the street type in the first cell allows movement to the second, AND the street type in the second cell allows movement back to the first. You can pre-map the connection rules for each street type to make the traversal logic cleaner.
Cell (0,0) has Type 1 (Left-Right). Cell (0,1) has Type 1 (Left-Right).
The most common mistake is forgetting the "mutual connection" rule—checking if you can move from A to B but not checking if B accepts a connection from A. Another error is overcomplicating the connection logic with a massive if-else block instead of using a clean lookup table or direction-based bitmask.
For problems with complex connectivity rules, use a "Direction Map." For example, map Type 1 -> [Left, Right]. This makes your neighbor-checking code much more readable and less prone to logic errors.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Islands With Total Value Divisible by K | Medium | Solve | |
| Count Sub Islands | Medium | Solve | |
| Detect Cycles in 2D Grid | Medium | Solve | |
| Max Area of Island | Medium | Solve | |
| Maximum Number of Fish in a Grid | Medium | Solve |