Validate a Two-Color Chessboard
Updated
Problem statement
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[][]) → booleanExamples
Example 1
board = [[0,1,0],[1,0,1]]return = trueEvery horizontal and vertical neighbor has the opposite color.
Example 2
board = [[0,1],[1,1]]return = falseThe two cells in the bottom row have the same color, so the pattern is invalid.
Constraints
1 <= board.length <= 1001 <= board[i].length <= 100- Every row has the same length.
board[i][j]is either0or1.
More Amazon Onsite Interview questions
- Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
- Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Rotate a Matrix by 90 DegreesIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Validate a Chess Bishop, Rook, or Queen MoveGlean · PHONE SCREENGlean interview questions
- Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- One-Nearest-Neighbor Classification with Manhattan DistanceOpenAI · PHONE SCREENOpenAI interview questions
- Map Black Cells to Covering 2x2 BlocksSquare · PHONE SCREEN
- Traverse Interior Matrix Cells in Row-Major OrderCitadel · ONSITE INTERVIEWCitadel interview questions
- Trace an Eight-Direction Robot Until BlockedPinterest · PHONE SCREENPinterest interview questions
- Detect a Winner on a 3x3 Tic-Tac-Toe BoardHebbia · ONSITE INTERVIEW
- Excel Training Data and Model Response AuditMicrosoft · PHONE SCREENMicrosoft interview questions
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)