DSAMaster Logo
DSAMaster
BackeasyArrays

Magnitude Spread Calculation

Problem Description

Given an array of integers, determine the magnitude spread, defined as the difference between the largest and smallest values present within the collection.

Example 1
Input
nums = [14, 2, 8, 31, 7]
Output
29

Explanation: The maximum value is 31 and the minimum value is 2. The spread is 31 - 2 = 29.

Example 2
Input
nums = [-5, 0, 12, 3]
Output
17

Explanation: The maximum value is 12 and the minimum value is -5. The spread is 12 - (-5) = 17.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^6 <= nums[i] <= 10^6
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