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/number-of-ways-to-split-array/discuss/2039264/Python-O(1)-space-Beats-100 | class Solution:
def waysToSplitArray(self, nums: List[int]) -> int:
count, left_sum, right_sum = 0, 0, sum(nums)
for i in range(len(nums)-1):
left_sum+=nums[i]
right_sum-=nums[i]
if left_sum>=right_sum:
count+=1
re... | number-of-ways-to-split-array | ✅ Python O(1) space Beats 100% | constantine786 | 0 | 12 | number of ways to split array | 2,270 | 0.446 | Medium | 31,400 |
https://leetcode.com/problems/number-of-ways-to-split-array/discuss/2038251/Python-3-Prefix-Sum-Easy-and-Clear-Solution | class Solution:
def waysToSplitArray(self, nums: List[int]) -> int:
running_sum = []
total = 0
for i, num in enumerate(nums):
total += num
running_sum.append(total)
total = sum(nums)
splits = 0
n = len(nums)
for i in range(n-1)... | number-of-ways-to-split-array | [Python 3] Prefix Sum Easy and Clear Solution | hari19041 | 0 | 89 | number of ways to split array | 2,270 | 0.446 | Medium | 31,401 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2148636/Python3-greedy | class Solution:
def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int:
tiles.sort()
ans = ii = val = 0
for i in range(len(tiles)):
hi = tiles[i][0] + carpetLen - 1
while ii < len(tiles) and tiles[ii][1] <= hi:
val += tiles[ii][1]... | maximum-white-tiles-covered-by-a-carpet | [Python3] greedy | ye15 | 1 | 105 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,402 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2061324/Python-Prefixsum-Binary-Search | class Solution:
def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int:
tiles = sorted(tiles, key = lambda x : x[0])
prefix_sum = [0]
res = 0
for idx, (start, end) in enumerate(tiles):
cur_cover = 0
prefix_sum.append(prefix_sum[-1] + (end -... | maximum-white-tiles-covered-by-a-carpet | Python, Prefixsum, Binary Search | yzhao156 | 1 | 73 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,403 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2714775/Python3-or-Self-Explanatory-Code-with-Comments-or-Sliding-Window | class Solution:
def maximumWhiteTiles(self, tiles: List[List[int]], carpetLength: int) -> int:
n=len(tiles)
tiles.sort(key=lambda x:x[0]) #sorting on starting point
i,j,whiteMarbel,ans=[0]*4
while i<n:
nextStartingPoint=tiles[i][0]+carpetLength #carpet will cover till nex... | maximum-white-tiles-covered-by-a-carpet | [Python3] | Self Explanatory Code with Comments | Sliding Window | swapnilsingh421 | 0 | 8 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,404 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2047734/java-python-sorting-and-sliding-window | class Solution:
def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int:
if carpetLen == 1 : return 1
tiles.sort()
ans = i = j = tmp = 0
while ans != carpetLen :
end = tiles[i][0] + carpetLen - 1
while j != len(tiles) and tiles[j][1] <= end:
tmp += tile... | maximum-white-tiles-covered-by-a-carpet | java, python - sorting & sliding window | ZX007java | 0 | 77 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,405 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2039156/Python-3Prefix-Sum-%2B-Two-Way-Binary-Search | class Solution:
def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int:
tiles.sort()
starts, ends = [], []
acc = [0]
for a, b in tiles:
starts.append(a)
ends.append(b)
acc.append(acc[-1] + b - a + 1)
ans = 0
... | maximum-white-tiles-covered-by-a-carpet | [Python 3]Prefix Sum + Two Way Binary Search | chestnut890123 | 0 | 52 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,406 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2038987/2-Python-Solutions | class Solution:
def maximumWhiteTiles(self, T: List[List[int]], k: int) -> int:
T.sort()
l=0 ; r=0 ; tot=0 ; ans=0
while l<len(T):
if r==l or T[r][0]+k>T[l][1]:
tot+=T[l][1]-T[l][0]+1
ans=max(ans,tot)
l+=1
else:
... | maximum-white-tiles-covered-by-a-carpet | 2 Python Solutions | Taha-C | 0 | 61 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,407 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2038987/2-Python-Solutions | class Solution:
def maximumWhiteTiles(self, T: List[List[int]], k: int) -> int:
T.sort() ; ans=0
A=list(accumulate([h-l+1 for l,h in T], initial=0))
L=[T[i][0] for i in range(len(T))]
for i in range(len(L)):
end=bisect_right(L,L[i]+k-1)
ans=max(ans,A[end]-A[i]... | maximum-white-tiles-covered-by-a-carpet | 2 Python Solutions | Taha-C | 0 | 61 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,408 |
https://leetcode.com/problems/maximum-white-tiles-covered-by-a-carpet/discuss/2038232/Python-O(len(tiles)) | class Solution:
def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int:
if not carpetLen or not tiles: return 0
def get_next(itl, lf, rt):
if itl < lf - 1:
next_itr = lf - 1
elif itl == lf - 1:
next_itr = lf
elif... | maximum-white-tiles-covered-by-a-carpet | Python O(len(tiles)) | yag313 | 0 | 66 | maximum white tiles covered by a carpet | 2,271 | 0.327 | Medium | 31,409 |
https://leetcode.com/problems/substring-with-largest-variance/discuss/2148640/Python3-pairwise-prefix-sum | class Solution:
def largestVariance(self, s: str) -> int:
ans = 0
seen = set(s)
for x in ascii_lowercase:
for y in ascii_lowercase:
if x != y and x in seen and y in seen:
vals = []
for ch in s:
i... | substring-with-largest-variance | [Python3] pairwise prefix sum | ye15 | 3 | 620 | substring with largest variance | 2,272 | 0.374 | Hard | 31,410 |
https://leetcode.com/problems/substring-with-largest-variance/discuss/2042949/Python-3-or-Kadane's-Algorithm-Two-Pointers-or-Explanation | class Solution:
def largestVariance(self, s: str) -> int:
d = collections.defaultdict(list)
for i, c in enumerate(s): # for each letter, create a list of its indices
d[c].append(i)
ans = 0
for x, chr1 in enumerate(string.ascii_lowerca... | substring-with-largest-variance | Python 3 | Kadane's Algorithm, Two Pointers | Explanation | idontknoooo | 3 | 1,100 | substring with largest variance | 2,272 | 0.374 | Hard | 31,411 |
https://leetcode.com/problems/substring-with-largest-variance/discuss/2786797/Python3-%2B-Explanation | class Solution:
def largestVariance(self, s: str) -> int:
# This is similar to the Kadane's algorithm, see problem 53 before attempting this one
# Here we take every permutation of 2 characters in a string and then apply Kadane algo to it
# Say string is 'abcdab'
# From the perspecti... | substring-with-largest-variance | Python3 + Explanation | rasnouk | 1 | 56 | substring with largest variance | 2,272 | 0.374 | Hard | 31,412 |
https://leetcode.com/problems/substring-with-largest-variance/discuss/2044294/Python-Kadane's-Algorithm-Simple-Solution | class Solution:
def largestVariance(self, s: str) -> int:
counter = Counter(s)
res = 0
for a, b in permutations(counter, 2):
count_a, count_b = 0, 0
remain_b = counter[b]
for ch in s:
if ch not in {a, b}:
contin... | substring-with-largest-variance | [Python] Kadane's Algorithm, Simple Solution | feifei2016 | 0 | 488 | substring with largest variance | 2,272 | 0.374 | Hard | 31,413 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2039752/Weird-Description | class Solution:
def removeAnagrams(self, w: List[str]) -> List[str]:
return [next(g) for _, g in groupby(w, sorted)] | find-resultant-array-after-removing-anagrams | Weird Description | votrubac | 39 | 2,900 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,414 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2039752/Weird-Description | class Solution:
def removeAnagrams(self, w: List[str]) -> List[str]:
return [w[i] for i in range(0, len(w)) if i == 0 or sorted(w[i]) != sorted(w[i - 1])] | find-resultant-array-after-removing-anagrams | Weird Description | votrubac | 39 | 2,900 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,415 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2039900/Python-3-or-Intuitive-%2B-How-to-approach-or-O(n)-without-sorting | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
res = []
anagrams = {}
for i in range(len(words)):
word = words[i]
counter = [0]*26
for c in word:
counter[ord(c)-ord('a')] += 1
if tuple(counter) not in anagrams:
res.append(word)
else... | find-resultant-array-after-removing-anagrams | Python 3 | Intuitive + How to approach | O(n) without sorting | ndus | 11 | 719 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,416 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2039900/Python-3-or-Intuitive-%2B-How-to-approach-or-O(n)-without-sorting | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
res = []
prev = []
for i in range(len(words)):
word = words[i]
counter = [0]*26
for c in word:
counter[ord(c)-ord('a')] += 1
if counter != prev:
res.append(word)
prev = counter
re... | find-resultant-array-after-removing-anagrams | Python 3 | Intuitive + How to approach | O(n) without sorting | ndus | 11 | 719 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,417 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2056341/python-small-and-easy-to-understand-solution | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
key = ""
result = []
for word in words:
letters = list(word)
letters.sort()
new_key = "".join(letters)
if new_key != key :
key = new_key
result.append(word)
return resu... | find-resultant-array-after-removing-anagrams | python - small & easy to understand solution | ZX007java | 3 | 255 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,418 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2056341/python-small-and-easy-to-understand-solution | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
def sort_construct(word):
letters = list(word)
letters.sort()
return "".join(letters)
key = sort_construct(words[0])
result = [words[0]]
for i in range(1, len(words)):
new_key = sort_construct(wo... | find-resultant-array-after-removing-anagrams | python - small & easy to understand solution | ZX007java | 3 | 255 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,419 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2040051/Python-Easy-Solution-with-Comments | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
if len(words) == 1:
return words
i = 1
while i < len(words):
anagram = "".join(sorted(words[i]))
# check if words[i-1] and words[i] are anagrams
if anagram == "".join(sort... | find-resultant-array-after-removing-anagrams | Python Easy Solution with Comments | MiKueen | 2 | 86 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,420 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2751510/Python-counter-oror-Solution | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
res=[words[0]]
for i in range(1,len(words)):
mp1,mp2=Counter(words[i-1]),Counter(words[i])
if mp1!=mp2:
res.append(words[i])
return res
#misread easy to medium
# s=[]... | find-resultant-array-after-removing-anagrams | Python counter || Solution | cheems_ds_side | 1 | 98 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,421 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2451358/Python%3A-Faster-than-upto-97-quick-hashmaplist-answer | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
#automatically get first word
hashMap ={0: words[0]}
for i in range(1,len(words)):
notAnagram = words[i]
#sort words in alphabetical order
#if not the same add to hashMap
... | find-resultant-array-after-removing-anagrams | Python: Faster than upto 97% quick hashmap/list answer | BasedBrenden | 1 | 95 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,422 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2345429/Python-or-5-lines | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
res = [words[0]]
for i in range(len(words)):
#check anagram
if sorted(words[i-1])!=sorted(words[i]):
res.append(words[i])
return res | find-resultant-array-after-removing-anagrams | Python | 5 lines | ana_2kacer | 1 | 100 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,423 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2054810/4-lines-solution-with-Counter | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
# `Counter` makes a letter frequency dictionary
# the == operator compares the two dictionaries
# if anagrams then delete the next word
# otherwise, we increment the pointer
pointer = 0
while pointer < ... | find-resultant-array-after-removing-anagrams | 4 lines solution with Counter | fhhh09 | 1 | 31 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,424 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2848766/Counter-and-Stack-Easy-Python3 | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
from collections import Counter
previous_c = Counter(words[0])
stack = [words[0]]
for i in range(1, len(words)):
current_c = Counter(words[i])
if current_c == previous_c:
... | find-resultant-array-after-removing-anagrams | Counter and Stack Easy Python3 | ben_wei | 0 | 1 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,425 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2733306/An-Optimized-Python-Sorting-Solution | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
prevAna, result = sorted(words[0]), [words[0]]
for word in words[1:]:
currAna = sorted(word)
if currAna != prevAna:
prevAna = currAna
result.append(word)
... | find-resultant-array-after-removing-anagrams | An Optimized Python Sorting Solution | kcstar | 0 | 1 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,426 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2714250/Literally-do-the-operation-in-description. | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
"""
Literally do the operation in description.
TC: O(n), SC: O(1)
"""
i = 1
while i < len(words):
if sorted(words[i-1]) == sorted(words[i]):
words.pop(i)
... | find-resultant-array-after-removing-anagrams | Literally do the operation in description. | woora3 | 0 | 1 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,427 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2697533/Simple-Python-Solution-or-Sorting | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
start=0
while start<len(words)-1:
curr=list(words[start])
nxt=list(words[start+1])
curr.sort()
nxt.sort()
if nxt==curr:
words.pop(start+1)
... | find-resultant-array-after-removing-anagrams | Simple Python Solution | Sorting | Siddharth_singh | 0 | 2 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,428 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2675799/Simple-Python-Solution | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
frequency = dict()
result = []
for word in words:
frequency[word] = Counter(word)
w1 = words[0]
result.append(w1)
for i in range(1, len(words)):
... | find-resultant-array-after-removing-anagrams | Simple Python Solution | mansoorafzal | 0 | 23 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,429 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2649571/Python3-Just-Use-Counter | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
w = list(zip(words, [Counter(i) for i in words]))
found = True
while found:
found = False
for i in range(1,len(w)):
if w[i][1] == w[i-1][1]:
del w[i]
... | find-resultant-array-after-removing-anagrams | Python3 Just Use Counter | godshiva | 0 | 8 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,430 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2572068/3-Python-solutions....Easy-to-understand | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
i=1
while i<len(words):
if (''.join(sorted(words[i])))==(''.join(sorted(words[i-1]))):
words.remove(words[i])
else:
i+=1
return words | find-resultant-array-after-removing-anagrams | 3 Python solutions....Easy to understand | guneet100 | 0 | 43 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,431 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2572068/3-Python-solutions....Easy-to-understand | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
i=1
while i<len(words):
if sorted(words[i])==sorted(words[i-1]):
words.remove(words[i])
else:
i+=1
return words | find-resultant-array-after-removing-anagrams | 3 Python solutions....Easy to understand | guneet100 | 0 | 43 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,432 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2572068/3-Python-solutions....Easy-to-understand | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
i=1
while i<len(words):
if Counter(words[i])==Counter(words[i-1]):
words.remove(words[i])
else:
i+=1
return words | find-resultant-array-after-removing-anagrams | 3 Python solutions....Easy to understand | guneet100 | 0 | 43 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,433 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2385060/Faster-than-90-easy-to-understand-Time-Complexity-O(n) | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
n = len(words)
ans = []
j = 0
for i in range(n):
if ("".join(sorted(words[i])) != "".join(sorted(words[j]))) or i == n-1 :
ans.append(words[j])
j = i
... | find-resultant-array-after-removing-anagrams | Faster than 90%, easy to understand, Time Complexity O(n) | Virus_003 | 0 | 71 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,434 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2156510/bottom-up-solution | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
# iterate from the bottom up
# keep track of the most recent anagram (start from last word)
# create a helper function that indicates True/False if words are anagrams
# iterate from the second to last word down ... | find-resultant-array-after-removing-anagrams | bottom up solution | andrewnerdimo | 0 | 28 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,435 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2042592/Python-3-or-Easy-to-understand-%2B-short-answer-or-Using-Sorting | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
result=[]
result.append(words[0])
for i in words:
if sorted(i)!=sorted(result[-1]):
result.append(i)
return result | find-resultant-array-after-removing-anagrams | Python 3 | Easy to understand + short answer | Using Sorting | Sasuke_U | 0 | 37 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,436 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2040849/Python3-using-recursive | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
def check(words, anagram):
if not anagram:
return words
else:
for i in range(len(words)):
if i + 1 < len(words):
c1 = Counter(words[i]); c2 = Counter(words[i + 1])
if c1 == c2:
words.pop(i + 1)
retur... | find-resultant-array-after-removing-anagrams | [Python3] using recursive | Shiyinq | 0 | 13 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,437 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2040183/Python-Simple-O(n)-solution-Beats-~95 | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
prev = Counter('0')
res = []
for word in words:
hashed = Counter(word)
if prev != hashed:
res.append(word)
prev=hashed
return ... | find-resultant-array-after-removing-anagrams | ✅ Python Simple O(n) solution - Beats ~95% | constantine786 | 0 | 31 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,438 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2040093/Python-or-Simple-Solution-with-sorting | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
ans = []
group = {}
cur = 0
for ind, word in enumerate(words):
cur = ind
tmp = ''.join(sorted(word))
if tmp in group and group[tmp] == cur - 1:
... | find-resultant-array-after-removing-anagrams | Python | Simple Solution with sorting | blazers08 | 0 | 16 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,439 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2040076/Python3-1-line | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
return [w for i, w in enumerate(words) if i == 0 or sorted(words[i-1]) != sorted(w)] | find-resultant-array-after-removing-anagrams | [Python3] 1-line | ye15 | 0 | 15 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,440 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2040076/Python3-1-line | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
return [w for i, w in enumerate(words) if i == 0 or Counter(words[i-1]) != Counter(w)] | find-resultant-array-after-removing-anagrams | [Python3] 1-line | ye15 | 0 | 15 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,441 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2040050/Python-Solution-Using-Stack-oror-O(n) | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
st=[]
for i in range(len(words)):
if not st:
st.append(words[i])
elif st and sorted(st[-1])==sorted(words[i]):
pass
else:
st.append(words[i])
... | find-resultant-array-after-removing-anagrams | Python Solution Using Stack || O(n) | a_dityamishra | 0 | 19 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,442 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2039989/Python-using-Counter | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
result = [words[0]]
for i in range(1, len(words)):
if Counter(words[i]) != Counter(result[-1]):
result.append(words[i])
return result | find-resultant-array-after-removing-anagrams | Python, using Counter | blue_sky5 | 0 | 34 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,443 |
https://leetcode.com/problems/find-resultant-array-after-removing-anagrams/discuss/2039881/Python-Counter | class Solution:
def removeAnagrams(self, words: List[str]) -> List[str]:
new = [words[0]]
for i in range(1, len(words)):
if Counter(words[i - 1]) == Counter(words[i]):
continue
else:
new.append(words[i])
return new | find-resultant-array-after-removing-anagrams | Python - Counter | GigaMoksh | 0 | 20 | find resultant array after removing anagrams | 2,273 | 0.583 | Easy | 31,444 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2039754/Python-Simulation-Just-sort-the-array-special | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: list[int]) -> int:
special.sort()
res = special[0] - bottom
for i in range(1, len(special)):
res = max(res, special[i] - special[i - 1] - 1)
return max(res, top - special[-1]) | maximum-consecutive-floors-without-special-floors | Python Simulation - Just sort the array special | GigaMoksh | 7 | 326 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,445 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2039808/Python-Simple-Solution-or-Single-Iteration-or-Optimized-solution-or-Difference-between-floors | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
c = 0
special.sort()
c = special[0]-bottom
bottom = special[0]
for i in range(1,len(special)):
if special[i]-bottom>1:
c = max(c,special[i]-bottom-1)
... | maximum-consecutive-floors-without-special-floors | Python Simple Solution | Single Iteration | Optimized solution | Difference between floors | AkashHooda | 2 | 91 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,446 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2098273/JAVA-oror-PYTHON-oror-100-oror-EASY | class Solution:
def maxConsecutive(self, x: int, y: int, a: List[int]) -> int:
a.sort()
r=max(a[0]-x,y-a[-1])
for i in range(len(a)-1):
a[i]=a[i+1]-a[i]
a[-1]=0
r=max(max(a)-1,r)
return r | maximum-consecutive-floors-without-special-floors | ✔️JAVA || PYTHON ||✔️ 100% || EASY | karan_8082 | 1 | 66 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,447 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2040148/Python-Simple-Solution-Beats-~95-(with-explanation) | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
special.sort()
special_floors=[bottom-1] + special + [top+1]
res = 0
for i in range(1, len(special_floors)):
res = max(res, special_floors[i] - special_floors[i-1... | maximum-consecutive-floors-without-special-floors | Python Simple Solution Beats ~95% (with explanation) | constantine786 | 1 | 111 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,448 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2040058/Python-Solution-oror-Easy-To-Understand | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
c=0
l=[]
special.sort()
a=special[0]-bottom
b=top-special[-1]
for i in range(len(special)-1):
l.append(special[i+1]-special[i]-1)
if len(l)>=1:
... | maximum-consecutive-floors-without-special-floors | Python Solution || Easy To Understand | a_dityamishra | 1 | 25 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,449 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2317468/Python3-Using-Sort | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
"""
# TLE
special.sort()
spec = 0
seq = max_seq = 0
for floor in range(bottom, top+1):
if spec < len(special) and floor == special[spec]:
max_seq = ... | maximum-consecutive-floors-without-special-floors | [Python3] Using Sort | Gp05 | 0 | 9 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,450 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2289973/Python3-Sorting-approach | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
special.sort()
max_count = special[0] - bottom
for idx in range(1, len(special)):
max_count = max(max_count, special[idx] - special[idx-1] - 1)
max_count = max(max_count, (top - sp... | maximum-consecutive-floors-without-special-floors | Python3 Sorting approach | yashchandani98 | 0 | 11 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,451 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2059681/python-java-sort-%3A-small-and-easy-to-understand | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
special.sort()
answer = special[0] - bottom + 1
for floor in special :
answer = max(answer, floor - bottom)
bottom = floor
return max(answer, top - special[-1] + 1) - 1 | maximum-consecutive-floors-without-special-floors | python, java - sort : small & easy to understand | ZX007java | 0 | 37 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,452 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2044776/Sort-zip-max-85-speed | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
if len(special) == 1:
return max(special[0] - bottom, top - special[0])
special.sort()
return (max(max(b - a for a, b in zip(special, special[1:])) - 1,
special[0] - bo... | maximum-consecutive-floors-without-special-floors | Sort, zip, max, 85% speed | EvgenySH | 0 | 16 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,453 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2041138/python-oror-sorting-oror-Easy-oror-Comments | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
maxi=0
# consider the lowermost possible values
special.sort()
a=special[0]-bottom
# consider the uppermost possible values
b=top-special[-1]
# when both the specials floor l... | maximum-consecutive-floors-without-special-floors | python || sorting || Easy || Comments | Aniket_liar07 | 0 | 8 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,454 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2040688/Python-oror-Sort-the-array | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
mx=0
special=sorted(special)
for i in range(1,len(special)):
mx=max(special[i]-special[i-1],mx)
return max(mx-1,special[0]-bottom,top-special[-1]) | maximum-consecutive-floors-without-special-floors | Python || Sort the array | aditya1292 | 0 | 15 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,455 |
https://leetcode.com/problems/maximum-consecutive-floors-without-special-floors/discuss/2040100/Python3-2-line | class Solution:
def maxConsecutive(self, bottom: int, top: int, special: List[int]) -> int:
aug = [bottom-1] + sorted(special) + [top+1]
return max(aug[i]-aug[i-1]-1 for i in range(1, len(aug))) | maximum-consecutive-floors-without-special-floors | [Python3] 2-line | ye15 | 0 | 14 | maximum consecutive floors without special floors | 2,274 | 0.521 | Medium | 31,456 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2039717/Check-Each-Bit | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
return max(sum(n & (1 << i) > 0 for n in candidates) for i in range(0, 24)) | largest-combination-with-bitwise-and-greater-than-zero | Check Each Bit | votrubac | 55 | 3,600 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,457 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2039741/Python-Count-the-Number-of-Ones-at-Each-Bit-Clean-and-Concise | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
s = [0 for _ in range(30)]
for c in candidates:
b = bin(c)[2:][::-1]
for i, d in enumerate(b):
if d == '1':
s[i] += 1
return max(s) | largest-combination-with-bitwise-and-greater-than-zero | [Python] Count the Number of Ones at Each Bit, Clean & Concise | xil899 | 2 | 109 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,458 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2040092/Python-Check-Each-Bit-O(30*N) | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
arr = [0]*32
for c in candidates:
for i in range(0, 30):
if c & (1<<i) :
arr[i] += 1
return max(arr) | largest-combination-with-bitwise-and-greater-than-zero | [Python] Check Each Bit O(30*N) | akwal | 1 | 33 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,459 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2039878/Python-Efficient-Solution-or-O(30*N)-solution-or-Easy-to-understand | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
d = {}
for i in range(32):
d[i] = 0
for a in candidates:
x = bin(a)[2:][::-1]
for j in range(len(x)):
if x[j]=='1':
d[j]+=1
return max(... | largest-combination-with-bitwise-and-greater-than-zero | Python Efficient Solution | O(30*N) solution | Easy to understand | AkashHooda | 1 | 47 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,460 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2788458/Python3-or-Bit-manipulation | class Solution:
def largestCombination(self, A: List[int]) -> int:
n = len(A)
ans= 0
for i in range(32):
maxCol = 0
for j in range(n):
if (A[j]>>i) & 1 == 1:
maxCol += 1
ans = max(ans,maxCol)
return ans | largest-combination-with-bitwise-and-greater-than-zero | [Python3] | Bit - manipulation | swapnilsingh421 | 0 | 8 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,461 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2087933/Python3-or-Simple-Approach | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
ans = 0
for i in range(0,32):
temp = 0
for candidate in candidates:
temp += ((1<<i)&(candidate))>>i
ans = max(temp, ans)
return ans | largest-combination-with-bitwise-and-greater-than-zero | Python3 | Simple Approach | goyaljatin9856 | 0 | 61 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,462 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2069487/java-c%2B%2B-python-bit-manipulation | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
bits = [0]*32
for x in candidates :
i = 0
while x != 0 :
bits[i] += x&1
i +=1
x >>= 1
ans = 0
for b in bits : ans = max(ans, b)
return ans | largest-combination-with-bitwise-and-greater-than-zero | java, c++, python - bit manipulation | ZX007java | 0 | 84 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,463 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2045623/Binary-string-of-each-number-100-speed | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
bit_counts = [0] * 24
for n in candidates:
for i, digit in enumerate(bin(n)[2:][::-1]):
if digit == "1":
bit_counts[i] += 1
return max(bit_counts) | largest-combination-with-bitwise-and-greater-than-zero | Binary string of each number, 100% speed | EvgenySH | 0 | 24 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,464 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2043970/bitwise-oror-python-oror-bit-masking-oror-easy | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
res=0
# Logic is simple and operation is !=0 only when all the ith bit of a no. is set for each candidates
for i in range(32):
count=0
# create mask at ith bit
mask=1<<i
... | largest-combination-with-bitwise-and-greater-than-zero | bitwise || python || bit-masking || easy | Aniket_liar07 | 0 | 8 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,465 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2040115/Python3-1-line | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
return max(sum(bool(x & 1<<i) for x in candidates) for i in range(24)) | largest-combination-with-bitwise-and-greater-than-zero | [Python3] 1-line | ye15 | 0 | 11 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,466 |
https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/2039860/Python3-Easy-to-understand-Explained | class Solution:
def largestCombination(self, candidates: List[int]) -> int:
lst, n = [], len(str(bin(max(candidates)))[2:])
for x in candidates:
lst.append(str(bin(x))[2:].zfill(n))
counter = Counter()
for x in lst:
for i, y in enumerate(x):
i... | largest-combination-with-bitwise-and-greater-than-zero | Python3 - Easy to understand - Explained | WoodlandXander | 0 | 40 | largest combination with bitwise and greater than zero | 2,275 | 0.724 | Medium | 31,467 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2061930/Simple-Python-Solution-or-Easy-to-Understand-or-Two-Liner-Solution-or-O(N)-Solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
a = s.count(letter)
return (a*100)//len(s) | percentage-of-letter-in-string | Simple Python Solution | Easy to Understand | Two Liner Solution | O(N) Solution | AkashHooda | 2 | 63 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,468 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2710506/Python-ororO(N)-Runtime-50-ms-Beats-56.36-Memory-13.9-MB-Beats-10.66 | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
c=0
for i in s:
if i==letter:
c+=1
n=len(s)
return int(c/n*100) | percentage-of-letter-in-string | [Python ||O(N)] Runtime 50 ms Beats 56.36% Memory 13.9 MB Beats 10.66% | Sneh713 | 1 | 47 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,469 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2061914/Python-Easy-Solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
cnt = 0
for char in s:
if char == letter:
cnt += 1
res = math.floor((cnt / len(s)) * 100)
return res | percentage-of-letter-in-string | Python Easy Solution | MiKueen | 1 | 40 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,470 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2848335/Python-1-liner-beats-99.91 | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return int(s.count(letter)*100/len(s)) | percentage-of-letter-in-string | Python 1 liner, beats 99.91% | Spex924 | 0 | 2 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,471 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2811204/Python-Solution-EASY-oror-EASY-TO-UNDERSTAND | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
c=0
for i in s:
if i==letter:
c+=1
a=(c/len(s))*100
return int(a) | percentage-of-letter-in-string | Python Solution - EASY || EASY TO UNDERSTAND | T1n1_B0x1 | 0 | 6 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,472 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2771174/Python-or-LeetCode-or-2278.-Percentage-of-Letter-in-String | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
x = 0
for i in s:
if i == letter:
x += 1
return (100 * x) // len(s) | percentage-of-letter-in-string | Python | LeetCode | 2278. Percentage of Letter in String | UzbekDasturchisiman | 0 | 5 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,473 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2771174/Python-or-LeetCode-or-2278.-Percentage-of-Letter-in-String | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return (100 * s.count(letter)) // len(s) | percentage-of-letter-in-string | Python | LeetCode | 2278. Percentage of Letter in String | UzbekDasturchisiman | 0 | 5 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,474 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2711068/100-EASY-TO-UNDERSTANDSIMPLECLEAN | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
count = 0
for c in s:
if c == letter:
count += 1
return int(count/len(s)*100) | percentage-of-letter-in-string | 🔥100% EASY TO UNDERSTAND/SIMPLE/CLEAN🔥 | YuviGill | 0 | 5 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,475 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2553429/Python-Simple-Python-Solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
frequency_count = s.count(letter)
result = (frequency_count * 100) // len(s)
return result | percentage-of-letter-in-string | [ Python ] ✅✅ Simple Python Solution 🥳✌👍 | ASHOK_KUMAR_MEGHVANSHI | 0 | 10 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,476 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2519134/Simple-Python-solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
n = len(s)
count = 0
for i in s:
if i == letter:
count += 1
return floor((count/n)*100) | percentage-of-letter-in-string | Simple Python solution | aruj900 | 0 | 18 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,477 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2507980/Python3-Easy-One-liner-str.count()-method-%2B-division | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return 100 * s.count(letter) // len(s) | percentage-of-letter-in-string | [Python3] Easy One-liner str.count() method + // division | ivnvalex | 0 | 9 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,478 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2451450/Python-simple-solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return round((s.count(letter) / len(s)) * 100) | percentage-of-letter-in-string | Python simple solution | VoidCupboard | 0 | 15 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,479 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2360497/29-ms-faster-than-95.49 | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return int(s.count(letter)/len(s)*100) | percentage-of-letter-in-string | 29 ms, faster than 95.49% | siktorovich | 0 | 21 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,480 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2165103/Percentage-of-Letter-in-String-or-Python-One-Line-or-Easy-way | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return int(Counter(s)[letter] / len(s) * 100) | percentage-of-letter-in-string | Percentage of Letter in String | Python One-Line | Easy way | YangJenHao | 0 | 15 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,481 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2152532/Python-or-Simple-and-clean-solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
count = 0
n = len(s)
for c in s:
if c == letter:
count += 1
# print(count,n)
return int((count / n) * 100) | percentage-of-letter-in-string | Python | Simple and clean solution | __Asrar | 0 | 39 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,482 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2135380/Python-oror-Straight-Forward | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
count = 0
for l in s:
if l == letter: count += 1
ans = (count / len(s))*100
return int(ans) | percentage-of-letter-in-string | Python || Straight Forward | morpheusdurden | 0 | 24 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,483 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2116183/Python-Easy-to-understand-Solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
m = s.count(letter)
n = len(s)
x = int(100 * m / n)
return x | percentage-of-letter-in-string | ✅Python Easy-to-understand Solution | chuhonghao01 | 0 | 14 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,484 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2094854/Python-one-liner-faster-than-95 | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return int((s.count(letter) / len(s)) * 100) | percentage-of-letter-in-string | Python one liner faster than 95% | alishak1999 | 0 | 21 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,485 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2089121/Python-Easy-solution-with-complexities | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
count = 0
for i in s:
if i == letter:
count = count + 1
answer = ( count / len (s) ) * 100
return int(answer)
# time O(N)
# space O(1) | percentage-of-letter-in-string | [Python] Easy solution with complexities | mananiac | 0 | 19 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,486 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2076313/Python-oneliner | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
from math import floor
return floor(s.count(letter)/len(s)*100) | percentage-of-letter-in-string | Python oneliner | StikS32 | 0 | 17 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,487 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2070620/Python-One-Line | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return s.count(letter) * 100 // len(s) | percentage-of-letter-in-string | Python One Line | Hejita | 0 | 28 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,488 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2068286/Python3-1-line | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
return 100*s.count(letter)//len(s) | percentage-of-letter-in-string | [Python3] 1-line | ye15 | 0 | 10 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,489 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2065988/java-python-counter | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
counter = 0
for i in range(len(s)):
if s[i] == letter : counter += 1
return counter*100//len(s) | percentage-of-letter-in-string | java, python - counter | ZX007java | 0 | 24 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,490 |
https://leetcode.com/problems/percentage-of-letter-in-string/discuss/2062470/Simple-Python-Solution | class Solution:
def percentageLetter(self, s: str, letter: str) -> int:
c=0
for i in letter:
if i in s:
c+=s.count(i)
return c*100//len(s) | percentage-of-letter-in-string | Simple Python Solution | a_dityamishra | 0 | 12 | percentage of letter in string | 2,278 | 0.741 | Easy | 31,491 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2062186/Python-Easy-Solution | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
remaining = [0] * len(capacity)
res = 0
for i in range(len(capacity)):
remaining[i] = capacity[i] - rocks[i]
remaining.sort()
for i in rang... | maximum-bags-with-full-capacity-of-rocks | Python Easy Solution | MiKueen | 1 | 28 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,492 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2061885/Python-Simple-Solution-or-Easy-to-Understand-or-O(NLogN) | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
l = []
c = 0
for i in range(len(capacity)):
if capacity[i]-rocks[i]:
l.append(capacity[i]-rocks[i])
else:
c+=1
l.sort()
... | maximum-bags-with-full-capacity-of-rocks | Python Simple Solution | Easy to Understand | O(NLogN) | AkashHooda | 1 | 50 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,493 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2061860/Python-or-Sort-on-basis-of-difference | class Solution:
def maximumBags(self, c: List[int], r: List[int], a: int) -> int:
n = len(c)
new = [[c[i], r[i]] for i in range(n)]
new.sort(key=lambda x: x[0] - x[1])
count = 0
for i in range(n):
if new[i][0] > new[i][1]:
x = new[i][0] -... | maximum-bags-with-full-capacity-of-rocks | Python | Sort on basis of difference | GigaMoksh | 1 | 9 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,494 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2824614/Python-greedy-solution | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
empty = []
for i in range(len(rocks)):
empty.append(capacity[i]-rocks[i])
empty.sort()
bags = 0
for i in range(len(em... | maximum-bags-with-full-capacity-of-rocks | Python greedy solution | ankurkumarpankaj | 0 | 1 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,495 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2806309/Understanding-Solution-(Python3) | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
n = len(capacity)
if len(capacity) == len(rocks) :
arr = {}
for i in range(n):
arr[i] = capacity[i]-rocks[i]
arr = sorted(arr.values())
... | maximum-bags-with-full-capacity-of-rocks | Understanding Solution (Python3) | Kasun98 | 0 | 1 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,496 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2688359/Python-or-Greedy-%2B-Min-heap-or-Beats-95 | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additional_rocks: int) -> int:
rocks_needed = [c - r for c, r in zip(capacity, rocks)]
heapq.heapify(rocks_needed)
bags = 0
while rocks_needed:
r = heapq.heappop(rocks_needed)
if add... | maximum-bags-with-full-capacity-of-rocks | Python | Greedy + Min-heap | Beats 95% | on_danse_encore_on_rit_encore | 0 | 4 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,497 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2248139/Python-oror-Easy-Solution | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
difflist = []
fullcapacity = 0
for i in range(0,len(rocks)):
difflist.append(capacity[i] - rocks[i])
difflist.sort()
for i in range(len(difflist)):
... | maximum-bags-with-full-capacity-of-rocks | Python || Easy Solution | dyforge | 0 | 15 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,498 |
https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/discuss/2221329/Intuitive-Approach-and-Solution | class Solution:
def maximumBags(self, capacity: List[int], rocks: List[int], additionalRocks: int) -> int:
n = len(capacity)
maximumBags = 0
for i in range(n):
if capacity[i] - rocks[i] == 0:
maximumBags += 1
difference = sorted([capacity[i] - roc... | maximum-bags-with-full-capacity-of-rocks | Intuitive Approach and Solution | Vaibhav7860 | 0 | 7 | maximum bags with full capacity of rocks | 2,279 | 0.626 | Medium | 31,499 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.