import java.util.Arrays;
import java.util.Scanner;
class ReverseArray{
static int[] printReverse(int a[],int n){
Arrays.sort(a); // O(nLogn)
for(int j = 0 ; j < a.length ; j++){ // O(n)
System.out.println(a[j]+" ");
}
return a;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
for(int i = 0 ; i<n ; i++){
a[i] = sc.nextInt();
}
printReverse(a,n);
sc.close();
}
}
I was trying to practice this code on my own and I wrote this code but I think this is not an optimal code to reverse an array. I have just started my journey in programming so I have only a little idea about Time Complexity. I just want to know the time complexity of this code. The time complexity for this code would be O(N log N)+O(n) right? Correct me if I wrong.