I must have misunderstood the question, but [4, 3] = 1324?


  • 0
    I

    I just submitted my code and it failed at this test case

    Input: 4, 3
    Output: "1423"
    Expected: "1324"

    I must have misunderstood the sequence, but I thought the permutation sequence for n = 4 is

    1234
    1243
    1423
    1324
    1342
    1432
    2134
    2143
    2413
    ...
    

    Could anyone let me know the correct sequence for n = 4? Thanks.


  • 1
    M

    The permutation sequence is in increasing order, until it can't increase anymore and becomes the lowest instead. Looking at your sequence, you have 1423 in the wrong place. 1423 > 1324, so it comes later. It in fact goes after 1342, leaving the sequence:

    1234
    1243
    1324
    1342
    1423
    1432
    2134
    2143
    2314
    2341
    ...
    

    As you can see, the third element is 1324, the expected output.


Log in to reply
 

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