Infinite loop problem

my program is not able to come out of while loop in findMinSquares() function, please tell me what I have missed.

my code:- https://ide.codingblocks.com/s/269927

add this condition in if condition

2 test cases are not passing , please review my code:- https://ide.codingblocks.com/s/270197

i dont think this can be done using bfs approach this is a dfs+ backtracking approach based question
where u need to keep track of maximum no of steps that are traverses ky knight in the journey