BackmediumArrays arrays medium

MaxSubarrayAmplitude Solution

Problem Statement

You are given an array of integers `nums` and a specified range defined by `left` and `right` indices. Find the maximum amplitude within this range, where amplitude is the difference between the maximum and minimum values in the subarray.

Example 1
Input
[1, 2, 3, 4, 5] left=1 right=3
Output
2

Explanation: The subarray from index 1 to 3 is [2, 3, 4], with max 4 and min 2, giving an amplitude of 4 - 2 = 2.

Constraints

  • 1 <= nums.length <= 10^5
  • -10^5 <= nums[i] <= 10^5
  • 0 <= left <= right < nums.length
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