Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Design a jigsaw puzzle (OOD)
Object-Oriented Design: Jigsaw Puzzle
Design an object-oriented model for a jigsaw puzzle game.
Requirements
- The puzzle consists of a set of pieces that can be assembled into a final board, represented as an
R x Cgrid. - Each piece has 4 distinct sides (top, right, bottom, left) that must match adjacent pieces when placed on the board.
- Pieces can be rotated in increments of 90 degrees (0°, 90°, 180°, 270°).
- The system must support the following functionalities:
- Initializing a puzzle from a given collection of pieces.
- Placing a piece onto the board at a specific location.
- Removing a piece from the board.
- Validating whether a proposed piece placement is legal. This includes checking if the location is within board bounds, if the target cell is empty, and if the piece's sides correctly match those of any existing adjacent pieces.
- Checking whether the entire puzzle is currently in a solved state.
Clarifications and Assumptions
- Assume the puzzle is rectangular, and each piece occupies exactly one cell in the grid.
- Side matching can be represented using abstract identifiers or keys (e.g.,
tab#42matchesblank#42).
Deliverables
- Propose the core classes, their key fields (attributes), and methods.
- Clearly explain how piece rotation impacts the side matching logic.
- Discuss how the design can be made extensible to accommodate future features such as different board shapes, irregular piece geometries, multiplayer functionality, or separation of UI concerns.
AI interview prep
Core dilemma
Managing the dynamic state and relationships of rotatable pieces within a static grid structure, ensuring consistency and validity of placements while maintaining extensibility for future game mechanics.
Mid-level signals3
Senior signals3
Red flags3
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a jigsaw puzzle (OOD)
Object-Oriented Design: Jigsaw Puzzle
Design an object-oriented model for a jigsaw puzzle game.
Requirements
- The puzzle consists of a set of pieces that can be assembled into a final board, represented as an
R x Cgrid. - Each piece has 4 distinct sides (top, right, bottom, left) that must match adjacent pieces when placed on the board.
- Pieces can be rotated in increments of 90 degrees (0°, 90°, 180°, 270°).
- The system must support the following functionalities:
- Initializing a puzzle from a given collection of pieces.
- Placing a piece onto the board at a specific location.
- Removing a piece from the board.
- Validating whether a proposed piece placement is legal. This includes checking if the location is within board bounds, if the target cell is empty, and if the piece's sides correctly match those of any existing adjacent pieces.
- Checking whether the entire puzzle is currently in a solved state.
Clarifications and Assumptions
- Assume the puzzle is rectangular, and each piece occupies exactly one cell in the grid.
- Side matching can be represented using abstract identifiers or keys (e.g.,
tab#42matchesblank#42).
Deliverables
- Propose the core classes, their key fields (attributes), and methods.
- Clearly explain how piece rotation impacts the side matching logic.
- Discuss how the design can be made extensible to accommodate future features such as different board shapes, irregular piece geometries, multiplayer functionality, or separation of UI concerns.