You are given a 2D grid representing a terrain map with three types of cells: • 'T' - Radio tower (emits signals) • 'M' - Mountain (blocks signals) • '.' - Empty cell (signals pass through) Each radio tower broadcasts signals in 4 cardinal directions (up, down, left, right). A signal travels in a straight line until it either: • Hits a mountain (signal stops) • Reaches the grid boundary (signal stops) Your task: Determine which pairs of radio towers can communicate with each other. Two towers can communicate if a signal from one tower can reach the other tower. Input Format grid = [ ['T', '.', '.', 'T'], ['.', 'M', '.', '.'], ['T', '.', '.', 'T'] ] Example 1: Basic Line of Sight Input: T . . T . . . . T . . T Signal Propagation: Tower (0,0) → → → reaches Tower (0,3) ✓ Tower (0,3) ↓ ↓ reaches Tower (2,3) ✓ Tower (2,0) → → → reaches Tower (2,3) ✓ Tower (0,0) ↓ ↓ reaches Tower (2,0) ✓ Output: [ ((0, 0), (0, 3)), # Top-left ↔ Top-right ((0, 3), (2, 3)), # Top-right ↔ Bottom-right ((2, 0), (2, 3)), # Bottom-left ↔ Bottom-right ((0, 0), (2, 0)) ] Total communicating pairs: 4
Coding question were building a word game feature. Given a 2d from user tray and dictionary of valid words return all the words found by connecting adjavent cells
board =
o a a n
e t a e
i h k r
i f l v
words = ["oath","pea","eat","rain"]
Output:
["oath","eat"]