Verify That Every Diagonal of a Schedule Grid Holds One Value

Last updated: November 29, 2026

Quick Overview

Given an R x C grid, return True if every diagonal running from top-left to bottom-right contains the same value throughout, and False otherwise.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Given an R x C grid, return True if every diagonal running from top-left to bottom-right contains the same value throughout, and False otherwise.

Appears as a quick first problem in a Meta online assessment or as the opener in a phone screen, framed as checking a rotating on-call schedule grid where each row is the previous row shifted by one. The interviewer cares about a clean neighbor comparison and then about the streaming follow-up, which is where the real discussion happens.

What the Interviewer Expects
  • Compare each cell with its upper-left neighbor instead of walking diagonals explicitly
  • Skip the first row and first column correctly
  • Return early on the first mismatch
  • Discuss the follow-up where only one row fits in memory
  • Keep it O(RC) time and O(1) space
Key Topics to Cover
Matrix traversal
Diagonals
Streaming
Arrays
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
  • What if only one row can be loaded into memory at a time?
  • What if only part of a row fits in memory?
  • How would you check the anti-diagonals instead?
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
  • Grid up to 20 x 20 of small integers, possibly a single row or column.
  • Return True if grid[r][c] == grid[r-1][c-1] holds for every cell with r, c >= 1.
  • Clarify that an empty grid or a single...
High-Level Design

A diagonal is constant exactly when each cell equals the one diagonally above-left of it, because equality chains along the diagonal. That turns the problem into a local check: compare every cell outs...


Submit Your Answer
Markdown supported