What is wrong with my Code?

Please help me out Why all the Test Cases are failing?

Code below.

import java.util.*;
public class Main {

public static void printArray(int[] nums, int n) {

	ArrayList<Integer> list = new ArrayList<>();
	for(int i=0;i<nums.length;i++) {
        int index = Math.abs(nums[i]) - 1;
        if(nums[index] < 0) {
            list.add(index + 1);
			// System.out.print(index+1 + " ");
        }
        nums[index] =  - nums[index];
    }
	Collections.sort(list);

	for(int i : list) {
		System.out.print(i + " ");
	}
}
public static void main (String args[]) {
	 Scanner scan = new Scanner(System.in);
  int n = scan.nextInt();
  int[] a = new int[n];
  for(int i=0;i<n;i++) {
      a[i] = scan.nextInt();
  }
  printArray(a, a.length);
}

}

hello @shivampokhriyal
pls share ur code using cb ide

Check here.

https://ide.geeksforgeeks.org/r8KyJWKUHT

@shivampokhriyal
ur output should be in this format (u r not printing those braces)->
image

Thanks! it worked.

But i think its really stupid to print it in such a format. ( provided that its a interview question ).

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.