BackeasyArrays

Calculate Span of Numeric Sequence Solution

Problem Statement

Given an array of integers, determine the span of the sequence. The span is defined as the absolute difference between the largest value and the smallest value present within the array.

Example 1
Input
nums = [12, 4, 8, 19, 3]
Output
16

Explanation: The maximum value is 19 and the minimum value is 3. The span is 19 - 3 = 16.

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

Explanation: The maximum value is 7 and the minimum value is 7. The span is 7 - 7 = 0.

Example 3
Input
nums = [-5, 0, 10, -2]
Output
15

Explanation: The maximum value is 10 and the minimum value is -5. The span is 10 - (-5) = 15.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^6 <= nums[i] <= 10^6
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free