I want to sort an 2D-array in zig-zag order using only the first number. For example:
int[][] a = {{2,5,4}{5,3,5}{56,5,54}{353,35}}
sort(a)
System.out.println(a)
What I want it to print is ((2,5,4),(56,5,54),(5,3,5),(353,35))
. Is there any way to do this with a time complexity of O(n)?
This is not a duplicate because I want it in O(n).