Step 3: Look for the unassigned location in the grid. Step 2: Write a recursive function that accepts the grid as the input. Instead of HashMap, one can use loops also. If the HashMap shows the frequency of any number greater than 1, then return false, else return true. For the boxes, column, and row, create a HashMap for storing the frequency of the numbers. Step 1: Create a function whose work is to check whether the grid is safe or not when a number is assigned to the current index. If none of the numbers from 1 to 9 leads to a solution, then false is returned, and the message 'the solution does not exit' is displayed. If the assignment does not lead to the solution, then we take another number and repeat the process. If the same number is not present, then the number is assigned, and then we check recursively whether this assignment leads to the solution or not. If the same number is present, then we take another number and check its safety. Before assigning any number, we check whether the same is present in the current column, current row, or the current 3 x 3 sub-grid or not. In this approach, we assign numbers one-by-one to empty cells. To fill the numbers in the empty cells, we will use backtracking approach to solve the puzzle. It indicates that the cells of the grid containing 0 are empty and need to be filled.