Validate a Two-Color Chessboard
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon reported this one in September 2026, and it looks too easy until a single-cell or single-row board hits your code. The task: check that a 0/1 matrix is a valid two-color chessboard, where every horizontal and vertical neighbor differs. It's a matrix scan, nothing fancy. The risk is sloppy bounds and assuming the board is bigger than it is. If you've got an Amazon OA coming, expect to write this in a few minutes, and expect the edge cases to decide whether it passes. StealthCoder sits invisibly as a safety net if your mind goes blank mid-assessment.
The problem
You are given a nonempty rectangular integer matrix board. Every cell is one of two colors, encoded as 0 or 1. Return true if board is a valid chessboard pattern: every pair of horizontally adjacent cells has different colors, and every pair of vertically adjacent cells has different colors. Otherwise, return false. Function isValidChessboard(board: int[][]) → boolean Examples Example 1 board = [[0,1,0],[1,0,1]] return = true Every horizontal and vertical neighbor has the opposite color. Example 2 board = [[0,1],[1,1]] return = false The two cells in the bottom row have the same color, so the pattern is invalid. Constraints 1 <= board.length <= 100 1 <= board[i].length <= 100 Every row has the same length. board[i][j] is either 0 or 1.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that you don't need to compare neighbors at all. A valid chessboard means cell (i,j) equals board[0][0] XOR ((i+j) mod 2). Loop over every cell, check that rule, and return false on the first mismatch. The alternative is checking right and down neighbors only, which also works and avoids double-checking. The pitfall is bounds. A 1x1 board is trivially true, and a 1xN or Nx1 board has no vertical or horizontal pairs to check, so your code must not index out of range. Another common bug is only checking rows and forgetting columns, which passes example 1 but fails example 2 style cases. Complexity is O(m*n) time and O(1) space. If you blank on the parity formula during the live OA, StealthCoder is the hedge: it reads the problem on screen and hands you a clean solution without the proctor seeing anything.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Validate a Two-Color Chessboard 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon 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.
Validate a Two-Color Chessboard FAQ
How hard is the Amazon chessboard validation question really?+
Easy on the algorithm, but the edge cases bite. It's a single pass over a grid up to 100x100. Most failures come from out-of-bounds indexing or skipping a direction, not from the logic. If you can write a nested loop cleanly, you can solve it.
What's the trick to solving it fast?+
Use parity. Every cell must equal board[0][0] XOR ((i+j) % 2). One nested loop, return false on the first mismatch, return true at the end. No neighbor lookups, so no bounds headaches and no duplicate comparisons.
Which edge cases should I test before submitting?+
Test a 1x1 board (true), a single row like [[0,1,0]], a single column like [[1],[0],[1]], and a board with a bad cell in the last row or column. Also try a valid board starting with 1 instead of 0, since the starting color is free.
Do I need to check both horizontal and vertical neighbors?+
Yes, both matter. A board can alternate perfectly across rows but repeat down columns. Example 2 fails because of an adjacent pair in the bottom row. The parity formula covers both directions at once, which is why it's safer than manual neighbor checks.
How do I prepare for this in 48 hours?+
Write the parity solution and the right/down neighbor solution once each, from memory. Then run the four edge cases above. Spend remaining time on other grid scans. This pattern is simple enough that clean habits beat extra volume.