This is a verified interview question from Accenture-japan. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Puzzle game" covers key patterns like Other.
"Takashi is playing a puzzle game. The puzzle involves placing multiple puzzle pieces on a square board to fill it completely without any gaps or overlaps. Your task is to write a program to check whether the board and the given pieces can form a valid puzzle. Rules & Definitions The Board: • The board is a square of size N * N, divided into 1 * 1 squares. The Pieces: • There are M pieces in total. • Each piece consists of one or more 1 * 1 tiles. • The tiles within a single piece must be connected by sharing an entire side (not just a corner). Placement Rules: 1. All Pieces Used: All M pieces must be used. 2. No Overlap: Multiple pieces must not overlap on any 1* 1 square. 3. In-Bounds: A piece must not extend beyond the edge of the N* N board. 4. Rotation Allowed: Pieces can be rotated (by 90, 180, or 270 degrees). 5. No Flipping: Pieces can not be turned over (flipped). 6. Exact Fit: The puzzle is only valid if the board is exactly filled by all the pieces, with no gaps remaining. Input Format The input is provided via standard input in the following format: 1. The first line contains two integers, N and M, separated by a space. 2. The input is then followed by M blocks, one for each piece. 3. Each block consists of N lines, and each line is a string of N characters. o The j-th line of the i-th piece is denoted by Si, j. o The character # indicates a square that is part of the piece. o The character . indicates a square that is not part of the piece. Input Structure: N M S_1,1 S_1,2 ... S_1,N S_2,1 ... S_2,N ... S_M,1 ... S_M,N Output Format Output Yes if the board can be filled exactly with all the given pieces according to the rules. Otherwise, output No."
Join thousands of developers practicing for Accenture-japan.