Check Whether Every Shelf Diagonal Holds the Same SKU

Last updated: November 29, 2026

Quick Overview

A planogram grid assigns a SKU code to each shelf slot. Return True if every top-left to bottom-right diagonal contains a single repeated SKU, which is how a cascading display layout is defined.

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

0

0

0 solved


A planogram grid assigns a SKU code to each shelf slot. Return True if every top-left to bottom-right diagonal contains a single repeated SKU, which is how a cascading display layout is defined.

Retail store teams use repeating diagonal displays, so verifying a layout is a quick matrix check. The interviewer looks for the neighbor comparison insight and then asks how you would verify a grid too large to fit in memory.

What the Interviewer Expects
  • Compare each cell with its upper-left neighbor
  • Skip the first row and column
  • Return early on the first mismatch
  • O(m * n) time and O(1) space
  • Handle the streaming follow-up by keeping only the previous row
Key Topics to Cover
matrix
diagonals
streaming rows
early exit
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 fits in memory at a time?
  • What if only part of a row fits in memory?
  • How would you report every diagonal that breaks the rule?
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: an m x n grid of strings or integers. Output: True when grid[i][j] equals grid[i-1][j-1] for every i, j >= 1. Rows all have the same length....

High-Level Design

Each diagonal is a chain of cells linked by the upper-left relation, so the property holds exactly when every cell (except those in row 0 or column 0) equals its upper-left neighbor. That reduces the ...


Submit Your Answer
Markdown supported