Sorting in linear time

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?

Please share your code using the online IDE. It’ll be easier to debug it that way.

You Mean Screen shot?

You can share your code like this: https://ide.codingblocks.com/s/580784

Your logic was completely correct, but there was an error in the display format. We had to display a single element in every new line. I have updated the code the correct code here.

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.