import java.util.*;
public class Main {
public static void main(String args[]) {
// Your Code Here
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] arr = new int[n];
for(int i=0; i<arr.length; i++) {
arr[i] = scn.nextInt();
}
int low = 0;
int mid = 0;
int high = arr.length-1;
while(mid<=high) {
if(arr[mid]==0) {
swap(arr, low, mid);
low++;
mid++;
}
else if(arr[mid]==1) {
mid++;
}
else {
swap(arr, mid,high);
high–;
}
}
display(arr);
}
public static void swap(int[] arr, int i, int j) {
int temp;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void display(int[] arr) {
for(int i=0; i<arr.length; i++) {
System.out.print(arr[i] + ",");
}
}
}
This is my code for Sorting in linear time it is givivig the correct otput but the test cases are wrong .
what i have done wrong?