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/maximum-number-of-words-you-can-type/discuss/2650405/O(n)-Time-O(1)-Space | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
b=0
for i in brokenLetters:
b= b | 1<<(ord(i)-97)
r=0
f=1
for i in text:
if i==' ':
r+=f
f=1
continue
... | maximum-number-of-words-you-can-type | O(n) Time , O(1) Space | saianirudh_me | 0 | 2 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,300 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/2584982/Python-oror-Easy-and-well-explain-solution | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
count = 0
checker = 0
words = text.split()
for word in words:
for i in word:
if i in brokenLetters:
checker = 1
break
... | maximum-number-of-words-you-can-type | Python || Easy and well explain solution | ride-coder | 0 | 25 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,301 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/2575451/Simple-python-solution | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
text_list = text.split(" ")
res = 0
for word in text_list:
for ch in word:
if ch in brokenLetters:
break
else:
res += 1
return ... | maximum-number-of-words-you-can-type | Simple python solution | aruj900 | 0 | 14 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,302 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/2567377/Maximum-Number-of-words-you-can-type | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
word=text.split(" ")
fullyTyped=len(word)
for word1 in word:
for letter in word1:
if letter in brokenLetters:
fullyTyped-=1
break
retur... | maximum-number-of-words-you-can-type | Maximum Number of words you can type | KavitaPatel966 | 0 | 16 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,303 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/2505524/Python3-No-hash-99-runtime-with-explanation | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
# Split the input into distinct words, and set the output equal to the number of words created
words = text.split(' ')
output = len(words)
# Loop through each word, and then loop throug... | maximum-number-of-words-you-can-type | [Python3] No hash - 99% runtime with explanation | connorthecrowe | 0 | 27 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,304 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/2155068/Operations-over-sets | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
words = list(map(set, text.split()))
res = 0
lts = set(brokenLetters)
for w in words:
if not w & lts:
res += 1
return res | maximum-number-of-words-you-can-type | Operations over sets | dima62 | 0 | 23 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,305 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1846938/Easiest-and-Smallest-Python3-Solution-oror-100-Faster-oror-Easy-to-Understand-oror-Explained | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
ct=0
t=0
s=text.split(" ")
for i in s:
for j in i:
if j in brokenLetters:
ct=ct+1
if ct==0:
t=t+1
ct=0
retu... | maximum-number-of-words-you-can-type | Easiest & Smallest Python3 Solution || 100% Faster || Easy to Understand || Explained | RatnaPriya | 0 | 81 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,306 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1826915/easy-python-code | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
w = text.split(" ")
count = 0
for i in w:
flag = False
for j in brokenLetters:
if j in i:
flag = True
break
if flag == ... | maximum-number-of-words-you-can-type | easy python code | dakash682 | 0 | 60 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,307 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1755726/Simple-Python-Solution | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
arr=text.split(' ')
print(arr)
count=0
for word in arr:
flag=0
for char in word:
if char in brokenLetters:
flag=1
break
... | maximum-number-of-words-you-can-type | Simple Python Solution | Siddharth_singh | 0 | 42 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,308 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1754201/Idk-why-mine-is-still-slow | class Solution:
def canBeTypedWords(self, txt: str, bl: str) -> int:
bl=set(bl)
cnt=len(txt.split(' '))
for i in range(cnt):
s_txt = set(txt.split(' ')[i])
if bl.intersection(s_txt) != set() :
cnt -= 1
return cnt | maximum-number-of-words-you-can-type | Idk why mine is still slow | flame91 | 0 | 11 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,309 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1692621/Python3-Map-Reduce-and-sets | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
def helper(w):
return int(len(set(w) & set(brokenLetters)) == 0)
return reduce(lambda acc, x: acc+is_valid(x), text.split(), 0) | maximum-number-of-words-you-can-type | [Python3] - Map / Reduce and sets | patefon | 0 | 37 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,310 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1620630/Easy-Python.-28ms-runtime | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
broken = set(list(brokenLetters))
res = 0
for word in text.split(" "):
validWord = True
for w in word:
if w in broken:
validWord = False
... | maximum-number-of-words-you-can-type | Easy Python. 28ms runtime | manassehkola | 0 | 61 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,311 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1407160/Python3-Faster-than-76.50-of-the-Solutions | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
words = text.split()
result = []
for word in words:
flag = True
for c in word:
if c in brokenLetters:
flag = False
break
... | maximum-number-of-words-you-can-type | Python3 - Faster than 76.50% of the Solutions | harshitgupta323 | 0 | 61 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,312 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1392527/Python3-Faster-Than-97.50 | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
b = set(brokenLetters)
c = len(text.split())
broken = False
for i in text:
if i in b:
broken = True
if i == ' ':
if broken:
... | maximum-number-of-words-you-can-type | Python3 Faster Than 97.50% | Hejita | 0 | 102 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,313 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1366572/Easy-Python-Solution | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
text = text.split()
length = len(text)
brokenLetters = set(brokenLetters)
for word in text:
for char in word:
if char in brokenLetters:
length -= 1
... | maximum-number-of-words-you-can-type | Easy Python Solution | sangam92 | 0 | 78 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,314 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1357412/Python-fast-and-pythonic | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
def _checker(word):
return all([i not in brokenLetters for i in set(word)])
return len([True for word in text.split() if _checker(word)]) | maximum-number-of-words-you-can-type | [Python] fast and pythonic | cruim | 0 | 93 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,315 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1355900/Python3-hash-set | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
ans = 0
brokenLetters = set(brokenLetters)
for word in text.split():
if not set(word) & brokenLetters: ans += 1
return ans | maximum-number-of-words-you-can-type | [Python3] hash set | ye15 | 0 | 50 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,316 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1346290/Python-3-Simple-and-Fast-Solution-(24ms) | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
count = 0
broken_chars = set(brokenLetters)
for word in text.split(" "):
unique_chars = set(word)
count += (len(unique_chars - broken_chars) == len(unique_chars))
return count | maximum-number-of-words-you-can-type | [Python 3] Simple & Fast Solution (24ms) | wasi0013 | 0 | 51 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,317 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1345371/easy-python-solution-with-comments-and-explanation | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
# split the words by space delimiter
words = text.split()
#end result variable
count=0
for word in words:
flag=1 #boolean for adding current word to final list or not
f... | maximum-number-of-words-you-can-type | easy python solution with comments and explanation | naveen_29 | 0 | 42 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,318 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1344979/Python-Easy | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
res, cnt = 0, 0
for val in text.split():
for t in brokenLetters:
if t not in val:
cnt += 1
else:
break
if cnt == len(broken... | maximum-number-of-words-you-can-type | Python Easy | torch7 | 0 | 39 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,319 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1344899/Easy-Python-Solution | class Solution:
def canBeTypedWords(self, text: str, bL: str) -> int:
count=0
arr=text.split(" ")
for a in arr:
flag=0
for b in bL:
if b in a:
flag=1
break
if not flag:
count+=1
... | maximum-number-of-words-you-can-type | Easy Python Solution | deleted_user | 0 | 83 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,320 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1788795/98.85-lesser-memory-or-Simple-Python3-solution-or-O(n)-solution | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
text = text.split()
n = len(text)
for i in text:
for j in brokenLetters:
if j in i:
n -= 1
break
return n | maximum-number-of-words-you-can-type | ✔98.85% lesser memory | Simple Python3 solution | O(n) solution | Coding_Tan3 | -1 | 62 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,321 |
https://leetcode.com/problems/maximum-number-of-words-you-can-type/discuss/1346611/Easy-Python-Solution(100) | class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
t=text.split(" ")
b=list(brokenLetters)
print(t,b)
ans=[]
for i in range(len(t)):
c=0
for j in range(len(b)):
if(b[j] in t[i]):
c+=1
... | maximum-number-of-words-you-can-type | Easy Python Solution(100%) | Sneh17029 | -1 | 149 | maximum number of words you can type | 1,935 | 0.71 | Easy | 27,322 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1344878/Divide-gaps-by-dist | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
return sum((a - b - 1) // dist for a, b in zip(rungs, [0] + rungs)) | add-minimum-number-of-rungs | Divide gaps by dist | votrubac | 37 | 1,800 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,323 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1345016/O(n)-python-solution-with-explanation-for-(-1) | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
newrungs = 0
prev = 0
for rung in rungs:
diff = rung - prev
if diff > dist:
add = diff / dist # Number of rungs we need to add
... | add-minimum-number-of-rungs | O(n) python solution, with explanation for (-1) | kkochhar9 | 3 | 214 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,324 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1345016/O(n)-python-solution-with-explanation-for-(-1) | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
newrungs = 0
prev = 0
for rung in rungs:
diff = rung - prev - 1
newrungs += diff // dist
prev = rung
return newrungs | add-minimum-number-of-rungs | O(n) python solution, with explanation for (-1) | kkochhar9 | 3 | 214 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,325 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1364199/Python-easy-to-understand-oror-Faster-than-87.16 | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
count = 0
if rungs[0] > dist:
m = rungs[0]
m = (m - 1) // dist
count += m
for i in range (len(rungs) - 1):
k = rungs[i+1] - rungs[i]
if k > dist:
... | add-minimum-number-of-rungs | Python easy to understand || Faster than 87.16% | adityarichhariya7879 | 2 | 136 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,326 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1361117/python3-or-Easy-or-For-beginners | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
h = 0
solution = 0
for r in rungs:
if (r-h)%dist==0:
solution+=(r-h)//dist-1
else:
solution+=(r-h)//dist
h=r
return solution | add-minimum-number-of-rungs | python3 | Easy | For beginners | charukalyani1098 | 1 | 112 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,327 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1344915/Best-Simple-one-pass-Solution-in-Python | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
height=0
sol=0
for r in rungs:
if (r-height)%dist==0:
sol+=(r-height)//dist-1
else:
sol+=(r-height)//dist
height=r
return sol | add-minimum-number-of-rungs | Best Simple one pass Solution in Python | deleted_user | 1 | 113 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,328 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/2782614/Simply-syntax-on-Python-O(n) | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
curr, preSum = 0, []
for run in rungs:
preSum.append(run - curr)
curr = run
result = sum([ (k-1 if dist == 1 else (k//dist if k%dist > 0 else (k//dist) - 1) ) for k in preSum if k > dis... | add-minimum-number-of-rungs | Simply syntax on Python O(n) | DNST | 0 | 1 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,329 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/2670251/Greedy-oror-distance-oror-python-oror-TC-O(N) | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
ans = 0
if rungs[0] - 0 > dist:
ans += (rungs[0]-1)//dist
for i in range(len(rungs)):
diff = rungs[i] - rungs[i-1]
if diff > dist:
ans += (diff-1)//dist
return... | add-minimum-number-of-rungs | Greedy || distance || python || TC - O(N) | mihirshah0114 | 0 | 4 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,330 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1808105/python-very-simple-solution | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
n = len(rungs)
res = 0
for i in range(n-1):
a, b = rungs[i], rungs[i+1]
s = b - a
if s > dist:
res += (s-1)//dist
if rungs[0] > dist:
res += (rungs... | add-minimum-number-of-rungs | python very simple solution | byuns9334 | 0 | 82 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,331 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1804687/Python-O(n)-Easy-Understanding-clean-solution | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
count = 0
if dist < rungs[0]:
count += int((rungs[0]-1)/dist)
for i in range(len(rungs)-1):
if rungs[i]+dist < rungs[i+1]:
count += (rungs[i+1]-rungs[i]-1)... | add-minimum-number-of-rungs | Python O(n), Easy Understanding clean solution | Nish786 | 0 | 38 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,332 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1367310/Walrus-operator | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
rungs.insert(0, 0)
return sum((diff := b - a) // dist - (diff % dist == 0)
for a, b in zip(rungs, rungs[1:])) | add-minimum-number-of-rungs | Walrus operator | EvgenySH | 0 | 59 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,333 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1367310/Walrus-operator | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
rungs.insert(0, 0)
return sum((b - a - 1) // dist for a, b in zip(rungs, rungs[1:])) | add-minimum-number-of-rungs | Walrus operator | EvgenySH | 0 | 59 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,334 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1360277/Python3-Straightforward-O(n)-Solution-with-Explanation | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
rungs.insert(0,0) #Firstly, we add 0 to the start of the array. Because in the question, it says that we should start from ground.
fin = 0
for number in range(len(rungs)-1): #we iterate over the array, excluding last... | add-minimum-number-of-rungs | Python3 Straightforward O(n) Solution with Explanation | selimtanriverdien | 0 | 76 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,335 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1355903/Python3-greedy | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
ans = prev = 0
for x in rungs:
ans += (x - prev - 1) // dist
prev = x
return ans | add-minimum-number-of-rungs | [Python3] greedy | ye15 | 0 | 55 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,336 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1346199/Python-3-O(n)-solution-easy-to-understand | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
current_rung = 0
count = 0
for next_rung in rungs:
if current_rung + dist < next_rung:
div, mod = divmod(next_rung - current_rung, dist)
count += div - (mod == 0)
... | add-minimum-number-of-rungs | [Python 3] O(n) solution easy to understand | wasi0013 | 0 | 56 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,337 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1345014/Python3-easy-solution-with-explanation | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
rungsDiff = [rungs[0]] + [ rungs[i] - rungs[i-1] for i in range(1,len(rungs))]
addRung = 0
# Find elements in rungsDiff that are larger than dist
for i, diff in enumerate(rungsDiff):
if diff > dist:
... | add-minimum-number-of-rungs | Python3 easy solution with explanation | wu1meng2 | 0 | 44 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,338 |
https://leetcode.com/problems/add-minimum-number-of-rungs/discuss/1344952/Python-Straight-forward | class Solution:
def addRungs(self, rungs: List[int], dist: int) -> int:
n = len(rungs)
count = 0
if dist == 1:
if rungs[0]>1:
count += rungs[0]-1
for i in range(n-1):
if rungs[i+1]-rungs[i] > 1:
count+= rungs[i+1]-ru... | add-minimum-number-of-rungs | [Python] Straight forward | error504 | 0 | 40 | add minimum number of rungs | 1,936 | 0.429 | Medium | 27,339 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/2119013/Python%3A-Dynamic-Programming-O(mn)-Solution | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
m, n = len(points), len(points[0])
dp = points[0]
left = [0] * n ## left side contribution
right = [0] * n ## right side contribution
for r in range(1, m):
for c in ran... | maximum-number-of-points-with-cost | Python: Dynamic Programming O(mn) Solution | dadhania | 14 | 784 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,340 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/2058133/python-3-oror-O(mn)-time-O(1)-space | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
m, n = len(points), len(points[0])
for i in range(m - 1):
for j in range(1, n):
points[i][j] = max(points[i][j], points[i][j - 1] - 1)
for j in range(n - 2, -1, -1):
... | maximum-number-of-points-with-cost | python 3 || O(mn) time, O(1) space | dereky4 | 4 | 546 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,341 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/1704260/Python3-Solution | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
M = len(points)
N = len(points[0])
dp = [[0]*N for _ in range(M)]
for i in range(N):
dp[0][i] = points[0][i]
for i in range(1, M):
rollingMax = float('-inf')
... | maximum-number-of-points-with-cost | Python3 Solution | ruifate | 3 | 738 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,342 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/1345120/Well-Explained-oror-88-faster-oror-DP-oror-pre-%2B-suff | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
m = len(points)
n = len(points[0])
if m==1:
return max(points[0])
if n==1:
s=0
for j in range(m):
s+=points[j][0]
return s
def lt(row):
left = [ele for ele in ... | maximum-number-of-points-with-cost | 🐍 Well-Explained || 88% faster || DP || pre + suff 📌 | abhi9Rai | 3 | 1,100 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,343 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/1542901/Intuitive-Python-DP-Solution | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
if not points:
return 0
res = max(points[0])
for r in range(1, len(points)):
dp = points[r-1]
for d in range(1, len(points[0])):
dp[d] = max(dp[d], dp[d-1]-1)
... | maximum-number-of-points-with-cost | Intuitive Python DP Solution | tohbaino | 2 | 1,100 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,344 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/1346338/Python-3-Priority-queue-O(m*n*log(n)) | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
m, n = len(points), len(points[0])
for i in range(1, m):
right = []
for j, x in enumerate(points[i-1]):
heappush(right, (-(x - j), j))
left = []
for j in rang... | maximum-number-of-points-with-cost | [Python 3] Priority queue O(m*n*log(n)) | chestnut890123 | 1 | 404 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,345 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/2807821/Python-(Simple-Dynamic-Programming) | class Solution:
def maxPoints(self, points):
m, n = len(points), len(points[0])
dp = points[0]
left, right = [0]*n, [0]*n
for i in range(1,m):
for j in range(n):
if j == 0:
left[j] = dp[j]
else:
le... | maximum-number-of-points-with-cost | Python (Simple Dynamic Programming) | rnotappl | 0 | 6 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,346 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/2718103/Python3-or-Prefix%2BSuffix-Sum-%2B-Tabular-DP | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
row,col=len(points),len(points[0])
dp=[[0 for i in range(col)] for j in range(row)]
for i in range(col):
dp[0][i]=points[0][i]
prefix,suffix=[0]*col,[0]*col
prefix[0]=points[0][0]
suffix[... | maximum-number-of-points-with-cost | [Python3] | Prefix+Suffix Sum + Tabular DP | swapnilsingh421 | 0 | 23 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,347 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/2104187/Python3-or-DP | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
m, n = len(points), len(points[0])
dp = [points[0]] + [[0] * n for _ in range(m - 1)]
for i in range(1,m):
prev_points = dp[i-1]
lft = dp[i - 1][::]
rht = dp[i - 1][::]
... | maximum-number-of-points-with-cost | Python3 | DP | yzhao156 | 0 | 266 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,348 |
https://leetcode.com/problems/maximum-number-of-points-with-cost/discuss/1355912/Python3-dp | class Solution:
def maxPoints(self, points: List[List[int]]) -> int:
m, n = len(points), len(points[0])
for i in range(1, m):
for j in range(n-2, -1, -1):
points[i-1][j] = max(points[i-1][j], points[i-1][j+1]-1)
prefix = 0
for j in range(n):
... | maximum-number-of-points-with-cost | [Python3] dp | ye15 | 0 | 369 | maximum number of points with cost | 1,937 | 0.362 | Medium | 27,349 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1359715/Python3-1-line | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set(Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | [Python3] 1-line | ye15 | 35 | 2,100 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,350 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1682769/93.6-accuracy-easiest-python-solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
a = set(s)
d = set()
for i in a:
d.add(s.count(i))
if len(d) == 1:
return True
else:
False | check-if-all-characters-have-equal-number-of-occurrences | 93.6% accuracy easiest python solution | ebrahim007 | 2 | 133 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,351 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2818754/Python-oror-Easy-oror-97.05-Faster-oror-Dictionary-oror-O(n)-Solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
d={}
for i in s:
if i in d:
d[i]+=1
else:
d[i]=1
t=d[s[0]]
for v in d.values():
if v!=t:
return False
return True | check-if-all-characters-have-equal-number-of-occurrences | Python || Easy || 97.05% Faster || Dictionary || O(n) Solution | DareDevil_007 | 1 | 43 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,352 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2656488/Simple-oror-Python-O(N) | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
dicta={}
for i in s:
dicta[i]=s.count(i)
d=dicta[s[0]]
print(d)
for i,j in enumerate(dicta):
print(j)
if dicta[j]!=d:
return False
return True | check-if-all-characters-have-equal-number-of-occurrences | [Simple || Python O(N)] | Sneh713 | 1 | 101 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,353 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1980559/Python-(Simple-Approach-and-Beginner-Friendly) | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
a = []
for i in s:
a.append(s.count(i))
print(a)
if a.count(a[0]) == len(a):
return True | check-if-all-characters-have-equal-number-of-occurrences | Python (Simple Approach and Beginner-Friendly) | vishvavariya | 1 | 77 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,354 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1894094/Python-Solution-or-100-Faster-or-HashMap-Based-or-Two-Solutions-Clean-Code-1-Liner | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
store = defaultdict()
for char in s:
store[char] += 1
if len(set(store.values())) == 1: return True
return False | check-if-all-characters-have-equal-number-of-occurrences | Python Solution | 100% Faster | HashMap Based | Two Solutions - Clean Code / 1 Liner | Gautam_ProMax | 1 | 116 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,355 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1894094/Python-Solution-or-100-Faster-or-HashMap-Based-or-Two-Solutions-Clean-Code-1-Liner | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set(Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python Solution | 100% Faster | HashMap Based | Two Solutions - Clean Code / 1 Liner | Gautam_ProMax | 1 | 116 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,356 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1806924/Python-3-Solution-or-93-Faster-runtime-or-2-Lines-solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
lst = [s.count(i) for i in set(s)]
return len(set(lst)) == 1 | check-if-all-characters-have-equal-number-of-occurrences | ✔Python 3 Solution | 93% Faster runtime | 2 Lines solution | Coding_Tan3 | 1 | 65 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,357 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1389203/Simple-Python-Solution-Using-Dictionary | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
if len(s)==1:
return True
dic={}
for i in s:
if i not in dic:
dic[i]=1
else:
dic[i]+=1
firs= dic.get(s[1])
for key,val in dic.items():
... | check-if-all-characters-have-equal-number-of-occurrences | Simple Python Solution Using Dictionary | sangam92 | 1 | 82 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,358 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2819241/Python-solution-using-set-and-Counter-one-line | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set(collections.Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python solution using set and Counter one line | samanehghafouri | 0 | 1 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,359 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2773821/Python-or-DictionaryorSetor-O(N)-time | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
d={}
for i in s:
d[i]=d.get(i,0)+1
s=set()
for i in d.values():
s.add(i)
return len(s)==1 | check-if-all-characters-have-equal-number-of-occurrences | Python | Dictionary|Set| O(N) time | ankit0702 | 0 | 2 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,360 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2666167/Python-Three-liner-Solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
counts = collections.Counter(s)
reference = counts[s[0]]
return all(val == reference for val in counts.values()) | check-if-all-characters-have-equal-number-of-occurrences | Python Three-liner Solution | kcstar | 0 | 4 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,361 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2604739/Solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
dtc = {}
for i in range(len(s)):
if s[i] in dtc:
dtc[s[i]] += 1
else:
dtc[s[i]] = 1
return (len(set(dtc.values())) < 2) | check-if-all-characters-have-equal-number-of-occurrences | Solution | fiqbal997 | 0 | 6 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,362 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2514081/Simple-python-solution-using-set | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
dic = collections.Counter(s)
count = set()
for k,v in dic.items():
count.add(v)
return len(count) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Simple python solution using set | aruj900 | 0 | 43 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,363 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2504510/Python-or-One-liner-with-Counter()-and-set() | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set(Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python | One-liner with Counter() and set() | Wartem | 0 | 18 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,364 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2426757/1941.-Check-if-All-Characters-Have-Equal-Number-of-Occurrences%3A-One-Liner | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set([s.count(element)for element in set(s)]))==1 | check-if-all-characters-have-equal-number-of-occurrences | 1941. Check if All Characters Have Equal Number of Occurrences: One Liner | rogerfvieira | 0 | 10 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,365 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2419255/Python-Solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set(Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python Solution | ethanroy | 0 | 13 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,366 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2293619/Simple-Python3-Solution-without-using-collections.Counter() | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
distinct_chr = set(s)
num = set()
for c in distinct_chr:
num.add(s.count(c))
if len(num) == 1:
return True
else:
return False | check-if-all-characters-have-equal-number-of-occurrences | Simple Python3 Solution without using collections.Counter() | vem5688 | 0 | 35 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,367 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2239090/Beginner-Friendly-Solution-oror-36ms-Faster-Than-91-oror-Python | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
# Initialize a Python dictionary to store each character and the corresponding number of occurences.
ds = {}
# Build our dictionary.
for char in s:
if char not in ds:
ds.setdefault(cha... | check-if-all-characters-have-equal-number-of-occurrences | Beginner Friendly Solution || 36ms, Faster Than 91% || Python | cool-huip | 0 | 32 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,368 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2207528/Python-1-line | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set(collections.Counter(s).values()))==1 | check-if-all-characters-have-equal-number-of-occurrences | Python 1-line | XRFXRF | 0 | 37 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,369 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2095015/PYTHON-or-Simple-python-solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
charMap = {}
for i in s:
charMap[i] = 1 + charMap.get(i, 0)
occurrence = charMap[s[0]]
for i in charMap:
if charMap[i] != occurrence:
ret... | check-if-all-characters-have-equal-number-of-occurrences | PYTHON | Simple python solution | shreeruparel | 0 | 52 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,370 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2045073/Check-if-All-Characters-Have-Equal-Number-of-Occurrences | class Solution(object):
def areOccurrencesEqual(self, s):
"""
:type s: str
:rtype: bool
"""
return len(set(Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Check if All Characters Have Equal Number of Occurrences | Muggles102 | 0 | 26 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,371 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/2044854/Python-simple-solution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
a = s[0]
for i in set(s):
if s.count(i) != s.count(a):
return False
return True | check-if-all-characters-have-equal-number-of-occurrences | Python simple solution | StikS32 | 0 | 60 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,372 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1949283/Python3-Solution-with-using-counting | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
c = collections.Counter(s)
prev_cnt = 0
for key in c:
if prev_cnt != 0 and c[key] != prev_cnt:
return False
prev_cnt = c[key]
return True | check-if-all-characters-have-equal-number-of-occurrences | [Python3] Solution with using counting | maosipov11 | 0 | 34 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,373 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1930510/Python-One-Line-or-Clean-and-Simple! | class Solution:
def areOccurrencesEqual(self, s):
counts = list(Counter(s).values())
return all(count == counts[0] for count in counts) | check-if-all-characters-have-equal-number-of-occurrences | Python - One Line | Clean and Simple! | domthedeveloper | 0 | 55 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,374 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1930510/Python-One-Line-or-Clean-and-Simple! | class Solution:
def areOccurrencesEqual(self, s):
return (lambda cts : all(count == cts[0] for count in cts))(list(Counter(s).values())) | check-if-all-characters-have-equal-number-of-occurrences | Python - One Line | Clean and Simple! | domthedeveloper | 0 | 55 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,375 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1930510/Python-One-Line-or-Clean-and-Simple! | class Solution:
def areOccurrencesEqual(self, s):
counts = Counter(s).values()
return len(set(counts)) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python - One Line | Clean and Simple! | domthedeveloper | 0 | 55 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,376 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1930510/Python-One-Line-or-Clean-and-Simple! | class Solution:
def areOccurrencesEqual(self, s):
return len(set(Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python - One Line | Clean and Simple! | domthedeveloper | 0 | 55 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,377 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1875267/Python-dollarolution | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
s = Counter(s)
return len(set(s.values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python $olution | AakRay | 0 | 34 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,378 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1701072/Python3-Solution-oror-Easy-way | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
lst = []
for x in s:
lst.append(s.count(x))
return len(set(lst)) == 1 | check-if-all-characters-have-equal-number-of-occurrences | [Python3] Solution || Easy way | Cheems_Coder | 0 | 50 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,379 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1687284/No-frill | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
char_map = {}
for c in s:
count = char_map.setdefault(c, 0)
char_map[c] = count + 1
counts = char_map.values()
return len(set(counts)) == 1 | check-if-all-characters-have-equal-number-of-occurrences | No frill | snagsbybalin | 0 | 23 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,380 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1560568/simple-solution-or-faster-than-~100 | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
list_of_set_of_s = list(set(s))
i_index = 0
j_index = i_index + 1
while j_index <= len(list_of_set_of_s):
if len(list_of_set_of_s) < 2:
... | check-if-all-characters-have-equal-number-of-occurrences | simple solution | faster than ~100% | anandanshul001 | 0 | 109 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,381 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1427351/Python3-or-easy-solution-or-set | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
d = set(collections.Counter(s).values())
if len(d) == 1:
return True
else:
return False | check-if-all-characters-have-equal-number-of-occurrences | Python3 | easy solution | set | FlorinnC1 | 0 | 132 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,382 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1425624/python-sol-faster-than-98 | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
dicc = {}
for i in s:
if i in dicc:
dicc[i] += 1
else:
dicc[i] = 1
for i in range(len(dicc.values()) - 1):
if list(dicc.values())[i] != list(dicc.values())[i + 1... | check-if-all-characters-have-equal-number-of-occurrences | python sol faster than 98% | elayan | 0 | 108 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,383 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1424161/Python-one-liner-and-one-more | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return len(set(Counter(s).values())) == 1 | check-if-all-characters-have-equal-number-of-occurrences | Python, one-liner and one more | blue_sky5 | 0 | 49 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,384 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1424161/Python-one-liner-and-one-more | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
counts = Counter(s).values()
return max(counts) == min(counts) | check-if-all-characters-have-equal-number-of-occurrences | Python, one-liner and one more | blue_sky5 | 0 | 49 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,385 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1406449/Python3-Faster-than-83-of-the-Solutions | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
counts = [0]*26
for i in s:
index = ord(i)-97
counts[index] += 1
x = set(counts)
return len(x) <= 2 | check-if-all-characters-have-equal-number-of-occurrences | Python3 - Faster than 83% of the Solutions | harshitgupta323 | 0 | 49 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,386 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1396113/Python-Solution-oror-14.1-MB-less-than-86.94-of-Python3-online-submissions | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
new = []
for i in s:
new.append(s.count(i))
return 1 == len(list(set(new))) | check-if-all-characters-have-equal-number-of-occurrences | Python Solution || 14.1 MB, less than 86.94% of Python3 online submissions | mzeli99 | 0 | 90 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,387 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1395521/python-oror-94-fast-oror-easy-oror-dictionary | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
d={}
lst=[]
for i in range (0,len(s)):
if s[i] not in d:
d[s[i]]=1
else:
d[s[i]]+=1
for value in d.values():
lst.append(value)
if len(set(lst)) >... | check-if-all-characters-have-equal-number-of-occurrences | python || 94% fast || easy || dictionary | minato_namikaze | 0 | 90 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,388 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1375260/Python3-1-line-Reduce | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
return reduce(lambda a,b : a&b, [set([val]) for val in collections.Counter(s).values()]) | check-if-all-characters-have-equal-number-of-occurrences | Python3 1-line [Reduce] | mikekaufman4 | 0 | 43 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,389 |
https://leetcode.com/problems/check-if-all-characters-have-equal-number-of-occurrences/discuss/1361043/Python-or-2-Lines-or-Counter | class Solution:
def areOccurrencesEqual(self, s: str) -> bool:
counts = list(Counter(s).values())
return all(count == counts[0] for count in counts) | check-if-all-characters-have-equal-number-of-occurrences | Python | 2 Lines | Counter | leeteatsleep | 0 | 51 | check if all characters have equal number of occurrences | 1,941 | 0.768 | Easy | 27,390 |
https://leetcode.com/problems/the-number-of-the-smallest-unoccupied-chair/discuss/1359713/Python-Simple-Heap-Solution-with-Explanation | class Solution:
def smallestChair(self, times: List[List[int]], targetFriend: int) -> int:
arrivals = []
departures = []
for ind, (x, y) in enumerate(times):
heappush(arrivals, (x, ind))
heappush(departures, (y, ind))
d = {}
occupied = [0] * len(times)... | the-number-of-the-smallest-unoccupied-chair | Python - Simple Heap Solution with Explanation | ajith6198 | 20 | 1,100 | the number of the smallest unoccupied chair | 1,942 | 0.406 | Medium | 27,391 |
https://leetcode.com/problems/the-number-of-the-smallest-unoccupied-chair/discuss/1359722/Python3-sweeping | class Solution:
def smallestChair(self, times: List[List[int]], targetFriend: int) -> int:
vals = []
for i, (arrival, leaving) in enumerate(times):
vals.append((arrival, 1, i))
vals.append((leaving, 0, i))
k = 0
pq = [] # available seats
mp... | the-number-of-the-smallest-unoccupied-chair | [Python3] sweeping | ye15 | 19 | 608 | the number of the smallest unoccupied chair | 1,942 | 0.406 | Medium | 27,392 |
https://leetcode.com/problems/the-number-of-the-smallest-unoccupied-chair/discuss/1361964/python-heapq-(Beats-100) | class Solution:
def smallestChair(self, times: List[List[int]], targetFriend: int) -> int:
n=len(times)
times=[(a,l,idx) for idx,(a,l) in enumerate(times)]
times.sort()
available=list(range(n)) #available chair no
used=[] #used chair (leaving,index)
heapify(available)... | the-number-of-the-smallest-unoccupied-chair | python heapq (Beats 100%) | ketan_raut | 1 | 92 | the number of the smallest unoccupied chair | 1,942 | 0.406 | Medium | 27,393 |
https://leetcode.com/problems/the-number-of-the-smallest-unoccupied-chair/discuss/1360890/Faster-than-100-or-python | class Solution:
def smallestChair(self, times: List[List[int]], target: int) -> int:
x,y=times[target]
n=len(times)
new=[]
for i in range(0,n):
heapq.heappush(new,i)
heap=[]
times.sort()
min_heap=[]
#print(times)
for i,j in... | the-number-of-the-smallest-unoccupied-chair | Faster than 100% | python | heisenbarg | 1 | 63 | the number of the smallest unoccupied chair | 1,942 | 0.406 | Medium | 27,394 |
https://leetcode.com/problems/the-number-of-the-smallest-unoccupied-chair/discuss/1390653/Python-3-or-Heap-Sorting-Hash-Table-or-Explanation | class Solution:
def smallestChair(self, times: List[List[int]], targetFriend: int) -> int:
n, d = len(times), dict()
heap = [i for i in range(n)]
cur = []
for i, (s, e) in enumerate(times):
cur += [(s, i), (-e, i)]
for idx, friend in sorted(cur, key=lambda x: (abs... | the-number-of-the-smallest-unoccupied-chair | Python 3 | Heap, Sorting, Hash Table | Explanation | idontknoooo | 0 | 105 | the number of the smallest unoccupied chair | 1,942 | 0.406 | Medium | 27,395 |
https://leetcode.com/problems/the-number-of-the-smallest-unoccupied-chair/discuss/1368976/Readable-solution-two-heaps | class Solution:
def smallestChair(self, times: List[List[int]], targetFriend: int) -> int:
arrivals = sorted((arrival, leave, friend) for friend, (arrival, leave)
in enumerate(times))
max_free_chair = 0
free_chairs = []
busy_chairs = []
for arrival, ... | the-number-of-the-smallest-unoccupied-chair | Readable solution, two heaps | EvgenySH | 0 | 74 | the number of the smallest unoccupied chair | 1,942 | 0.406 | Medium | 27,396 |
https://leetcode.com/problems/the-number-of-the-smallest-unoccupied-chair/discuss/1360597/Python3-two-priority-queue-solution | class Solution:
def smallestChair(self, times: List[List[int]], targetFriend: int) -> int:
#track the friend of interest since we are going to
#sort the array later
target_start, target_end = times[targetFriend]
#sort array by the time each friend arrive
times.sort(key = lambda x ... | the-number-of-the-smallest-unoccupied-chair | Python3 two priority queue solution | xxHRxx | 0 | 38 | the number of the smallest unoccupied chair | 1,942 | 0.406 | Medium | 27,397 |
https://leetcode.com/problems/describe-the-painting/discuss/1359717/Python-Easy-solution-in-O(n*logn)-with-detailed-explanation | class Solution:
def splitPainting(self, segments: List[List[int]]) -> List[List[int]]:
# via this mapping, we can easily know which coordinates should be took into consideration.
mapping = defaultdict(int)
for s, e, c in segments:
mapping[s] += c
mapping[e] -= c
... | describe-the-painting | [Python] Easy solution in O(n*logn) with detailed explanation | fishballLin | 129 | 2,000 | describe the painting | 1,943 | 0.48 | Medium | 27,398 |
https://leetcode.com/problems/describe-the-painting/discuss/1359720/Line-Sweep | class Solution:
def splitPainting(self, segments: List[List[int]]) -> List[List[int]]:
mix, res, last_i = DefaultDict(int), [], 0
for start, end, color in segments:
mix[start] += color
mix[end] -= color
for i in sorted(mix.keys()):
if last_i in mix and mix... | describe-the-painting | Line Sweep | votrubac | 67 | 3,900 | describe the painting | 1,943 | 0.48 | Medium | 27,399 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.