FastPrepOnline Chess Move Validation
Problem · Array

Online Chess Move Validation

HardOpenAI logoOpenAIFULLTIMEPHONE SCREEN

Problem statement

Simulate move attempts from the standard initial chess position. White moves first. Each string in moves contains an origin square followed by a destination square in lowercase file-rank notation, such as e2e4.

For each attempt, append LEGAL or ILLEGAL to the result. An illegal attempt leaves the board and turn unchanged. An accepted move changes the board and passes the turn.

Use ordinary movement for kings, queens, rooks, bishops, knights, and pawns. Sliding pieces may not jump. A pawn may move one empty square forward, move two empty squares from its starting rank when the intermediate square is empty, or capture one opposing piece diagonally forward. A move may not capture a king or leave the moving side's king in check. Castling, en passant, promotion, clocks, draw rules, and checkmate adjudication are outside this exercise; a pawn move onto the last rank is illegal.

The problem statement continues
Pro

Examples

Example 1

moves = ["e2e4","e7e5","g1f3"]return = ["LEGAL","LEGAL","LEGAL","rnbqkbnr","pppp.ppp","........","....p...","....P...",".....N..","PPPP.PPP","RNBQKB.R"]

Both king pawns advance, then White's knight jumps from g1 to f3. The eight trailing strings encode the resulting board.

FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week