Check Constant Values along Down-Right Diagonals

Quick Overview

Check Constant Values along Down-Right Diagonals. Return whether every diagonal running from upper left to lower right in matrix contains one repeated value.

Check Constant Values along Down-Right Diagonals

Company: TCS

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return whether every diagonal running from upper left to lower right in matrix contains one repeated value. Single-cell diagonals satisfy the condition. ```cpp class Solution { public: bool isToeplitzMatrix(vector<vector<int>>& matrix); }; ``` ### Examples **Example 1:** ```text matrix = [[4,7,2],[9,4,7]] Output: true Explanation: Every cell with an upper-left neighbor matches that neighbor. ``` **Example 2:** ```text matrix = [[4,7],[9,5]] Output: false Explanation: The diagonal containing 4 and 5 differs. ``` ### Constraints - Rectangular matrix dimensions are each in [1,20]. - Entries are integers from 0 through 99. ### Contract considerations Only down-right diagonals matter. ```hint Read the boundary condition Which local equality connects consecutive members of a diagonal? ``` ### Boundary reminders Only down-right diagonals matter. ### Optional extensions - How would you check a disk-backed matrix when memory can retain only one row? - How would you process it if even a complete row cannot fit, retaining the necessary diagonal boundary between chunks?

Overview: Check Constant Values along Down-Right Diagonals. Return whether every diagonal running from upper left to lower right in matrix contains one repeated value.

TCS logo
TCS
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return whether every diagonal running from upper left to lower right in matrix contains one repeated value. Single-cell diagonals satisfy the condition.

class Solution {
public:
    bool isToeplitzMatrix(vector<vector<int>>& matrix);
};

Examples

Example 1:

matrix = [[4,7,2],[9,4,7]]
Output: true
Explanation: Every cell with an upper-left neighbor matches that neighbor.

Example 2:

matrix = [[4,7],[9,5]]
Output: false
Explanation: The diagonal containing 4 and 5 differs.

Constraints

  • Rectangular matrix dimensions are each in [1,20].
  • Entries are integers from 0 through 99.

Contract considerations

Only down-right diagonals matter.

Boundary reminders

Only down-right diagonals matter.

Optional extensions

  • How would you check a disk-backed matrix when memory can retain only one row?
  • How would you process it if even a complete row cannot fit, retaining the necessary diagonal boundary between chunks?