post_href stringlengths 57 213 | python_solutions stringlengths 71 22.3k | slug stringlengths 3 77 | post_title stringlengths 1 100 | user stringlengths 3 29 | upvotes int64 -20 1.2k | views int64 0 60.9k | problem_title stringlengths 3 77 | number int64 1 2.48k | acceptance float64 0.14 0.91 | difficulty stringclasses 3
values | __index_level_0__ int64 0 34k |
|---|---|---|---|---|---|---|---|---|---|---|---|
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2078998/Easy-python-solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
letters.sort()
for i in letters:
if (i>target):
return i
return letters[0] | find-smallest-letter-greater-than-target | Easy python solution | tusharkhanna575 | 3 | 137 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,200 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1846914/94-faster-python-solution.-Easy-to-understand. | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
start = 0
end = len(letters)-1
while start <= end:
mid = start + (end-start)//2
if letters[mid] > target:
end = mid - 1
else :
... | find-smallest-letter-greater-than-target | 94% faster python solution. Easy to understand. | 1903480100017_A | 2 | 114 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,201 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2150374/Simple-Python-Solution-Binary-Search | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
l=0
r=len(letters)-1
res=letters[0]
while(l<=r):
mid=(l+r)//2
if letters[mid]>target:
r=mid-1
res=letters[mid]
else:
... | find-smallest-letter-greater-than-target | Simple Python Solution - Binary Search | pruthashouche | 1 | 114 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,202 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1992106/Python-Short-and-Clean-Binary-Search-(without-bisect) | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
lo, hi = 0, len(letters)
while lo != hi:
mid = (lo + hi) // 2
if target < letters[mid]:
hi = mid
else:
lo = mid + 1
return letters[lo % le... | find-smallest-letter-greater-than-target | ✅ Python, Short and Clean Binary Search (without bisect) | AntonBelski | 1 | 89 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,203 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1910398/Python3-binary-search-implementation | class Solution:
def search(self,letters,target):
low=0
high=len(letters)-1
idx=-1
while low<=high:
mid=(low+high)//2
if letters[mid]==target:
idx=mid
break
elif target<letters[mid]:
high=mid-1
... | find-smallest-letter-greater-than-target | Python3 binary search implementation | amannarayansingh10 | 1 | 103 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,204 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1892592/O(logn)-Time-Complexity-Solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
left = 0
right = len(letters) - 1
while left <= right:
mid = (left + right) // 2
if letters[mid] <= target:
if mid + 1 < len(letters) and letters[mid + 1] > ... | find-smallest-letter-greater-than-target | O(logn) Time Complexity Solution | EdwinJagger | 1 | 50 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,205 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1875289/Python-Easiest-Solution-With-Explanation-or-99.2-Faster-or-Binary-Search-O(logn-or-Beg-to-Adv | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
left = 0
right = len(letters) - 1
# our array is a circular one, that implies that the next greatest value must be the first value in the array.
if target < letters[left] or target... | find-smallest-letter-greater-than-target | Python Easiest Solution With Explanation | 99.2 % Faster | Binary Search O(logn | Beg to Adv | rlakshay14 | 1 | 80 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,206 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1818343/Python-using-Binary-Search-with-constant-space.-Time-O(logn)-Space-O(1) | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
left = 0
right = len(letters)
if ord(target) < ord(letters[0]) or ord(target) >= ord(letters[right-1]):
return letters[0]
if right == 2 and (ord(target) == ord(letters[... | find-smallest-letter-greater-than-target | [Python] using Binary Search with constant space. Time-O(logn), Space-O(1) | jamil117 | 1 | 55 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,207 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1496779/EASY-Python-Solution | class Solution:
def nextGreatestLetter(self, arr: List[str], t: str) -> str:
strt=0
end=len(arr)-1
res=arr[0]
while strt<=end:
mid=strt+(end-strt)//2
if ord(arr[mid])>ord(t):
res=arr[mid]
end=mid-1
else:
... | find-smallest-letter-greater-than-target | EASY Python Solution | dashrathsingh | 1 | 92 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,208 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1280735/Easy-Python-Solution(96.57) | class Solution(object):
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
if letters[0]>target or letters[-1]<=target:
return letters[0]
l=0
h=len(letters)-1
while l <=h:
m = l+ (h - l)// 2
if letters[m]<=target:
... | find-smallest-letter-greater-than-target | Easy Python Solution(96.57%) | Sneh17029 | 1 | 337 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,209 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/577769/Straightforward-Solution-from-Scratch | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
# Getting rid of duplicates - set()
letters = sorted(set(letters))
#-----------------------------------------------
# where target character is in 'letters'
if target in lett... | find-smallest-letter-greater-than-target | Straightforward Solution from Scratch | cppygod | 1 | 79 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,210 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2748155/99-.44-faster-than-any-other-python-solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
st=0
end=len(letters)
result=0
if target >= letters[-1] or target < letters[0]:
return letters[0]
while st<=end:
mid= st+(end-st)//2
if letters[mid]==targ... | find-smallest-letter-greater-than-target | 99 .44% faster than any other python solution | sushants007 | 0 | 7 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,211 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2716796/Binary-Search-Easy-Solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
N = len(letters)
left = 0
right = N - 1
if letters[N - 1] <= target or letters[0] > target:
return letters[0]
while left <= right:
mid = left + (right - left + 1) /... | find-smallest-letter-greater-than-target | Binary Search Easy Solution | user6770yv | 0 | 4 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,212 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2699039/Simple-Python3-solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
l=0
r=len(letters)-1
res=letters[0]
while l<=r:
mid=l+(r-l)//2
if letters[mid]<=target:
l=mid+1
else:
res=letters[mid]
... | find-smallest-letter-greater-than-target | Simple Python3 solution | anirudh422 | 0 | 6 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,213 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2661251/Python3-or-binary-search | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
st=0
end=len(letters)-1
#edgecase1 ==> when given target is greater than elements in letters
#edgecase2 ==> when given target is less than elements in letters
if letters[-1]<=target or lett... | find-smallest-letter-greater-than-target | Python3 | binary search | 19pa1a1257 | 0 | 16 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,214 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2659437/Pyhton-or-Easy-Solution-or-Loop | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
letters.sort()
target_ord = ord(target)
curr_diff = 99999
ans = ""
for i in letters:
if int(curr_diff) > int(ord(i)) - int(target_ord) and int(ord(i)) - int(target_ord) > 0:
... | find-smallest-letter-greater-than-target | Pyhton | Easy Solution | Loop | atharva77 | 0 | 1 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,215 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2389149/Python-Binary-Search-Solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
beg = 0
end = len(letters)-1
while beg <= end:
mid = (beg+end)//2
if letters[mid]>target:
end = mid -1
else:
beg = mid +1
return l... | find-smallest-letter-greater-than-target | Python Binary Search Solution | Harshi_Tyagi | 0 | 68 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,216 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2361434/Python-Simple-Solution-using-Binary-Searchoror-Documented | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
low, high = 0, len(letters)-1
# if first letter is greater than target or
# if target is greater than even last element, return first letter
if target < letters[low] or target >= letters[hi... | find-smallest-letter-greater-than-target | [Python] Simple Solution using Binary Search|| Documented | Buntynara | 0 | 19 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,217 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2332486/Python-or-Java-or-CPP-orO(log-n-) | class Solution:
def nextGreatestLetter(self, nums: List[str], target: str) -> str:
start, end = 0, len(nums)-1
out = nums[0]
while(start <= end):
mid = start + (end - start)//2
if nums[mid] > target:
out = nums[mid]
end = m... | find-smallest-letter-greater-than-target | Python | Java | CPP |O(log n ) | devilmind116 | 0 | 22 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,218 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2214085/Python-solution-with-and-without-binary-search | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for i in letters:
if ord(i)>ord(target):
return (i)
break;
return(letters[0]) | find-smallest-letter-greater-than-target | Python solution with and without binary search | SakshiMore22 | 0 | 66 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,219 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2214085/Python-solution-with-and-without-binary-search | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
n = len(letters)
if n == 0:
return ""
low = 0
high = n - 1
res = 0
while low <= high:
mid =(low + high)// 2
if letters[mid] > target:
res= mid
high = mid - ... | find-smallest-letter-greater-than-target | Python solution with and without binary search | SakshiMore22 | 0 | 66 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,220 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2127872/Python-Easy-solution-with-complexities | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for letter in letters:
if letter > target:
return letter
return letters[0]
# time O(n)
# space O(1) | find-smallest-letter-greater-than-target | [Python] Easy solution with complexities | mananiac | 0 | 48 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,221 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2127872/Python-Easy-solution-with-complexities | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
if letters[0] > target or letters[-1] <= target:
return letters[0]
left = 0
right = len(letters) -1
while (left <= right):
mid = (lef... | find-smallest-letter-greater-than-target | [Python] Easy solution with complexities | mananiac | 0 | 48 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,222 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2083312/4-Lines-Python-Solution-oror-Easy | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
target_ord=ord(target)
for i in letters:
if ord(i)>target_ord:
return i
return letters[0] # If target not found, then it is wrapped arround case, so ... | find-smallest-letter-greater-than-target | 4 Lines Python Solution || Easy | aksgupta98 | 0 | 44 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,223 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2031339/Python-solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for i in sorted(letters):
if i > target:
return i
else:
return letters[0] | find-smallest-letter-greater-than-target | Python solution | StikS32 | 0 | 55 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,224 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2024000/Faster-than-93%3A-Beginner-Python-Solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for i in letters:
if i > target:
return i
return letters[0] | find-smallest-letter-greater-than-target | Faster than 93%: Beginner Python Solution | 7yler | 0 | 42 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,225 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2000366/Python-Linear-Search-%2B-Binary-Search | class Solution:
def nextGreatestLetter(self, letters, target):
return min(filter(lambda x : x > target, letters), default=letters[0]) | find-smallest-letter-greater-than-target | Python - Linear Search + Binary Search | domthedeveloper | 0 | 56 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,226 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/2000366/Python-Linear-Search-%2B-Binary-Search | class Solution:
def nextGreatestLetter(self, letters, target):
i = bisect_right(letters,target)
return letters[i] if i < len(letters) else letters[0] | find-smallest-letter-greater-than-target | Python - Linear Search + Binary Search | domthedeveloper | 0 | 56 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,227 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1964302/Python-oror-Simple-and-Clean-Binary-Search | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
n = len(letters)
start , end = 0, n
while start < end:
mid = (start + end)//2
if target < letters[mid] :
end = mid
else: start = mid +1
return letters[start%n] | find-smallest-letter-greater-than-target | Python || Simple and Clean Binary Search | morpheusdurden | 0 | 67 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,228 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1949713/java-python-easy-binary-search-(Time-Ologn-space-O1) | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
l = 0
r = len(letters) - 1
if target < letters[0] or target >= letters[r] : return letters[0]
while True :
if r - l == 1 : return letters[r]
m = (l+r)>>1
if letters[m] == letters[... | find-smallest-letter-greater-than-target | java, python - easy binary search (Time Ologn, space O1) | ZX007java | 0 | 32 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,229 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1937304/Python-Linear-Search-%2B-Binary-Search-Easy-To-Understand-Both | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
# ******** Linear Search Solution ********
# for c in letters:
# if c > target:
# return c
# return letters[0]
# ******** Binary Search Solutio... | find-smallest-letter-greater-than-target | Python Linear Search + Binary Search, Easy To Understand Both | Hejita | 0 | 42 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,230 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1870563/Python-Easy-Solutions-or-LogN | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for i in letters:
if i > target: return i
return letters[0] | find-smallest-letter-greater-than-target | ✅ Python Easy Solutions | LogN | dhananjay79 | 0 | 62 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,231 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1870563/Python-Easy-Solutions-or-LogN | class Solution:
def nextGreatestLetter(self, arr: List[str], target: str) -> str:
lo, hi = 0, len(arr) - 1
while lo <= hi:
mid = (lo + hi) // 2
if target >= arr[mid]: lo = mid + 1
if target < arr[mid]: hi = mid - 1
return arr[lo % len(arr)] | find-smallest-letter-greater-than-target | ✅ Python Easy Solutions | LogN | dhananjay79 | 0 | 62 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,232 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1857532/Python3-Solution-(99-Faster-and-easy-to-understand) | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
letters = list(set(letters))
if target not in letters:
letters.append(target)
letters.sort()
index_of_target = letters.index(target)
if index_of_t... | find-smallest-letter-greater-than-target | Python3 Solution (99% Faster and easy to understand) | hardik097 | 0 | 48 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,233 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1849557/Python3-Faster-Than-98.4-Using-Binary-Search | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
left = 0
right = len(letters) - 1
next_largest = letters[0]
while left <= right:
mid = left + (right - left) // 2
# case: left or ... | find-smallest-letter-greater-than-target | Python3 Faster Than 98.4% Using Binary Search | justtestingn | 0 | 39 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,234 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1706864/simple-python-solution-faster-than-99.63 | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
low, high = 0, len(letters)-1
while low <= high:
mid = (low+high)//2
if letters[mid] <= target:
low = mid+1
else:
high = mid-1
return le... | find-smallest-letter-greater-than-target | simple python solution faster than 99.63% | fatmakahveci | 0 | 108 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,235 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1599328/Simple-Python-Solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
asc = ord(target)
for i in letters:
if ord(i) > asc:
return i
return letters[0] | find-smallest-letter-greater-than-target | Simple Python Solution | jodyzhou | 0 | 40 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,236 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1510852/Simplest-or-Python-3 | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for letter in letters:
if ord(letter) > ord(target):
return letter
return letters[0] | find-smallest-letter-greater-than-target | Simplest | Python 3 | deep765 | 0 | 187 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,237 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1495107/Multiple-Ways-to-Approach-a-Problem-for-BEGINNERS-greater-Step-by-Step | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
# Approach 1 : O(N) Time and O(1) Space -- Brute Force Thinking
# Step 1 : We will simply append the given target in letters and sort it
# This way, if the target is present at ith index, ... | find-smallest-letter-greater-than-target | Multiple Ways to Approach a Problem for BEGINNERS --> Step by Step | aarushsharmaa | 0 | 36 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,238 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1365804/Python-Solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
letters.append(target)
letters = sorted(set(letters))
ind = letters.index(target)
return letters[ind + 1] if len(letters) > ind+1 else letters[0] | find-smallest-letter-greater-than-target | Python Solution | _Mansiii_ | 0 | 31 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,239 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1238839/Python3-simple-solution-using-binary-search | class Solution(object):
def nextGreatestLetter(self, letters, target):
x = bisect.bisect(letters, target)
return letters[x % len(letters)] | find-smallest-letter-greater-than-target | Python3 simple solution using binary search | EklavyaJoshi | 0 | 42 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,240 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1172475/Python3-Simple-Approach-with-Explanation-and-Comments | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
'''
1. Starting from the next letter in alphabetical order of the 'target' letter, check if the letter is in list 'letters'.
2. Let the index of target letter in alphabet be i. So start checking from index... | find-smallest-letter-greater-than-target | Python3 Simple Approach with Explanation and Comments | bPapan | 0 | 28 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,241 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1106310/Python-simple-solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
letters = list(set(letters))
ind = "abcdefghijklmnopqrstuvwxyz"
lis=[-1 for i in range(26)]
for i in range(len(letters)):
lis[ord(letters[i])-ord('a')] = 1
for i in range(ord(tar... | find-smallest-letter-greater-than-target | Python simple solution | abhisek_ | 0 | 35 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,242 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1032349/Faster-than-95.99-of-Python-3-online-submissions-using-BINARY-SEARCH-ONLY | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
arr=letters
ele=target
res=-1
low=0
high=len(arr)-1
if ele>=arr[high]:
return arr[low]
if ele<arr[low]:
res=arr[low]
while low<=high:
... | find-smallest-letter-greater-than-target | Faster than 95.99% of Python 3 online submissions using BINARY SEARCH ONLY | sr_snehil | 0 | 35 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,243 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1018576/python3 | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
if letters[-1] <= target :
return letters[0]
start = 0
end = len(letters)-1
boundary = -1
while start <= end :
mid = start + (end-start)//2
if letters[mi... | find-smallest-letter-greater-than-target | python3 | ankur1801 | 0 | 39 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,244 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/867845/Python-Simple-Python-Solution-Using-Two-Approach | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
low = 0
high = len(letters) - 1
while low < high:
mid = ( low + high ) //2
if letters[mid] <= target:
low = mid + 1
else:
high = mid
if letters[low] ... | find-smallest-letter-greater-than-target | [ Python ] ✅✅ Simple Python Solution Using Two Approach🥳✌👍 | ASHOK_KUMAR_MEGHVANSHI | 0 | 70 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,245 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/867845/Python-Simple-Python-Solution-Using-Two-Approach | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for i in letters:
if i>target:
return i
if letters[-1]<=target:
return letters[0] | find-smallest-letter-greater-than-target | [ Python ] ✅✅ Simple Python Solution Using Two Approach🥳✌👍 | ASHOK_KUMAR_MEGHVANSHI | 0 | 70 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,246 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/772522/Simple-Python-Solution | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
letrs = [ord(l) for l in letters]
trgt = ord(target)
found=False
i=0
while i < len(letrs) and not found:
if letrs[i]>trgt:
found=True
else:
... | find-smallest-letter-greater-than-target | Simple Python Solution | bharatgg | 0 | 37 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,247 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1848926/3-Lines-Python-Solution-oror-80-Faster-oror-Memory-less-than-97 | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
alphas = [chr(i) for i in range(97,123)]*2 ; idx = alphas.index(target)+1
for i in range(idx, len(alphas)):
if alphas[i] in letters: return alphas[i] | find-smallest-letter-greater-than-target | 3-Lines Python Solution || 80% Faster || Memory less than 97% | Taha-C | -1 | 26 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,248 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1848926/3-Lines-Python-Solution-oror-80-Faster-oror-Memory-less-than-97 | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
for letter in letters:
if letter > target: return letter
return letters[0] | find-smallest-letter-greater-than-target | 3-Lines Python Solution || 80% Faster || Memory less than 97% | Taha-C | -1 | 26 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,249 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/1526768/Python-Pseudo-O(lg-n)-solution-using-Binary-Search | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
start, end = 0, len(letters)-1
while start<=end:
mid = (start+end)//2
if ord(letters[mid])<ord(target): start = mid+1
elif ord(letters[mid])>ord(target): end = mid-1
... | find-smallest-letter-greater-than-target | Python Pseudo O(lg n) solution using Binary Search | abrarjahin | -1 | 84 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,250 |
https://leetcode.com/problems/find-smallest-letter-greater-than-target/discuss/336477/Solution-in-Python-3 | class Solution:
def nextGreatestLetter(self, letters: List[str], target: str) -> str:
t, n = ord(target), list(map(ord,letters))
if t >= max(n): return chr(min(n))
d = {c : i for i,c in enumerate(n) if c > t}
return letters[d[min(d)]]
- Python 3
- Junaid Mansuri | find-smallest-letter-greater-than-target | Solution in Python 3 | junaidmansuri | -3 | 325 | find smallest letter greater than target | 744 | 0.448 | Easy | 12,251 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2260902/94-FASTER-97-Space-Efficient-Python-solutions-Different-approaches | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
cur = 0
dp0 = cost[0]
if len(cost) >= 2:
dp1 = cost[1]
for i in range(2, len(cost)):
cur = cost[i] + min(dp0, dp1)
dp0 = dp1
dp1 = cur
return min(dp0, dp1) | min-cost-climbing-stairs | 94% FASTER 97% Space Efficient Python solutions Different approaches | anuvabtest | 34 | 2,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,252 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2260902/94-FASTER-97-Space-Efficient-Python-solutions-Different-approaches | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
if not cost:
return 0
cur=0
dp0=cost[0]
if len(cost) >= 2:
dp1=cost[1]
for i in range(2, len(cost)):
cur=cost[i] + min(dp0,dp1)
dp0=dp1
dp1=cur
return min(dp0,dp1) | min-cost-climbing-stairs | 94% FASTER 97% Space Efficient Python solutions Different approaches | anuvabtest | 34 | 2,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,253 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2260902/94-FASTER-97-Space-Efficient-Python-solutions-Different-approaches | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
for i in range(len(cost) - 3, -1, -1):
cost[i] += min(cost[i+1], cost[i+2])
return min(cost[0], cost[1]) | min-cost-climbing-stairs | 94% FASTER 97% Space Efficient Python solutions Different approaches | anuvabtest | 34 | 2,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,254 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2260902/94-FASTER-97-Space-Efficient-Python-solutions-Different-approaches | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
if not cost:return 0
cur=0
dp0=cost[0]
dp1=cost[1]
for i in range(2, len(cost)):
cur=cost[i] + min(dp0,dp1)
dp0=dp1
dp1=cur
return min(dp0,dp1) | min-cost-climbing-stairs | 94% FASTER 97% Space Efficient Python solutions Different approaches | anuvabtest | 34 | 2,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,255 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/530398/EASY-Python-Solution-100-faster-and-less-memory-three-simple-lines | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
# Loop through every cost after the first two steps
for i in range(2, len(cost)):
# Update the cheapest cost to step here
cost[i] += min(cost[i-2], cost[i-1])
# Cheapest cost of the last... | min-cost-climbing-stairs | EASY Python Solution 100% faster and less memory, three simple lines | jhacker | 23 | 1,800 | min cost climbing stairs | 746 | 0.625 | Easy | 12,256 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2519502/Very-Easy-oror-0-ms-oror-100-oror-Fully-Explained-oror-C%2B%2B-Java-Python-JS-Python3-oror-DP | class Solution(object):
def minCostClimbingStairs(self, cost):
# Traverse all stairs through the loop...
for idx in range(2,len(cost)):
# Recurrence formula: cost[idx] = math.min(cost[idx - 1], cost[idx - 2]) + cost[idx];
# Get the minimum cost that will be counted to reach t... | min-cost-climbing-stairs | Very Easy || 0 ms || 100% || Fully Explained || C++, Java, Python, JS, Python3 || DP | PratikSen07 | 10 | 409 | min cost climbing stairs | 746 | 0.625 | Easy | 12,257 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/394083/Four-Solutions-in-Python-3-(DP)-(Bottom-Up-and-Top-Down) | class Solution:
def minCostClimbingStairs(self, c: List[int]) -> int:
c1, c2 = c[0], c[1]
for i in range(2,len(c)): c1, c2 = c2, c[i] + min(c1,c2)
return min(c1, c2) | min-cost-climbing-stairs | Four Solutions in Python 3 (DP) (Bottom Up and Top Down) | junaidmansuri | 10 | 1,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,258 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/394083/Four-Solutions-in-Python-3-(DP)-(Bottom-Up-and-Top-Down) | class Solution:
def minCostClimbingStairs(self, c: List[int]) -> int:
c1, c2 = c[-2], c[-1]
for i in range(len(c)-3,-1,-1): c1, c2 = c[i] + min(c1,c2), c1
return min(c1, c2) | min-cost-climbing-stairs | Four Solutions in Python 3 (DP) (Bottom Up and Top Down) | junaidmansuri | 10 | 1,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,259 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/394083/Four-Solutions-in-Python-3-(DP)-(Bottom-Up-and-Top-Down) | class Solution:
def minCostClimbingStairs(self, c: List[int]) -> int:
L, _ = len(c), c.append(0)
def MinCost(i):
if i < 2: return c[i]
return c[i] + min(MinCost(i-1),MinCost(i-2))
return MinCost(L) | min-cost-climbing-stairs | Four Solutions in Python 3 (DP) (Bottom Up and Top Down) | junaidmansuri | 10 | 1,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,260 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/394083/Four-Solutions-in-Python-3-(DP)-(Bottom-Up-and-Top-Down) | class Solution:
def minCostClimbingStairs(self, c: List[int]) -> int:
DP, L, _ = c[:2] + [-1]*len(c), len(c), c.append(0)
def MinCost(i):
if DP[i] != -1: return DP[i]
DP[i] = c[i] + min(MinCost(i-1),MinCost(i-2))
return DP[i]
return MinCost(L)
- Junaid Mansuri
(LeetCode ID)... | min-cost-climbing-stairs | Four Solutions in Python 3 (DP) (Bottom Up and Top Down) | junaidmansuri | 10 | 1,300 | min cost climbing stairs | 746 | 0.625 | Easy | 12,261 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1695178/Python-Simple-Python-Solution-Using-Dynamic-Programming-!!-O(N) | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
if len(cost)==2:
return min(cost)
dp=[0]*len(cost)
dp[0]=cost[0]
dp[1]=cost[1]
for i in range(2,len(cost)):
dp[i]=min(dp[i-1],dp[i-2])+cost[i]
return min(dp[-1],dp[-2]) | min-cost-climbing-stairs | [ Python ] ✅✅ Simple Python Solution Using Dynamic Programming !! O(N) 🥳✌👍 | ASHOK_KUMAR_MEGHVANSHI | 6 | 302 | min cost climbing stairs | 746 | 0.625 | Easy | 12,262 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1541553/Python-Easy-to-Understand-Solution | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
for i in range(2, len(cost)):
cost[i] += min(cost[i-2], cost[i-1])
return min(cost[-2], cost[-1]) | min-cost-climbing-stairs | Python Easy to Understand Solution | aaffriya | 5 | 338 | min cost climbing stairs | 746 | 0.625 | Easy | 12,263 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1546085/Short-python-solution-with-comments-O(n)-time-and-O(1)-space. | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
# The problem description tells us our staircase is at least 2 steps long.
# a and b track the most cost-effective paths to the last 2 steps we looked at.
# Let's look at the first 2 steps of our staircase:
a, b = cost[0], cost[1... | min-cost-climbing-stairs | Short python solution with comments, O(n) time and O(1) space. | imterrible | 4 | 345 | min cost climbing stairs | 746 | 0.625 | Easy | 12,264 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1546085/Short-python-solution-with-comments-O(n)-time-and-O(1)-space. | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
for i in range(2, len(cost)):
cost[i] = cost[i] + min(cost[i-1], cost[i-2])
return min(cost[-1], cost[-2]) | min-cost-climbing-stairs | Short python solution with comments, O(n) time and O(1) space. | imterrible | 4 | 345 | min cost climbing stairs | 746 | 0.625 | Easy | 12,265 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1832953/Python3-Dynamic-programming | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
"""
[10, 15, 20]
10 15
"""
n = len(cost)
dp = [0] * n
dp[0] = cost[0]
dp[1] = cost[1]
for i in range(2,n):
... | min-cost-climbing-stairs | [Python3] Dynamic programming | zhanweiting | 3 | 193 | min cost climbing stairs | 746 | 0.625 | Easy | 12,266 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1447910/python3-solution-dp | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
prev1=cost[0]
prev2=cost[1]
for i in range(2,len(cost)):
temp=cost[i]+min(prev1,prev2)
prev1=prev2
prev2=temp
return min(prev2,prev1) | min-cost-climbing-stairs | python3 solution dp | abhi_n_001 | 3 | 401 | min cost climbing stairs | 746 | 0.625 | Easy | 12,267 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2824595/oror-O(1)-space-oror-EASIEST-and-SHORTEST-solution-oror | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
a=b=0
for c in cost:a,b=b,min(a,b)+c
return min(a,b) | min-cost-climbing-stairs | || O(1) space || EASIEST and SHORTEST solution || | m9810223new1 | 2 | 121 | min cost climbing stairs | 746 | 0.625 | Easy | 12,268 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2695518/O(1)-Space-O(n)-Time-DP-Solution | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:dyan
a = cost[0]
b = cost[1]
#This is the same as:
#memo[0] = cost[0]
#memo[1] = cost[1]
cost.append(0) #For some reason, we want to get to the last index + 1, which is free. This is the same as a... | min-cost-climbing-stairs | O(1) Space O(n) Time DP Solution | mephiticfire | 2 | 524 | min cost climbing stairs | 746 | 0.625 | Easy | 12,269 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2261130/python3-or-explained-or-very-easy-or-dp | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
if n==2:
return min(cost) # minimum of two elements as n == 2
dp = [0]*n
dp[0], dp[1] = cost[0], cost[1] # initializing the dp
for i in range(2, n):
... | min-cost-climbing-stairs | python3 | explained | very easy | dp | H-R-S | 2 | 138 | min cost climbing stairs | 746 | 0.625 | Easy | 12,270 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2260874/Python-Fibonacci-it-is.-98.19 | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
if len(cost) < 3:
return min(cost)
dp = [0]*(len(cost)+1)
dp[0] = cost[0]
dp[1] = cost[1]
for i in range(2, len(cost)):
dp[i] = cost[i] + min(dp[i-1],dp[i-2])
ret... | min-cost-climbing-stairs | [Python] Fibonacci it is. 98.19% | justinjia0201 | 2 | 370 | min cost climbing stairs | 746 | 0.625 | Easy | 12,271 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1960654/Simple-python3-dp-solution | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
dp = [0]*(n)
dp[0] = cost[0]
dp[1] = cost[1]
for i in range(2, n):
dp[i] = cost[i] + min(dp[i-1], dp[i-2])
return min(dp[n-2], dp[n-1]) | min-cost-climbing-stairs | Simple python3 dp solution | codesankalp | 2 | 63 | min cost climbing stairs | 746 | 0.625 | Easy | 12,272 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1216127/Python-Recursive-Solution-and-Bottom-Up-Solution | class Solution:
def helper(self, cost):
# Base Condition
if len(cost)==1 or len(cost)==2:
return cost[0]
# Choices
return min(cost[0] + self.helper(cost[1:]), cost[0] + self.helper(cost[2:]) )
def minCostClimbingStairs(self, cost: List[int]) -> int:
retu... | min-cost-climbing-stairs | Python Recursive Solution & Bottom Up Solution | paramvs8 | 2 | 145 | min cost climbing stairs | 746 | 0.625 | Easy | 12,273 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1027451/Simple-and-easy | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
dp=[0]*(len(cost))
dp[0],dp[1]=cost[0],cost[1]
for i in range(2,len(cost)):
dp[i]=min(dp[i-1]+cost[i],dp[i-2]+cost[i])
return min(dp[-1],dp[-2]) | min-cost-climbing-stairs | Simple and easy | thisisakshat | 2 | 222 | min cost climbing stairs | 746 | 0.625 | Easy | 12,274 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/452506/Beats-97-in-run-time-and-100-in-memory. | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
for i in range(0,len(cost) -2):
cost[i+2] += min(cost[i], cost[i+1])
return min(cost[-2], cost[-1]) | min-cost-climbing-stairs | Beats 97% in run time and 100% in memory. | sudhirkumarshahu80 | 2 | 322 | min cost climbing stairs | 746 | 0.625 | Easy | 12,275 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2465942/Python-(Simple-Solution-and-Beginner-Friendly) | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
cost.append(0)
for i in range(len(cost)-3, -1, -1):
cost[i]+= min(cost[i+1], cost[i+2])
return min(cost[0], cost[1]) | min-cost-climbing-stairs | Python (Simple Solution and Beginner-Friendly) | vishvavariya | 1 | 87 | min cost climbing stairs | 746 | 0.625 | Easy | 12,276 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2323337/Top-to-Bottom-oror-Bottom-to-Top-Approach-oror-Two-way-Solutions | class Solution(object):
def minCostClimbingStairs(self, cost):
"""
:type cost: List[int]
:rtype: int
"""
for i in range(2,len(cost)):
cost[i] = min(cost[i-1],cost[i-2])+cost[i]
return min(cost[-1],cost[-2]) | min-cost-climbing-stairs | Top-to-Bottom || Bottom-to-Top Approach || Two way Solutions | mridulbhas | 1 | 150 | min cost climbing stairs | 746 | 0.625 | Easy | 12,277 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2323337/Top-to-Bottom-oror-Bottom-to-Top-Approach-oror-Two-way-Solutions | class Solution(object):
def minCostClimbingStairs(self, cost):
"""
:type cost: List[int]
:rtype: int
"""
#Top-to-Bottom Approach
dp = [-1]*(len(cost))
return min(self.topToBottom(cost,dp,len(cost)-1),self.topToBottom(cost,dp,len(cost)-2))
def topToBot... | min-cost-climbing-stairs | Top-to-Bottom || Bottom-to-Top Approach || Two way Solutions | mridulbhas | 1 | 150 | min cost climbing stairs | 746 | 0.625 | Easy | 12,278 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2261150/Python3-DP-solution-top-down-approach | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
dp, length = {}, len(cost)
def getResult(index):
if index >= length:
return 0
if index in dp:
return dp[index]
dp[index] = cost[index] + ... | min-cost-climbing-stairs | 📌 Python3 DP solution top down approach | Dark_wolf_jss | 1 | 5 | min cost climbing stairs | 746 | 0.625 | Easy | 12,279 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2087773/Python3-O(N)-oror-O(1)-72ms-62.89 | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
return self.solTwo(cost)
# return self.solOneByDpList(cost)
# O(n) || O(1)
# 72ms 62.89%
def solTwo(self, cost):
if not cost:
return 0
current, next = 0, 0
... | min-cost-climbing-stairs | Python3 O(N) || O(1) 72ms 62.89% | arshergon | 1 | 87 | min cost climbing stairs | 746 | 0.625 | Easy | 12,280 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2058908/Python3-easy-understanding | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
f = [0]*len(cost)
f[0] = cost[0]
f[1] = cost[1]
for i in range(2, len(cost)):
f[i] = min(f[i-2]+cost[i], f[i-1]+cost[i])
return min(f[-1], f[-2]) | min-cost-climbing-stairs | Python3 easy understanding | Shirley_lx | 1 | 76 | min cost climbing stairs | 746 | 0.625 | Easy | 12,281 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1885895/Python | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
a0=cost[0]
a1=cost[1]
for i in range(2, len(cost)):
a0, a1=a1, cost[i]+min(a0, a1)
return min(a0,a1) | min-cost-climbing-stairs | Python | zouhair11elhadi | 1 | 165 | min cost climbing stairs | 746 | 0.625 | Easy | 12,282 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1709240/Python-Easy-O(1)-Space-Complexity-Solution | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
i2 = 0
i1 = 0
for i in range(2, len(cost)+1):
i2, i1 = i1, min(i1 + cost[i-1],i2+cost[i-2])
return i1 | min-cost-climbing-stairs | Python Easy O(1) Space Complexity Solution | atiq1589 | 1 | 135 | min cost climbing stairs | 746 | 0.625 | Easy | 12,283 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1565669/Python3-Solution-or-DP-Solution | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
for i in range(2,n):
cost[i] += min(cost[i-1],cost[i-2])
return min(cost[n-1],cost[n-2]) | min-cost-climbing-stairs | Python3 Solution | DP Solution | satyam2001 | 1 | 343 | min cost climbing stairs | 746 | 0.625 | Easy | 12,284 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1478960/Python3-DP-solution | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
if len(cost) == 0:
return 0
if len(cost) == 1:
return cost[0]
dp = [0]*len(cost)
dp[0] = cost[0]
dp[1] = cost[1]
i = 2
while i < len(cost):
dp[i] = cost[i] + min(dp[i-1], dp[i-2])
i += 1
return min(dp[len(cost)-1], dp... | min-cost-climbing-stairs | Python3 DP solution | Janetcxy | 1 | 149 | min cost climbing stairs | 746 | 0.625 | Easy | 12,285 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1367715/A-Bottom-Up-Dynamic-Programming-Solution-for-absolute-beginners | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
if(len(cost) == 1):
return cost[0]
if(len(cost) == 2):
return min(cost[0], cost[1])
dp = [0]*len(cost)
dp[0] = cost[0]
dp[1] = cost[1]
for i in range(2, len(cost)):
... | min-cost-climbing-stairs | A Bottom Up Dynamic Programming Solution for absolute beginners | Amogh23 | 1 | 278 | min cost climbing stairs | 746 | 0.625 | Easy | 12,286 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1363401/Python-Code-or-95-Faster-in-Time | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
f,s=cost[0],cost[1]
for i in cost[2:]:
x=min(i+f,i+s)
f=s
s=x
return min(f,s) | min-cost-climbing-stairs | Python Code | 95% Faster in Time | rackle28 | 1 | 134 | min cost climbing stairs | 746 | 0.625 | Easy | 12,287 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1257579/Python-Solution | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
first = second = 0
for c in cost:
first, second = second, c + min(first, second)
return min(first, second) | min-cost-climbing-stairs | Python Solution | mariandanaila01 | 1 | 175 | min cost climbing stairs | 746 | 0.625 | Easy | 12,288 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1221676/Python3-simple-solution-beats-97-users | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
a = cost[1]
b = cost[0]
for i in range(2,n):
x = cost[i] + min(a, b)
b = a
a = x
return min(a, b) | min-cost-climbing-stairs | Python3 simple solution beats 97% users | EklavyaJoshi | 1 | 69 | min cost climbing stairs | 746 | 0.625 | Easy | 12,289 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/1012637/Python3-DP-Solution-or-Beats-97-or-Easy-to-understand | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n=len(cost)
dp=[0]*n
dp[0]=cost[0]
dp[1]=cost[1]
for i in range(2,n):
dp[i]=min(dp[i-1], dp[i-2])+cost[i]
return min(dp[n-1], dp[n-2]) | min-cost-climbing-stairs | [Python3] DP Solution | Beats 97% | Easy to understand | _vaishalijain | 1 | 260 | min cost climbing stairs | 746 | 0.625 | Easy | 12,290 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/493976/Python-52ms12.8MB-Solution-(92100) | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
f0, f1 = cost[0], cost[1]
for i in range(2,len(cost)):
tmp = cost[i] + min(f0, f1)
f0 = f1
f1 = tmp
return min(f0, f1) | min-cost-climbing-stairs | Python 52ms/12.8MB Solution (92%/100%) | X_D | 1 | 208 | min cost climbing stairs | 746 | 0.625 | Easy | 12,291 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2841965/Solution-version-01 | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
self.cost = cost
one , two = cost[len(cost)-1] , 0
pointer = len(cost) - 2
while pointer > -1:
temp = min(cost[pointer] + one,cost[pointer] + two)
pointer -= 1
two = one
... | min-cost-climbing-stairs | Solution version 01 | MahsanulNirjhor | 0 | 2 | min cost climbing stairs | 746 | 0.625 | Easy | 12,292 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2818376/746.-Min-Cost-Climbing-Stairs-Solutionor-TC%3A-O(n)-or-SC%3A-O(1) | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
if n <= 2:
return min(cost)
prev2 = cost[0]
prev = cost[1]
curr = 0
for i in range(2, n):
curr = min(prev2, prev) + cost[i]
prev2 = pre... | min-cost-climbing-stairs | 746. Min Cost Climbing Stairs Solution| TC: O(n) | SC: O(1) | khritish17 | 0 | 3 | min cost climbing stairs | 746 | 0.625 | Easy | 12,293 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2818135/Python-Each-step-visualized-concise-single-screen-O(n)-time%2Bspace | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
'''
The idea is, given we can take either 1 or 2 steps,
and the goal is to get to the step after last step
(as in, if cost in [10,15,20], we want to get to index 3, after 20)
We can start from 2 ... | min-cost-climbing-stairs | [Python] Each step visualized concise single screen O(n) time+space | graceiscoding | 0 | 1 | min cost climbing stairs | 746 | 0.625 | Easy | 12,294 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2815330/Min-Cost-Climbing-Stairs-using-Dynamic-Programming | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
def solve(n,cost,dp):
if n==1 or n==0:
return cost[n]
if dp[n] != -1:
return dp[n]
dp[n] = cost[n] + min(solve(n-1,cost,dp), solve(n-2,cost,dp))... | min-cost-climbing-stairs | Min Cost Climbing Stairs using Dynamic Programming | sarthakchawande14 | 0 | 2 | min cost climbing stairs | 746 | 0.625 | Easy | 12,295 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2814037/Python-or-Simple-or-Recursion-or-DP | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
cost = [0] + cost + [0]
dp = {}
def dfs(idx):
if idx<1: return 0
if dp.get(idx,None) is not None: return dp[idx]
dp[idx] = min(cost[idx] + dfs(idx-1), cost[idx] + dfs(idx-2))
... | min-cost-climbing-stairs | Python | Simple | Recursion | DP | girraj_14581 | 0 | 5 | min cost climbing stairs | 746 | 0.625 | Easy | 12,296 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2812698/Python-solutionororEasy-to-Understand | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
dp = [-1]*len(cost)
dp[0] = cost[0]
dp[1] = cost[1]
n = len(cost)
for i in range(2,n):
dp[i] = min(cost[i]+dp[i-1],cost[i]+dp[i-2])
return min(dp[n-1],dp[n-2]) | min-cost-climbing-stairs | Python solution||Easy to Understand | sajit9285 | 0 | 3 | min cost climbing stairs | 746 | 0.625 | Easy | 12,297 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2790364/Bottom-Up-Approach-or-O(n)-time-O(1)-space | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
cost.append(0)
for i in range(len(cost)-3, -1, -1):
cost[i] += min(cost[i+1], cost[i+2])
return min(cost[0], cost[1]) | min-cost-climbing-stairs | Bottom-Up Approach | O(n) time, O(1) space | wakadoodle | 0 | 7 | min cost climbing stairs | 746 | 0.625 | Easy | 12,298 |
https://leetcode.com/problems/min-cost-climbing-stairs/discuss/2750659/DP-Short-Python-O(n)-time-and-no-extra-space-(re-use-existing-list) | class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
for i in range(2, len(cost)):
cost[i] += min(cost[i-1], cost[i-2])
return min(cost[-2:]) | min-cost-climbing-stairs | DP Short Python O(n) time and no extra space (re-use existing list) | MVR11 | 0 | 8 | min cost climbing stairs | 746 | 0.625 | Easy | 12,299 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.