Maximum Number Unique Move Knight Chess Board
This programming question is also very famous in financial companies to screening candidate in first round of interview. This question has been asked middle to senior level developer position where interviewer want to check candidate ability to write algorithm quickly and for below question they gave two hours time:
Please implement a program to determin the maximum number of unique moves a knight can make on a chess board. The chess board can be of any size rectangle and the knight move can of any size. For example, a chess piece that moves 2X5 on a board 8X6. Please utilize a thread pool to decrease the real time it take to solve the problem.
Program should take as arguments, the configuration of the board and knight, as well as the number of thread to launch.
Solution: There are many different logic and algorithm can be use to write this algorithm, although to keep thing simple I have got the desired output using two for loop. Next I will implement same program by using thread as asked by interviewer but for now this what I have:
- KnightUniqueMoves.java: Method findKnightMove takes two parameters which you could pass in main method and based on that program will create two dimensional array and find knight moves:
- Output: Total number of unique move knight can do on 8X8 chess board is: 336. I am not pasting full output because its so big, you can try in your workspace to see full output.