Not Passing all test cases

import java.util.;
public class Main {
public static List findFreqElements(int[] arr){
List ans=new ArrayList<>();
for(int i=0;i<arr.length;i++){
int temp=Math.abs(arr[i]);
if(arr[temp-1]<0){
ans.add(temp);
}
else{
arr[temp-1]
=-1;
}
}
return ans;

}

public static void main (String args[]) {
	Scanner scn=new Scanner(System.in);
	int t=scn.nextInt();
	int[] arr=new int[t];
	for(int i=0;i<t;i++)
	arr[i]=scn.nextInt();
	System.out.print(findFreqElements(arr));

}

}

Please share your working code on coding blocks ide.

Hi kartik,
CodeBlocks ide was not working
so i will share with gfg ide
https://ide.geeksforgeeks.org/qWMQEPdS2h

Hey code is correct but its mentioned in ques that ““Answer must be sorted””

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.