- Home
- Assessment

13 / 13

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:

- 1 <= len(A)<= 10000
- 0 <= A[i] <= 10000
- 0 <= K <= 10000

- Write your code inside a function named
`smallest_range`

- There are no partial marks for the question.
- Your function must
**return**the output, it should**not print**the output. - To execute a block on the right-side coding panel, please press 'shift'+ 'enter' inside the block.
- Your code should work for all permitted possible values(check Constraints) of
`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
```

XP

Want to create exercises like this yourself? Click here.

Checking Please wait.

Success

Error

No hints are availble for this assesment

Fetching answer, please wait...

Error

**Note - **Having trouble with the assessment engine? Follow the steps listed
here

## Loading comments...