Check Whether a Sheets Range Is Constant Along Every Diagonal

Last updated: November 29, 2026

Quick Overview

Given an m x n grid of values copied from a Google Sheets range, return True if every top-left to bottom-right diagonal holds a single repeated value (a Toeplitz matrix), and False otherwise.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given an m x n grid of values copied from a Google Sheets range, return True if every top-left to bottom-right diagonal holds a single repeated value (a Toeplitz matrix), and False otherwise.

A warm-up in the Google phone screen style: a tiny grid check that leaves room for a streaming follow-up. The interviewer wants a clean neighbor comparison instead of building every diagonal, and then wants to see how you would adapt when rows arrive one at a time from storage.

What the Interviewer Expects
  • Notices that each cell only needs to match its upper-left neighbor
  • Avoids materializing diagonals into extra lists
  • Handles single-row and single-column grids
  • Runs in O(mn) time and O(1) extra space
  • Discusses the row-at-a-time streaming variant
Key Topics to Cover
Matrix Traversal
Diagonals
Neighbor Comparison
Streaming
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Rows are streamed from disk and only one previous row fits in memory; what changes?
  • Only a partial row fits in memory at a time; how would you still verify the property?
  • Return the first diagonal that breaks the rule instead of a boolean.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: grid, a non-empty list of equal-length rows.
  • Output: True when grid[r][c] == grid[r-1][c-1] holds for every cell that has an upper-left neighbor.
  • A 1 x n or m x 1 grid is trivially ...
High-Level Design

Every diagonal is a chain of cells linked by the step (r-1, c-1). If each cell equals its predecessor on that chain, the whole chain is constant by induction. So a single pass over cells with `r >= ...


Submit Your Answer
Markdown supported