Question: Java There are K knights on N x N chessboard and you are to determine how many squares they are guarding. Write a program that
Java
There are K knights on N x N chessboard and you are to determine how many squares they are guarding. Write a program that reads positive integers N and K and then K positions of knights, and prints the number of squares that are guarded by these K knights. A square is guarded if it is either occupied by a knight or is reachable by a knight by a single move. A knight move is always by two squares in one direction and by one square in perpendicular direction. E.g. by two squares in horizontal direction and by one square in vertical direction.

Example of input: 8 2 c 1 e 2
Corresponding output: 10
Example of input: 8 6 c 1 e 2 d 4 c 7 f 7 h 6
Corresponding output: 30
23 abcdefgh 87654321
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
