Knight Tour
InterviewTime limit2sMemory limit128 MB
Check whether a given sequence of 36 squares on a 6x6 board forms a valid closed knight's tour with legal moves between consecutive squares and back to the start.
- Level
Easy3 of 10
- Topics
- Simulation, Array, Hash map
- Solved
- No attempts yet
Problem
A knight's tour is a path on a chessboard in which a knight visits every square exactly once, and from the last square it can move back to the starting square with a legal knight move.
Each square of a 6×6 chessboard is written as one letter from A through F followed by one digit from 1 through 6. Given the 36 squares visited by a knight in order, determine whether the path is a valid knight's tour.
Input
The input consists of 36 lines, each giving one square in the order visited by the knight. Every square in the input exists on the 6×6 chessboard.
Output
Print Valid if the path is a valid knight's tour. Otherwise, print Invalid.