Question Bank
/

JavaScript Min/Max Leave-One-Out Sum: Three Approaches Quiz

JavaScript Min/Max Leave-One-Out Sum: Three Approaches Quiz

Compute the smallest and largest "drop one and sum the rest" totals three ways (sort + slice, total-sum minus extremum, single-pass min/max tracker), plus two companions on streaming inputs and a top-K leave-out generalisation.

Question Bank
Hard
JavaScript
quiz
arrays
math
array-manipulation-patterns

983 views

20

Implement findMinMaxSum(arr) using a SORT + SLICE approach: sort a copy, drop the last element to get the min-sum, drop the first element to get the max-sum, and return { min, max }.

Examples

Example 1:

Input: [1, 2, 3, 4]
Output: { min: 6, max: 9 }
Explanation: Dropping 4 yields 1+2+3 = 6 (min); dropping 1 yields 2+3+4 = 9 (max).

4 more questions, with full solutions and explanations, are available for premium members.

Upgrade to Premium