What is the asymptotic runtime complexity of my code?
Anonymous User
66
public static int myAlgorithm(List<Integer> myList) {
 if (myList.isEmpty()) {
 return 0;
    } 
 
Collections.sort(myList); // Can assume the sort algorithm is merge sort 

int sum = 0; 
int max = myList.get(myList.size() - 1); 
for (int item : myList) {
 int diff = Math.abs(max - item);
 sum = sum + diff; 
    } 
return sum; 
}
Comments (0)