Login using Social Account
     Continue with GoogleLogin using your credentials
Given an array A
of integers, for each integer A[i]
we need to choose either x = -K
or x = K
, and add x
to A[i]
(only once).
After this process, we have some array B
.
Return the smallest possible difference between the maximum value of B
and the minimum value of B
.
Example:
Input: A = [1], K = 0
Output: 0
Explanation: B = [1]
Input: A = [0,10], K = 2
Output: 6
Explanation: B = [2,8]
Constraints:
smallest_range
A
and K
Complete the below code in the right side coding panel
def smallest_range(A: list, K: int) -> int:
# your code goes here
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...