bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 910. Smallest Range II

910. Smallest Range II

Leetcode Solutions

Minimizing Score by Adjusting Elements with K

  1. Sort the array nums.
  2. Initialize minScore as the difference between the last and first elements after adding k to the first and subtracting k from the last.
  3. Iterate through the array from the second element to the second-to-last element. a. For each index i, calculate the high as the maximum of nums[i] + k and nums[-1] - k. b. Calculate the low as the minimum of nums[i+1] - k and nums[0] + k. c. Update minScore with the minimum of the current minScore and high - low.
  4. Return minScore.
UML Thumbnail

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...