First of all, sorry for such a late response. Actually, the indentation of the code was disturbed after uploading it over here. Second of all, there are a few instances where you cannot solve the N-Puzzle problem. I haven’t validated my code with that exception.
https://www.geeksforgeeks.org/check-instance-15-puzzle-solvable/