DSAMaster Logo
DSAMaster
BackeasyArrays

Extreme Spread Calculation

Problem Description

Given an array of integers, compute the absolute difference between the largest and smallest values present in the collection. The spread is defined as the result of subtracting the minimum value from the maximum value.

Example 1
Input
[12, 5, 8, 21, 3]
Output
18

Explanation: The maximum element is 21 and the minimum element is 3. The spread is 21 - 3 = 18.

Example 2
Input
[7, 7, 7, 7]
Output
0

Explanation: Both the maximum and minimum elements are 7. The spread is 7 - 7 = 0.

Example 3
Input
[-10, 0, 50, -5]
Output
60

Explanation: The maximum element is 50 and the minimum element is -10. The spread is 50 - (-10) = 60.

Constraints

  • 2 <= array.length <= 1000
  • -10^4 <= array[i] <= 10^4
00:00
Loading...

Sign in to Solve

Access the full code editor, ThinkBuddy AI hints, and track your progress.

Sign in Free
Test Cases & Output
Enter test input here...
Click "Run Code" to execute