You are viewing a single comment's thread. Return to all comments →
// C# public static void miniMaxSum(List<int> arr) { for (int i = 0; i <= arr.Count - 2; i++) { if (arr[i] > arr[i + 1]) { int temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; } int pos = (arr.Count - 1) - i; if (arr[pos] < arr[pos - 1]) { int temp = arr[pos]; arr[pos] = arr[pos - 1]; arr[pos - 1] = temp; } } long min = 0; long max = 0; for (int i = 0; i < arr.Count; i++) { if (i > 0) max += arr[i]; if (i < arr.Count - 1) min += arr[i]; } Console.WriteLine($"{min} {max}"); } }
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 →