As reported: SoFi senior software engineer loop (2025), the "logical and maintainable" coding round: design a chess board so that moves by different pieces are validated, and implement the Knight piece. The interviewer also asked about interfaces versus abstract classes, and why an interface was used.
Design the classes so that each kind of piece knows how it may move and the board can validate a move. Implement the Knight first; the design must make the other pieces easy to add. Be ready to explain your use of interfaces vs abstract classes.
The code runner tests a complete version of the design:
ChessBoard(rows)— 8 strings,rows[0]is rank 8 androws[7]is rank 1; filesa–hleft to right.K Q R B N Pare white pieces,k q r b n pblack,.empty.isValidMove(from, to)→trueif the piece onfrommay move toto(squares like"g1"), elsefalse.
Rules to implement: a move must start on a piece, stay on the board, change square, and not land on a piece of the same color. Knight — an L-shape (2 + 1), jumping over pieces. King — one square in any direction. Rook — straight lines, bishop — diagonals, queen — both, none of them jumping over pieces. Pawn — one square forward to an empty square, two from its starting rank if both squares are empty, one square diagonally forward only to capture (white moves toward rank 8). Check, castling, en passant and promotion are out of scope.
Example 1 (the starting position)
isValidMove("g1", "f3") -> true (knight jumps over the pawns)
isValidMove("g1", "e2") -> false (own pawn on e2)
isValidMove("b8", "c6") -> true
isValidMove("e2", "e4") -> true (pawn's first move)
isValidMove("e2", "e5") -> false
isValidMove("a1", "a3") -> false (rook blocked by a2)
isValidMove("d1", "h5") -> false (queen blocked by e2)
isValidMove("e1", "e2") -> false
Example 2
rows = ["........", "........", "........", "...n....", "........", "....P...", "........", "....K..."]
isValidMove("d5", "e3") -> true (black knight captures the white pawn)
isValidMove("d5", "d6") -> false
isValidMove("e3", "d4") -> false (pawns move diagonally only to capture)
isValidMove("e1", "f2") -> true
Code runner format: line 1 is rows, line 2 a list of [from, to] moves; the runner prints isValidMove for each.