[
greedy
]
Leetcode 0908. Smallest Range I
Problem statement
https://leetcode.com/problems/smallest-range-i/
Solution
We need to look at maximum and minimim values and try to make them as close as possible.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def smallestRangeI(self, A, K):
return max(0, max(A) - min(A) - 2*K)