Tap here to switch tabs
Problem
Submissions

Problem: Absolute Difference of Maximum and Minimum K Elements

Absolute Difference of Maximum and Minimum K Elements asks you to calculate the absolute difference between the sums of the k largest and k smallest values in an integer array.

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

Absolute Difference of Maximum and Minimum K Elements asks you to calculate the absolute difference between the sums of the k largest and k smallest values in an integer array.

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