Test case seems to be wrong

For input :

[ 444, 994, 508, 72, 125, 299, 181, 238, 354, 223, 691, 249, 838, 890, 758, 675, 424, 199, 201, 788, 609, 582, 979, 259, 901, 371, 766, 759, 983, 728, 220, 16, 158, 822, 515, 488, 846, 321, 908, 469, 84, 460, 961, 285, 417, 142, 952, 626, 916, 247, 116, 975, 202, 734, 128, 312, 499, 274, 213, 208, 472, 265, 315, 335, 205, 784, 708, 681, 160, 448, 365, 165, 190, 693, 606, 226, 351, 241, 526, 311, 164, 98, 422, 363, 103, 747, 507, 669, 153, 856, 701, 319, 695, 52 ]

My Output is :

444 994 508 72 125 299 181 238 354 223 691 249 838 890 758 675 424 199 201 788 609 582 979 259 901 371 766 759 983 728 220 16 158 822 515 488 846 321 908 469 84 460 961 285 417 142 952 626 916 247 116 975 202 734 128 312 499 274 213 208 472 265 315 335 205 784 708 681 160 448 365 165 190 693 606 226 351 241 526 311 164 98 422 363 103 747 507 669 153 856 701 695 319 52

The expected Output is:

444 994 508 72 125 299 181 238 354 223 691 249 838 890 758 675 424 199 201 788 609 582 979 259 901 371 766 759 983 728 220 16 158 822 515 488 846 321 908 469 84 460 961 285 417 142 952 626 916 247 116 975 202 734 128 312 499 274 213 208 472 265 315 335 205 784 708 681 160 448 365 165 190 693 606 226 351 241 526 311 164 98 422 363 103 747 507 669 153 856 701 695 52 319

My output < Expected Output

2 Likes

Hi, I have the same problem here with this test case.

Yes. Test cases are wrong.

You are looking for the next permutation, not just any higher permutation. The permutations for 52, 319 and 695 are (in order):

  1. 52, 319, 695
  2. 52, 695, 319
  3. 319, 52, 695
  4. 319, 695, 52
  5. 695, 52, 319
  6. 695, 319, 52

The input is at #4. The expected output is #5, yet your output jumps straight to #6.

Its still unclear.
How come you start with 52, 319 and 695 permutation ?

What my understanding is,
if we have an input like this : 3 319 695 52
Out put should be : 695 319 52
Instead of : 695 52 319
Because : 69552319 > 69531952 , therefore output should be: 695 319 52 (the next larger permutation). Please explain. Thanks!

Think of 319 695 52 as 2 3 1, now, what is the next permutation?
Is it 3 2 1 or 3 1 2?

Click here to start solving coding interview questions