Tap here to switch tabs
Problem
Submissions

Problem: Absolute Difference of Maximum and Minimum K Elements

Try to solve the Absolute Difference Between Maximum and Minimum K Elements problem.

Statement

You are given an integer array nums of length n and an integer k.

Calculate the sum of the k largest elements in nums and the sum of the k smallest elements in nums.

Return the absolute difference between these two sums.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100

  • 1≤1 \leq k ≤\leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Absolute Difference of Maximum and Minimum K Elements

Try to solve the Absolute Difference Between Maximum and Minimum K Elements problem.

Statement

You are given an integer array nums of length n and an integer k.

Calculate the sum of the k largest elements in nums and the sum of the k smallest elements in nums.

Return the absolute difference between these two sums.

Constraints:

  • 1≤1 \leq n ==== nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100

  • 1≤1 \leq k ≤\leq n