BackeasyArrays TCS

Range Span of an Integer Sequence Solution

Problem Statement

Given an array of integers, compute the range span of the sequence. The range span is defined as the mathematical difference between the maximum element and the minimum element present in the array. If the array contains only one element, the range span is 0.

Example 1
Input
nums = [14, 2, 9, 21, 5]
Output
19

Explanation: The maximum element is 21 and the minimum element is 2. The range span is 21 - 2 = 19.

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

Explanation: The maximum element is 0 and the minimum element is -10. The range span is 0 - (-10) = 10.

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