Tap here to switch tabs
Problem
Submissions

Problem: Smallest Range II

Try to solve the Smallest Range II problem.

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

Try to solve the Smallest Range II problem.

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