Tap here to switch tabs
Problem
Submissions

Problem: Smallest Range II

Smallest Range II lets you add or subtract k from every array element. Return the smallest possible difference between the array's maximum and minimum values after all updates.

Statement

You are given an integer array nums and an integer k.

For each index i where 0≤i<0 \leq i < nums.length, you must update nums[i] to either nums[i] ++ k or nums[i] −- k.

The score of nums is the difference between the maximum element and the minimum element of nums.

Return the minimum possible score of nums after modifying every element.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • 0≤0 \leq nums[i] ≤104\leq 10^4

  • 0≤0 \leq k ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Smallest Range II

Smallest Range II lets you add or subtract k from every array element. Return the smallest possible difference between the array's maximum and minimum values after all updates.

Statement

You are given an integer array nums and an integer k.

For each index i where 0≤i<0 \leq i < nums.length, you must update nums[i] to either nums[i] ++ k or nums[i] −- k.

The score of nums is the difference between the maximum element and the minimum element of nums.

Return the minimum possible score of nums after modifying every element.

Constraints:

  • 1≤1 \leq nums.length ≤104\leq 10^4

  • 0≤0 \leq nums[i] ≤104\leq 10^4

  • 0≤0 \leq k ≤104\leq 10^4