Wrong Expected Output For Next Permutation Problem

Isn’t output number is smaller than input number.

Although, it seems like we can have any integer as a element of vector A but, according to problem mentioned, every element must a digit only (0-9). The problem is framed for this type of input only.
So, it is giving the incorrect output because of invalid input format (i.e. 12 and 18 which are combination of digits).
It must be mentioned in the problem statement.
Hope it helps!

can you plese help me, this is my solution class but for the input

84 300 259 359 639 268 271 565 113 322 293 994 357 178 986 101 70 554 119 508 671 111 120 169 505 709 206 625 933 865 536 647 150 412 481 796 365 721 334 221 339 544 136 332 672 781 317 529 729 874 983 296 973 563 244 802 104 179 556 782 315 278 542 252 369 917 233 58 245 627 833 424 444 658 373 859 985 471 846 511 521 673 20 299 476

my code is getting Array index bound out of exception !!
Can you please review my code?
public class Solution {

    public static void swap(ArrayList<Integer> ar, int i, int j) 
{
    int temp = ar.get(i);
    ar.set(i,ar.get(j));
    ar.set(j,temp);
}

public static void nextPermutation(ArrayList<Integer> a) {
    ArrayList<Integer> c = new ArrayList<Integer>(a);
    Collections.sort(c);
    int n = a.size();
    int i;
    for (i = n -1 ; i > 0; i--){
        if (a.get(i) > a.get(i - 1)) {
            break;
        }	        
    }
    if (i == 0){
        Collections.sort(a);
        
    }
    
    else if(a == c){
        swap(a, n-1, n-2);
        
    }
    else{
        int x = a.get(i-1), min = i;
        for (int j = i + 1; j < n; j++) 
        {
            if (a.get(j) > x && a.get(j) < a.get(min)) 
            {
                min = j;
            }
        }
        swap(a, i-1, min);
        ArrayList<Integer> b = new ArrayList<Integer>();
        for(int j = i; j < n; j++){
            b.add(a.get(j));
        }
        Collections.sort(b);
        int lb = b.size();
        for(int k = i; k < n; k++){
            a.set(k,b.get(k-lb));
        }
    }
    
}

}

@Samyak
the first number ie. 7 in the input you specified is the size of the array.
The numbers following 7 are the elements of array .
Now , look at it again u’ll realise that the output is correct.

Click here to start solving coding interview questions