Find the Longest Straight Run of One Color
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: Find the longest straight run of equal-colored cells across horizontal, vertical, and both diagonal directions in a rectangular grid.
Constraints
- grid is a nonempty list of equally long nonempty strings.
- The total number of cells is at most 1000000; no smaller independent dimension cap is imposed.
- Every cell is an uppercase English letter A through Z.
- Count only consecutive equal-color cells along one horizontal, vertical, down-right or down-left line; do not turn, skip or wrap.
Examples
Input: (['RRRG', 'RRBB', 'GRRR', 'BGBR'],)
Expected Output: 4
Explanation: Published sample 1: the main diagonal consists of four R cells.
Input: (['RBG', 'BGR', 'GRB'],)
Expected Output: 3
Explanation: Published sample 2: three G cells form the down-left diagonal.