Sudoku solver problem

https://ide.codingblocks.com/s/225483 here’s the link to my code, one of the test case is giving wrong input

Hello @pooja_narula,

Your code is giving wrong output for:

9
0 0 0 0 0 0 6 8 0
0 0 0 0 7 3 0 0 9
3 0 9 0 0 0 0 4 5
4 9 0 0 0 0 0 0 0
8 0 3 0 5 0 9 0 2
0 0 0 0 0 0 0 3 6
9 6 0 0 0 0 3 0 8
7 0 0 6 8 0 0 0 0
0 2 8 0 0 0 0 0 0

Expected Output:
1 7 2 5 4 9 6 8 3
6 4 5 8 7 3 2 1 9
3 8 9 2 6 1 7 4 5
4 9 6 3 2 7 8 5 1
8 1 3 4 5 6 9 7 2
2 5 7 1 9 8 4 3 6
9 6 4 7 1 5 3 2 8
7 3 1 6 8 2 5 9 4
5 2 8 9 3 4 1 6 7

But why is it giving the wrong output? I can’t find any mistake in the code

Hello @pooja_narula,

Your code is giving the wrong output:
1 4 2 3 9 5 6 8 7
6 8 5 2 7 3 4 1 9
3 7 9 1 6 8 2 4 5
4 9 6 7 2 1 8 5 3
8 1 3 4 5 6 9 7 2
2 5 1 8 4 9 7 3 6
9 6 7 5 1 4 3 2 8
7 3 4 6 8 2 5 9 1
5 2 8 9 3 7 1 6 4

In this output, it is assigning same number twice in the same block as highlighted above.
Reson:
Your code is not checking the presence of the element correctly.

I have corrected it:

Suggestion:
Use cout statements to check what are the values of sx and sy for given i and j.

Hope, this would help.