We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticvoidminiMaxSum(List<int>arr){// Calculate the total sum of all elements, casting to long// (necessary because the sum might exceed the int limit in some cases).longtotal=arr.Sum(x=>(long)x);// The minimum sum is obtained by subtracting the largest element (Max).longminSum=total-arr.Max();// The maximum sum is obtained by subtracting the smallest element (Min).longmaxSum=total-arr.Min();// Print both sums in the expected format: "minSum maxSum"Console.WriteLine($"{minSum} {maxSum}");}
Cookie support is required to access HackerRank
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 →