Reported September 2026
Googledynamic programming

Longest Consecutive Same-Color Line

Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Google OA. Under 2s to a working solution.
Founder's read

Google reported this one in September 2026, and the trap is right in the title: it looks like a simple grid scan, but a first attempt usually breaks on the diagonals. You get a grid of uppercase letters and need the longest same-color run in four directions: horizontal, vertical, down-right, and down-left. It's a grid DP problem that feels easier than it is. If you blank on the direction bookkeeping during the live OA, StealthCoder runs invisibly as a safety net and gives you the solution on screen. Better to walk in already knowing the trick.

The problem

You are given a non-empty rectangular grid of uppercase color symbols. The grid is represented by grid, where grid[row][column] is the color at that cell.
A same-color line is a contiguous sequence of cells that all contain the same symbol. A line may extend in exactly one of these four orientations:
horizontally from left to right,
vertically from top to bottom,
diagonally down and right, or
diagonally down and left.
Return the maximum number of cells in any same-color line.

Function
longestSameColorLine(grid: String[]) → int

Examples
Example 1
grid = ["RRRG","RRBB","GRRR","BGBR"]
return = 4
The cells from (0, 0) through (3, 3) form a down-right diagonal of four R symbols. No longer line exists.
Example 2
grid = ["RRGGGG"]
return = 4
The only row ends with four consecutive G symbols, so the longest line has length 4.
Example 3
grid = ["R","G","G","G"]
return = 3
The single column contains a vertical run of three consecutive G symbols.

Constraints
1 <= grid.length <= 1000.
1 <= grid[i].length <= 1000.
Every row has the same length.
The total number of cells is at most 100000.
Every cell contains one uppercase English letter from A through Z.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is one DP table per direction. For each cell, store the length of the run ending at that cell. For horizontal, look at the left neighbor. For vertical, look up. For down-right, look up-left. For down-left, look up-right. If the neighbor has the same letter, your value is neighbor + 1, otherwise it's 1. Track the max as you go. That's O(rows * cols) time, and it fits the 100000 cell cap easily. The classic mistake is checking only rows and columns, or handling the down-left diagonal with the wrong neighbor and going out of bounds on the last column. Another one is resetting the max per row instead of globally. Keep four values per cell, or keep only the previous row to save memory. If the indexing gets tangled mid-assessment, StealthCoder is the hedge that lays out the clean version while the proctor sees nothing.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Longest Consecutive Same-Color Line cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Google's OA.

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Longest Consecutive Same-Color Line FAQ

What's the trick in the Google longest same-color line problem?+

Run a DP where each cell stores the length of the same-color run ending there, once per direction. Each value depends only on one neighbor: left, up, up-left, or up-right. Match the letter and add 1, otherwise reset to 1. Keep a global max.

How hard is this problem really?+

Easy to medium. The idea is simple, but the four directions and boundary checks cause bugs. If you've done the longest line of consecutive ones in a matrix problem, this is nearly the same thing with letters instead of ones.

Do I need a full 2D table for each direction?+

No. Each cell only looks at the previous row, so you can keep two rows per direction. With at most 100000 cells, a full table is fine too. Pick whichever you can write without off-by-one errors under pressure.

What edge cases should I test?+

A single cell grid returns 1. A single row or single column works as a pure horizontal or vertical case, like examples 2 and 3. Check the first and last columns for the down-left diagonal, and make sure the max starts at 1, not 0.

How do I prepare in 48 hours for this kind of OA?+

Write this problem from scratch twice, once with a full table and once with rolling rows. Then do two or three other grid DP problems that check neighbors. Focus on neighbor indexing and bounds checks, since that's where first attempts fail.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Google.

OA at Google?
Invisible during screen share
Get it