You are viewing a single comment's thread. Return to all comments →
Well, that way you don't write out the loop yourself, but .sort() loops over the array O(n log n) times. The best I can find is one total iteration:
(in C)
unsigned long max = arr[0]; unsigned long min = arr[0]; unsigned long total = 0; for (int i = 0; i < arr_size; i++) { if (arr[i] > max) max = arr[i]; if (arr[i] < min) min = arr[i]; total+=arr[i]; } printf("%ul %ul", total - max, total - min);
Seems like cookies are disabled on this browser, please enable them to open this website
Mini-Max Sum
You are viewing a single comment's thread. Return to all comments →
Well, that way you don't write out the loop yourself, but .sort() loops over the array O(n log n) times. The best I can find is one total iteration:
(in C)