[LeetCode]#908. Smallest Range I

Input: A = [1], K = 0
Output: 0
Explanation: B = [1]
Input: A = [0,10], K = 2
Output: 6
Explanation: B = [2,8]
  1. Use formula “max(max(A) — min(A) — 2 * K, 0)” to do this problem.
class Solution:
def smallestRangeI(self, A: List[int], K: int) -> int:

return max(max(A) - min(A) - 2 * K, 0)

Interesting in any computer science.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Bash Scripting Tutorial, Part 3

How to Make Sure That the Dedicated Development Team Is Truly Dedicated

Advanced ARM Templates: Microservice Pattern for Functions

Create Excel Column Chart Using Java

Python and Dominion

Young man putting on a face mask

Abell World Update #8

Integrate Jenkins with AWS — Part IV

No matter how big your Turo crew is, task distribution comes easily with CarSync’s multi-users

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Fatboy Slim

Fatboy Slim

Interesting in any computer science.

More from Medium

[LeetCode]#2089. Find Target Indices After Sorting Array

How to implement a Queue class using deque. PYTHON data structures and algorithm.

LeetCode Patterns Adventure 12 — Palindrome Linked List

Remove nth node from end of list Leetcode Python