The output is not unique


  • 0
    J

    I use a DFS method to solve the problem. But i got an output which is right but different from the expected answer;

    Input: ["..9748...","7........",".2.1.9...","..7...24.",".64.1.59.",".98...3..","...8.3.2.","........6","...2759.."]

    Output: ["139748652","712456839","325169478","987631245","864312597","498527361","576893124","253984716","641275983"]

    Expected: ["519748632","783652419","426139875","357986241","264317598","198524367","975863124","832491756","641275983"]


  • 3
    M

    From your solution, it looks like you solved 2 parts of a Sudoku, having the rows and columns not repeat any numbers. However, you missed the 3rd part, where the blocks of 3x3 also do not repeat numbers. I divided up your solution into the blocks to show the problem more easily.

    1 3 9 | 7 4 8 | 6 5 2
    7 1 2 | 4 5 6 | 8 3 9
    3 2 5 | 1 6 9 | 4 7 8
    ---------------------
    9 8 7 | 6 3 1 | 2 4 5
    8 6 4 | 3 1 2 | 5 9 7
    4 9 8 | 5 2 7 | 3 6 1
    ---------------------
    5 7 6 | 8 9 3 | 1 2 4
    2 5 3 | 9 8 4 | 7 1 6
    6 4 1 | 2 7 5 | 9 8 3
    

    Here is the correct answer, similarly divided.

    5 1 9 | 7 4 8 | 6 3 2
    7 8 3 | 6 5 2 | 4 1 9
    4 2 6 | 1 3 9 | 8 7 5
    ---------------------
    3 5 7 | 9 8 6 | 2 4 1
    2 6 4 | 3 1 7 | 5 9 8
    1 9 8 | 5 2 4 | 3 6 7
    ---------------------
    9 7 5 | 8 6 3 | 1 2 4
    8 3 2 | 4 9 1 | 7 5 6
    6 4 1 | 2 7 5 | 9 8 3

  • 0
    Y

    yes, your first answer is not right. you can try it in the previous problem, Valid Sukodu.


  • 0
    J

    yes, i should solve Valid Sukodu first.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.