BackeasyArrays

Calculate Array Range Solution

Problem Statement

Given an array of integers, compute the difference between the maximum and minimum elements present in the sequence. The range is defined as the absolute difference between the largest value and the smallest value found within the array.

Example 1
Input
nums = [12, 4, 7, 2, 9]
Output
10

Explanation: The maximum element is 12 and the minimum element is 2. The range is 12 - 2 = 10.

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

Explanation: Both the maximum and minimum elements are 5. The range is 5 - 5 = 0.

Constraints

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