can anyone suggest me approach to this problem
Funky chess board problem
This problem can be solved using BFS graph traversal.
Lets see how.
you first need to create 2D array for chess board having 0 entry where knight can’t move. and a 2D array for visited cells(we usually do in graph traversal)
we will find how many maximum cells can knight cover. then your answer will be (total cells - max covered cells).
your recursion would be like; let f(x) be no of cells covered starting from position x.
f(r,c) = 1 + max{ f(r-2,c-1), f(r-2,c+1), f(r-1,c-2), f(r-1,c+2), f(r+1,c-2), f(r+1,c+2), f(r+2,c-1), f(r+2,c+1) } ;
and f(r,c) = 0 if r,c does not exists (i,e it contains 0 in input matrix ) or it is already visited.
here starting r,c will be top left corner.
you need to carefully update visited matrix(it should be local to path).
Thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.