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/check-if-all-the-integers-in-a-range-are-covered/discuss/1851546/3-Lines-Python-Solution-oror-80-Faster-(44ms)oror-Memory-less-than-60 | class Solution:
def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool:
for nbr in [i for i in range(left,right+1,1)]:
if not any([True for r in ranges if r[0]<=nbr<=r[1]]): return False
return True | check-if-all-the-integers-in-a-range-are-covered | 3-Lines Python Solution || 80% Faster (44ms)|| Memory less than 60% | Taha-C | 0 | 63 | check if all the integers in a range are covered | 1,893 | 0.508 | Easy | 26,800 |
https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered/discuss/1725186/WEEB-EXPLAINS-PYTHON-(SIMPLE-SOLUTION) | class Solution:
def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool:
ranges.sort() # we don't sort, we will miss out some intermediate numbers
for i in range(len(ranges)):
if ranges[i][0] <= left <= ranges[i][1]: # if left within the current interval
left = ranges[i][1] + 1 # set th... | check-if-all-the-integers-in-a-range-are-covered | WEEB EXPLAINS PYTHON (SIMPLE SOLUTION) | Skywalker5423 | 0 | 73 | check if all the integers in a range are covered | 1,893 | 0.508 | Easy | 26,801 |
https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered/discuss/1426455/Python3-Prefix-Array-For-Visited-Elements-Faster-Than-89.47-Memory-Less-Than-99.58 | class Solution:
def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool:
mn, mx = 99999, 0
for i in ranges:
mn, mx = min(mn, i[0]), max(mx, i[1])
if mn > left or mx < right:
return False
prefix = [0] * (mx + 2)
for i in ... | check-if-all-the-integers-in-a-range-are-covered | Python3 Prefix Array For Visited Elements, Faster Than 89.47%, Memory Less Than 99.58% | Hejita | 0 | 93 | check if all the integers in a range are covered | 1,893 | 0.508 | Easy | 26,802 |
https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered/discuss/1316235/Simple-Python3-O(n)-solution-using-dp | class Solution:
def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool:
li=[0]*52
for x,y in ranges:
li[x]+=1
li[y+1]-=1
for i in range(1,52):
li[i]+=li[i-1]
for i in range(left,right+1):
if li[i]<=0:
... | check-if-all-the-integers-in-a-range-are-covered | Simple Python3 O(n) solution using dp | atm1504 | 0 | 62 | check if all the integers in a range are covered | 1,893 | 0.508 | Easy | 26,803 |
https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered/discuss/1269136/easy-to-understand-python3 | class Solution:
def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool:
ranges.sort()
rop=[False]*((right-left)+1)
k=-1
for i in range(left,right+1):
k+=1
for j in range(len(ranges)):
if ranges[j][0]<=i<=ranges[j][1]:
... | check-if-all-the-integers-in-a-range-are-covered | easy to understand python3 | janhaviborde23 | 0 | 81 | check if all the integers in a range are covered | 1,893 | 0.508 | Easy | 26,804 |
https://leetcode.com/problems/check-if-all-the-integers-in-a-range-are-covered/discuss/1268159/Python-Easy-solution-using-Set | class Solution:
def isCovered(self, ranges: List[List[int]], left: int, right: int) -> bool:
seen = set()
for interval in ranges:
start = interval[0]
end = interval[1]
# adds all numbers in range to the seen numbers
f... | check-if-all-the-integers-in-a-range-are-covered | Python, Easy solution using Set | ayrleetcoder | 0 | 74 | check if all the integers in a range are covered | 1,893 | 0.508 | Easy | 26,805 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1612394/Python-oror-Prefix-Sum-and-Binary-Search-oror-O(n)-time-O(n)-space | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
prefix_sum = [0 for i in range(len(chalk))]
prefix_sum[0] = chalk[0]
for i in range(1,len(chalk)):
prefix_sum[i] = prefix_sum[i-1] + chalk[i]
remainder = k % prefix_sum[-1]
#apply b... | find-the-student-that-will-replace-the-chalk | Python || Prefix Sum and Binary Search || O(n) time O(n) space | s_m_d_29 | 4 | 244 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,806 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1267418/Python-or-simple-O(N) | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
x = sum(chalk)
if x<k:
k = k%x
if x == k:
return 0
i = 0
n = len(chalk)
while True:
if chalk[i]<=k:
k -= chalk[i]
else:
... | find-the-student-that-will-replace-the-chalk | Python | simple O(N) | harshhx | 4 | 248 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,807 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1439073/Python-3-or-O(N)-or-Explanation | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
k %= sum(chalk)
for i, num in enumerate(chalk):
if k >= num: k -= num
else: return i
return -1 | find-the-student-that-will-replace-the-chalk | Python 3 | O(N) | Explanation | idontknoooo | 3 | 138 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,808 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/2131735/C%2B%2B-and-Python-solution%3A-Single-pass-and-Binary-search | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
return bisect.bisect(list(accumulate(chalk)), k % sum(A)) | find-the-student-that-will-replace-the-chalk | C++ and Python solution: Single pass and Binary search | deleted_user | 1 | 23 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,809 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/2131735/C%2B%2B-and-Python-solution%3A-Single-pass-and-Binary-search | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
k %= sum(chalk)
for i, ck in enumerate(chalk):
if k < ck:
return i
k -= ck
return 0 | find-the-student-that-will-replace-the-chalk | C++ and Python solution: Single pass and Binary search | deleted_user | 1 | 23 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,810 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1267594/Python3-O(n)-Solution | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
sumi = sum(chalk)
k = k % sumi
for i , j in enumerate(chalk):
if(k < j): break
k -= j
return i | find-the-student-that-will-replace-the-chalk | [Python3] O(n) Solution | VoidCupboard | 1 | 21 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,811 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1267388/Python3-remainder | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
k %= sum(chalk)
for i, x in enumerate(chalk):
k -= x
if k < 0: return i | find-the-student-that-will-replace-the-chalk | [Python3] remainder | ye15 | 1 | 26 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,812 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/2764771/Python-3-or-Easy-3-line-solution-or-O(N)-O(1)-or-Modulus | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
k=k%sum(chalk)
for i in range(len(chalk)):
if k<chalk[i]:return i
else: k-=chalk[i] | find-the-student-that-will-replace-the-chalk | Python 3 | Easy 3 line solution | O(N), O(1) | Modulus | saa_73 | 0 | 4 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,813 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/2686506/Super-Easy-Python-Solution | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
s = sum(chalk)
k %= s
n = len(chalk)
for i in range(n):
if chalk[i]>k:
return i
k -= chalk[i] | find-the-student-that-will-replace-the-chalk | Super Easy Python Solution | RajatGanguly | 0 | 3 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,814 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/2107403/Python-3-solution-with-binary-search-and-prefix-sum-technique | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
prefix_sum = [chalk[0]]
for i in range(1,len(chalk)):
prefix_sum.append(prefix_sum[i-1]+chalk[i])
left_chalk = k % prefix_sum[len(prefix_sum)-1]
s , e = 0 , len(prefix_sum)-1
while(s<=e):... | find-the-student-that-will-replace-the-chalk | Python 3 solution with binary search and prefix sum technique | ronipaul9972 | 0 | 35 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,815 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1941199/Python-Binary-Search-(-89.28-99.2) | class Solution:
def chalkReplacer(self, chalk, k: int) -> int:
k = k % sum(chalk)
left = 0
right = len(chalk) - 1
while left <= right:
mid = left + (right - left) // 2
res = sum(chalk[0:mid])
if res == k:
return mid
if ... | find-the-student-that-will-replace-the-chalk | Python Binary Search ( 89.28%, 99.2%) | fy552005184 | 0 | 81 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,816 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1906818/Python-or-Math-or-Linear-or-Comments-or-Easy-Solution | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
chalk_sum = sum(chalk)
#finding the remaining ans after some loops
ans = k%chalk_sum
#Now finding same at last loop
for i in range(len(chalk)):
if ans==0 or ans<ch... | find-the-student-that-will-replace-the-chalk | Python | Math | Linear | Comments | Easy Solution | Brillianttyagi | 0 | 37 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,817 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1499605/Python-3-Solution-Faster-then-88-and-memory-usage-93 | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
iteration = sum(chalk)
remainder = k%iteration
if remainder == 0:
return 0
else:
while remainder >= 0:
for i in range(0,len(chalk)):
remainder =rema... | find-the-student-that-will-replace-the-chalk | Python 3 Solution, Faster then 88% and memory usage 93% | xevb | 0 | 47 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,818 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1267582/Simple-python-answer | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
while k>=0:
for j,i in enumerate(chalk):
if k<0:
return j-1
k = k-i | find-the-student-that-will-replace-the-chalk | Simple python answer | Sanyamx1x | 0 | 23 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,819 |
https://leetcode.com/problems/find-the-student-that-will-replace-the-chalk/discuss/1267793/Python-Solution | class Solution:
def chalkReplacer(self, chalk: List[int], k: int) -> int:
k %= sum(chalk)
n = len(chalk)
for i in range(n):
if chalk[i] > k:
return i
k -= chalk[i] | find-the-student-that-will-replace-the-chalk | Python Solution | mariandanaila01 | -1 | 30 | find the student that will replace the chalk | 1,894 | 0.438 | Medium | 26,820 |
https://leetcode.com/problems/largest-magic-square/discuss/1267452/Python3-prefix-sums | class Solution:
def largestMagicSquare(self, grid: List[List[int]]) -> int:
m, n = len(grid), len(grid[0]) # dimensions
rows = [[0]*(n+1) for _ in range(m)] # prefix sum along row
cols = [[0]*n for _ in range(m+1)] # prefix sum along column
for i in range(m):
fo... | largest-magic-square | [Python3] prefix sums | ye15 | 6 | 449 | largest magic square | 1,895 | 0.519 | Medium | 26,821 |
https://leetcode.com/problems/largest-magic-square/discuss/1267452/Python3-prefix-sums | class Solution:
def largestMagicSquare(self, grid: List[List[int]]) -> int:
m, n = len(grid), len(grid[0]) # dimensions
rows = [[0]*(n+1) for _ in range(m)]
cols = [[0]*n for _ in range(m+1)]
diag = [[0]*(n+1) for _ in range(m+1)]
anti = [[0]*(n+1) for _ in range(m+1)]
... | largest-magic-square | [Python3] prefix sums | ye15 | 6 | 449 | largest magic square | 1,895 | 0.519 | Medium | 26,822 |
https://leetcode.com/problems/largest-magic-square/discuss/1267470/DP-and-Prefix-Sum-oror-97-faster-oror-well-Explained | class Solution:
def largestMagicSquare(self, grid: List[List[int]]) -> int:
m=len(grid)
n=len(grid[0])
# Row sum matrix
rowPrefixSum=[[0]*(n+1) for r in range(m)]
for r in range(m):
for c in range(n):
rowPrefixSum[r][c+1]=rowPrefixSum[r][c] + grid[r][c]
#column sum Matr... | largest-magic-square | 🐍 DP and Prefix Sum || 97% faster || well-Explained 📌 | abhi9Rai | 4 | 341 | largest magic square | 1,895 | 0.519 | Medium | 26,823 |
https://leetcode.com/problems/largest-magic-square/discuss/1436127/Python-3-or-Very-Clean-Code-O(min(M-N)-2-*-M-*-N)-or-Explanation | class Solution:
def largestMagicSquare(self, grid: List[List[int]]) -> int:
m, n = len(grid), len(grid[0])
dp = [[(0, 0, 0, 0)] * (n+1) for _ in range(m+1)] # [prefix-row-sum, prefix-col-sum, prefix-major-diagonal, prefix-minor-diagonal]
for i in range(1, m+1): # O(... | largest-magic-square | Python 3 | Very Clean Code, O(min(M, N) ^ 2 * M * N) | Explanation | idontknoooo | 2 | 388 | largest magic square | 1,895 | 0.519 | Medium | 26,824 |
https://leetcode.com/problems/largest-magic-square/discuss/2553485/Python-Fast-by-PreFixSum-and-early-returns-(220-429ms) | class Solution:
def largestMagicSquare(self, grid: List[List[int]]) -> int:
# get matrix dimensions
m, n = len(grid), len(grid[0])
# make the prefix sum for faster summation
preSumRow = [[0] * (n + 1) for _ in range(m)]
preSumCol = [[0] * (m + 1) for _ in ra... | largest-magic-square | [Python] - Fast by PreFixSum and early returns - (220-429ms) | Lucew | 0 | 28 | largest magic square | 1,895 | 0.519 | Medium | 26,825 |
https://leetcode.com/problems/largest-magic-square/discuss/1362476/Brute-force-approach | class Solution:
@staticmethod
def is_magic(mat: List[List[int]]):
n, s = len(mat), sum(mat[0])
for r in range(1, n):
if sum(mat[r]) != s:
return False
if any(sum(col) != s for col in zip(*mat)):
return False
d1 = d2 = 0
n1 = n - 1
... | largest-magic-square | Brute force approach | EvgenySH | 0 | 134 | largest magic square | 1,895 | 0.519 | Medium | 26,826 |
https://leetcode.com/problems/minimum-cost-to-change-the-final-value-of-expression/discuss/1272620/Python3-divide-and-conquer | class Solution:
def minOperationsToFlip(self, expression: str) -> int:
loc = {}
stack = []
for i in reversed(range(len(expression))):
if expression[i] == ")": stack.append(i)
elif expression[i] == "(": loc[stack.pop()] = i
def fn(lo, hi):
... | minimum-cost-to-change-the-final-value-of-expression | [Python3] divide & conquer | ye15 | 0 | 57 | minimum cost to change the final value of expression | 1,896 | 0.548 | Hard | 26,827 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1268522/Python-or-dictionary | class Solution:
def makeEqual(self, words: List[str]) -> bool:
map_ = {}
for word in words:
for i in word:
if i not in map_:
map_[i] = 1
else:
map_[i] += 1
n = len(words)
for k,v in map_.items():
... | redistribute-characters-to-make-all-strings-equal | Python | dictionary | harshhx | 14 | 1,200 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,828 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1339018/PYTHON-3-%3A-or-98.48-or-EXPLAINED-orTWO-EASY-SOLUTIONSor | class Solution:
def makeEqual(self, words: List[str]) -> bool:
joint = ''.join(words)
set1 = set(joint)
for i in set1 :
if joint.count(i) % len(words) != 0 : return False
return True | redistribute-characters-to-make-all-strings-equal | PYTHON 3 : | 98.48% | EXPLAINED |TWO EASY SOLUTIONS| | rohitkhairnar | 11 | 347 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,829 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1339018/PYTHON-3-%3A-or-98.48-or-EXPLAINED-orTWO-EASY-SOLUTIONSor | class Solution:
def makeEqual(self, words: List[str]) -> bool:
joint = ''.join(words)
dic = {}
for i in joint :
if i not in dic :
dic[i] = joint.count(i)
for v in dic.values() :
if v % len(words) != 0 : return... | redistribute-characters-to-make-all-strings-equal | PYTHON 3 : | 98.48% | EXPLAINED |TWO EASY SOLUTIONS| | rohitkhairnar | 11 | 347 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,830 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1268699/Python3-freq-table | class Solution:
def makeEqual(self, words: List[str]) -> bool:
freq = defaultdict(int)
for word in words:
for ch in word: freq[ord(ch)-97] += 1
return all(x % len(words) == 0 for x in freq.values()) | redistribute-characters-to-make-all-strings-equal | [Python3] freq table | ye15 | 2 | 80 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,831 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1853047/Python-or-Count-All-Characters | class Solution:
def makeEqual(self, words: List[str]) -> bool:
n = len(words)
d = defaultdict(int)
for word in words:
for ch in word:
d[ch] += 1
for letter_count in d.values():
if letter_count % n != 0:
... | redistribute-characters-to-make-all-strings-equal | Python | Count All Characters | jgroszew | 1 | 44 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,832 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1617412/Python-1-line-Counter-Reduce-Map | class Solution:
def makeEqual(self, words: List[str]) -> bool:
return all(list(map(lambda a:a%len(words)==0, collections.Counter(functools.reduce(lambda a,b:a+b,words)).values()))) | redistribute-characters-to-make-all-strings-equal | Python 1 line Counter, Reduce, Map | mikekaufman4 | 1 | 49 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,833 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1271152/Easy-Python | class Solution:
def makeEqual(self, arr: List[str]) -> bool:
h = [0]*26
n = len(arr)
for w in arr:
for i in w:
h[ord(i)-ord('a')] += 1
for i in h:
if i%n!=0:
return 0
return 1 | redistribute-characters-to-make-all-strings-equal | Easy Python | lokeshsenthilkumar | 1 | 104 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,834 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2831353/Python-100-with-explanation | class Solution:
def makeEqual(self, words: List[str]) -> bool:
_ = ''.join(words)
for c in set(_):
if _.count(c) % len(words) != 0:
return False
return True | redistribute-characters-to-make-all-strings-equal | Python 100% with explanation | Kros-ZERO | 0 | 2 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,835 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2689807/Easy-To-Understand-Python-Solution | class Solution:
def makeEqual(self, words: List[str]) -> bool:
n = len(words)
s = "".join(words)
for count in Counter(s).values():
if count % n != 0:
return False
return True | redistribute-characters-to-make-all-strings-equal | Easy To Understand Python Solution | scifigurmeet | 0 | 3 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,836 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2682994/PYTHON-or-Easy-or-4-Lines-or-Counter-or-Beginner | class Solution:
def makeEqual(self, words: List[str]) -> bool:
d= (Counter(''.join(words)))
for k,v in d.items():
if (v%len(words)) != 0: return False
return True | redistribute-characters-to-make-all-strings-equal | PYTHON | Easy | 4 Lines | Counter | Beginner | envyTheClouds | 0 | 8 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,837 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2492035/Python-very-short-and-easy-without-Counter | class Solution:
def makeEqual(self, words: List[str]) -> bool:
joined = "".join(words)
return all(joined.count(w) % len(words) == 0 for w in set(joined)) | redistribute-characters-to-make-all-strings-equal | Python - very short and easy without Counter | yhc22593 | 0 | 11 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,838 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2414306/Python3-Dictionary | class Solution:
def makeEqual(self, words: List[str]) -> bool:
l=len(words)
if l==1:
return True
d={}
for i in range(l):
for j in words[i]:
if j in d:
d[j]+=1
else:
d[j]=1
... | redistribute-characters-to-make-all-strings-equal | [Python3] Dictionary | sunakshi132 | 0 | 34 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,839 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2389807/Fast-One-liner | class Solution:
def makeEqual(self, words: List[str]) -> bool:
return all(count % len(words) == 0 for count in Counter(''.join(words)).values()) | redistribute-characters-to-make-all-strings-equal | Fast One-liner | blest | 0 | 16 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,840 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2371757/Easy-Python-Solution-or-6-lines | class Solution:
def makeEqual(self, words: List[str]) -> bool:
n, s = len(words), "".join(words)
d = Counter(s)
for key in d:
if d[key]%n != 0:
return False
return True | redistribute-characters-to-make-all-strings-equal | Easy Python Solution | 6 lines | RajatGanguly | 0 | 25 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,841 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2208646/Python3-simple-solution | class Solution:
def makeEqual(self, words: List[str]) -> bool:
d = {}
for i in words:
for j in i:
d[j] = d.get(j,0) + 1
n = len(words)
for i,j in d.items():
if j % n != 0:
return False
return True | redistribute-characters-to-make-all-strings-equal | Python3 simple solution | EklavyaJoshi | 0 | 25 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,842 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/2020875/Python-Counter-Clean-and-Simple! | class Solution:
def makeEqual(self, words):
counter, n = reduce(add, map(Counter, words)), len(words)
return all(v%n==0 for v in counter.values()) | redistribute-characters-to-make-all-strings-equal | Python - Counter - Clean and Simple! | domthedeveloper | 0 | 66 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,843 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1875565/Python-(Simple-Approach-and-Beginner-Friendly) | class Solution:
def makeEqual(self, words: List[str]) -> bool:
dict = {}
if len(words) == 1: return True
for i in words:
for j in i:
if j in dict:
dict[j]+=1
else:
dict[j] = 1
for i, n in dict.items()... | redistribute-characters-to-make-all-strings-equal | Python (Simple Approach and Beginner-Friendly) | vishvavariya | 0 | 48 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,844 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1872064/Python-dollarolution | class Solution:
def makeEqual(self, words: List[str]) -> bool:
d = Counter({})
x = len(words)
for i in words:
d += Counter(i)
for i in d:
if d[i]%x != 0:
return False
return True | redistribute-characters-to-make-all-strings-equal | Python $olution | AakRay | 0 | 25 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,845 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1588706/Python-3-faster-than-96-using-counter | class Solution:
def makeEqual(self, words: List[str]) -> bool:
c = collections.Counter(''.join(words))
n = len(words)
return all(x % n == 0 for x in c.values()) | redistribute-characters-to-make-all-strings-equal | Python 3 faster than 96% using counter | dereky4 | 0 | 60 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,846 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1514703/python-O(n)-time-O(n)-space | class Solution:
def makeEqual(self, words: List[str]) -> bool:
n = len(words)
if n ==1:
return True
count = defaultdict(int)
for word in words:
for w in word:
count[w] += 1
for w in count:
if count[w] % n != 0:
... | redistribute-characters-to-make-all-strings-equal | python O(n) time, O(n) space | byuns9334 | 0 | 77 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,847 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1309805/Python-clean-and-Easy | class Solution:
def makeEqual(self, words: List[str]) -> bool:
tmp = ''.join(words)
suposed_w = len(words)
from collections import Counter
d = Counter(tmp)
return all([x%suposed_w == 0 for x in d.values()]) | redistribute-characters-to-make-all-strings-equal | Python clean and Easy | StneFx | 0 | 58 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,848 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1270131/Python-or-2-Lines-or-Counter-%2B-Reduce | class Solution:
def makeEqual(self, words: List[str]) -> bool:
total_counts = reduce(lambda x, y: x + Counter(y), words, Counter())
return all(total_counts[char] % len(words) == 0 for char in ascii_lowercase) | redistribute-characters-to-make-all-strings-equal | Python | 2 Lines | Counter + Reduce | leeteatsleep | 0 | 50 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,849 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1269105/Python-Count-Chars-and-Take-Mod | class Solution:
def makeEqual(self, words: List[str]) -> bool:
if len(words) == 1:
return True
count = collections.defaultdict(int)
for word in words:
for char in word:
count[char] += 1
for val in count.values():
if val % l... | redistribute-characters-to-make-all-strings-equal | [Python] Count Chars and Take Mod | LydLydLi | 0 | 34 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,850 |
https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/discuss/1268738/Python3-Solution | class Solution:
def makeEqual(self, words: List[str]) -> bool:
x = {}
for word in words:
for i in word:
if i in x:
x[i]+=1
else:
x[i]=1
return all(i%len(words) == 0 for i in x.values()) | redistribute-characters-to-make-all-strings-equal | Python3 Solution | Sanyamx1x | 0 | 34 | redistribute characters to make all strings equal | 1,897 | 0.599 | Easy | 26,851 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/1268727/Python3-binary-search | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
mp = {x: i for i, x in enumerate(removable)}
def fn(x):
"""Return True if p is a subseq of s after x removals."""
k = 0
for i, ch in enumerate(s):
if... | maximum-number-of-removable-characters | [Python3] binary search | ye15 | 10 | 467 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,852 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/2337738/Python-Plain-Binary-Search | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
def isSubseq(s,subseq,removed):
i = 0
j = 0
while i<len(s) and j<len(subseq):
if i in removed or s[i]!= subseq[j]:
i+=1
... | maximum-number-of-removable-characters | Python Plain Binary Search | Abhi_009 | 1 | 93 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,853 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/2575056/Easy-Binary-Search-Explained-%2B-Clean-Code.-Python-95-efficient-than-other-soln. | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
# You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable.
# as usual we can search through the answer.
# we have to use a "se... | maximum-number-of-removable-characters | Easy Binary Search Explained + Clean Code. Python 95% efficient than other soln. | notxkaran | 0 | 22 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,854 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/2575056/Easy-Binary-Search-Explained-%2B-Clean-Code.-Python-95-efficient-than-other-soln. | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
# You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable.
# as usual we can search through the answer.
left = 0
... | maximum-number-of-removable-characters | Easy Binary Search Explained + Clean Code. Python 95% efficient than other soln. | notxkaran | 0 | 22 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,855 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/2097593/Python-or-Clear-and-Simple-Using-Binary-Search-TC%3A-O(nlogk) | class Solution:
# ////// TC: O(n * logk) //////
# //// Checking is subsequence or not ////
def isSubsequence(self,s,subStr,removed):
i,j = 0,0
while i < len(s) and j < len(subStr):
if s[i] != subStr[j] or i in removed:
i += 1
continue
i... | maximum-number-of-removable-characters | Python | Clear and Simple Using Binary Search TC: O(nlogk) | __Asrar | 0 | 65 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,856 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/1918844/Python-or-Easy-or-Binary-Search-or-With-comments | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
#function to check that p is a subsequence of s
def issubsequence(t,s):
j = 0
if len(s)==0:
return True
for i in range(len(t)):
if t[i]==s[j]:
... | maximum-number-of-removable-characters | ✔️✔️Python🐍 | Easy | Binary Search | With comments | Brillianttyagi | 0 | 49 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,857 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/1906316/Python-Explained-Binary-Search-fast-solution-96-better-memory | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
n = len(removable)
start, end = 0, n-1
## (k+1) is what we will return. We set it to the lowest possible (k+1=0 => k = -1).
## k=-1 because of zero-indexing.
k = -1
# Binary search for t... | maximum-number-of-removable-characters | [Python] Explained - Binary Search fast solution 96% better memory | akhileshravi | 0 | 30 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,858 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/1742618/Binary-search-87-speed | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
len_p = len(p)
len_r = len(removable)
def is_subsequence(idx_rem: set) -> bool:
j = 0
for i, c in enumerate(s):
if i not in idx_rem and c == p[j]:
... | maximum-number-of-removable-characters | Binary search, 87% speed | EvgenySH | 0 | 69 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,859 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/1268732/Binary-Search-(python)-O(NlogN) | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
l,r=0,len(removable)-1
def subseq(s,p,set_):
i,j=0,0
while j<len(p) and i<len(s):
if s[i]==p[j] and i not in set_:
i+=1
j+=1
... | maximum-number-of-removable-characters | Binary Search (python)- O(NlogN) | TarunAn | 0 | 96 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,860 |
https://leetcode.com/problems/maximum-number-of-removable-characters/discuss/1583345/Python-or-Explained-or-Binary-Search-%2B-Dictionary-or-Intuitive | class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
indices = {}
for i in range(len(removable)):
indices[removable[i]] = i
def check(mid):
i, j = 0, 0
while i < len(s) and j < len(p):
if s[i] == ... | maximum-number-of-removable-characters | Python | Explained | Binary Search + Dictionary | Intuitive | detective_dp | -1 | 80 | maximum number of removable characters | 1,898 | 0.393 | Medium | 26,861 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1268491/python-or-implementation-O(N) | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
i = 1
cur = []
for a,b,c in triplets:
if a<=target[0] and b<=target[1] and c<= target[2]:
cur = [a,b,c]
break
if not cur:
return Fals... | merge-triplets-to-form-target-triplet | python | implementation O(N) | harshhx | 4 | 234 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,862 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1280409/Simple-and-clean-Greedy-Python-solution | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
a, b, c = 0, 0, 0
for i, (x, y, z) in enumerate(triplets):
if not( x > target[0] or y > target[1] or z > target[2]):
a, b, c = max(a, x), max(b, y), max(c, z)... | merge-triplets-to-form-target-triplet | Simple and clean Greedy Python solution | jaipoo | 3 | 131 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,863 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1268544/Greedy | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
m,n,o=0,0,0
for i,j,k in triplets:
if i<=target[0] and j<=target[1] and k<=target[2]:
m=max(m,i)
n=max(n,j)
o=max(o,k)
return [m,n,o]==ta... | merge-triplets-to-form-target-triplet | Greedy | prashanthp0703 | 2 | 66 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,864 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1434298/Python3-simple-one-pass-solution | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
if target in triplets:
return True
a = b = c = 0
for i in triplets:
if i[0] == target[0] and i[1] <= target[1] and i[2] <= target[2] or i[1] == target[1] and i[0] <= target[... | merge-triplets-to-form-target-triplet | Python3 simple one-pass solution | EklavyaJoshi | 1 | 57 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,865 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1268619/Greedy-oror-well-explained-oror-98-faster-oror-Easy-undestanding | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
curr=[0]*3
for t in triplets:
tmp=[max(curr[i],t[i]) for i in range(3)]
f=0
for i in range(3):
if tmp[i]>target[i]:
f=1
break
#... | merge-triplets-to-form-target-triplet | 🐍 Greedy || well-explained || 98% faster || Easy-undestanding 📌 | abhi9Rai | 1 | 59 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,866 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2798098/Python-simple-solution-with-O(N)-time-and-O(1)-space-complexity | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
set1 = set()
a = b= c = 0
for i in range(len(triplets)):
if triplets[i][0]>target[0] or triplets[i][1]>target[1] or triplets[i][2]>target[2]:
continue
... | merge-triplets-to-form-target-triplet | Python simple solution with O(N) time and O(1) space complexity | Rajeev_varma008 | 0 | 3 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,867 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2688129/Neat-O(n)-solution-using-zip-in-Python | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
merge_triplet = [float("-inf")] * len(target)
for cur_triplet in triplets:
if all(cur_num <= target_num for cur_num, target_num in zip(cur_triplet, target)):
merge_triplet = [ma... | merge-triplets-to-form-target-triplet | Neat O(n) solution using zip in Python | ste42 | 0 | 6 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,868 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2670463/Python3-Easy-Solution | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
# loop trough the triplets to find any triplet that matches to one of the num in the target
cur = [0] * 3
for triplet in triplets:
if cur == target:
return True
... | merge-triplets-to-form-target-triplet | Python3 Easy Solution | a1ex_Yichen | 0 | 31 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,869 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2640289/Easy-O(N)-Python-Solution | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
good=[]
for x,y,z in triplets:
if x>target[0] or y>target[1] or z>target[2]:
continue
good.append([x,y,z])
result=set()
for item in good:
... | merge-triplets-to-form-target-triplet | Easy O(N) Python Solution | wahid_nlogn | 0 | 1 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,870 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2607608/Simple-Python3-or-O(n) | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
ta = tb = tc = False
for a, b, c in triplets:
if a <= target[0] and b <= target[1] and c <= target[2]:
if a == target[0]:
ta = True
if b == t... | merge-triplets-to-form-target-triplet | Simple Python3 | O(n) | ryangrayson | 0 | 10 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,871 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2538221/Python-easy-to-read-and-understand-or-greedy | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
res = set()
for t in triplets:
if t[0] <= target[0] and t[1] <= target[1] and t[2] <= target[2]:
for i, s in enumerate(t):
if s == target[i]:
... | merge-triplets-to-form-target-triplet | Python easy to read and understand | greedy | sanial2001 | 0 | 22 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,872 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2340377/Fast-and-Super-Simple-Python-O(n).-Explained-in-comments | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
res=[0,0,0]
for a,b,c in triplets:
if(a>target[0] or b>target[1] or c>target[2]): # triplet has a value bigger than any value in target. Hence skip it
continue
res[0... | merge-triplets-to-form-target-triplet | ✅✅✅ Fast and Super Simple Python O(n). Explained in comments | arnavjaiswal149 | 0 | 25 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,873 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/2080509/Python-O(n)-time-O(1)-space-solution | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
current = [-1, -1, -1]
for triplet in triplets:
if triplet[0] > target[0] or triplet[1] > target[1] or triplet[2] > target[2]:
continue
if triplet[0... | merge-triplets-to-form-target-triplet | Python O(n) time O(1) space solution | CarnivalWilson | 0 | 24 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,874 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1508088/One-pass-98-speed | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
a, b, c = target
max_x = max_y = max_z = 0
for x, y, z in triplets:
if x <= a and y <= b and z <= c:
max_x, max_y, max_z = max(max_x, x), max(max_y, y), max(max_z, z)
... | merge-triplets-to-form-target-triplet | One pass, 98% speed | EvgenySH | 0 | 48 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,875 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1269101/Python-Simple-Solution-w-Brief-Explanation | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
first = second = third = False
for trip in triplets:
if trip == target:
return True
if trip[0] == target[0] and trip[1] <= target[1] and trip[2] <= target[2]:
... | merge-triplets-to-form-target-triplet | [Python] Simple Solution w/ Brief Explanation | LydLydLi | 0 | 29 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,876 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1268792/Python3oror-Greedy-oror-Easy-Understanding | class Solution:
def mergeTriplets(self, e: List[List[int]], target: List[int]) -> bool:
t=[]
for i in range(len(e)):
if(e[i][0]>target[0] or e[i][1]>target[1] or e[i][2]>target[2]):
pass
else:
t.append([e[i][0],e[i][1],e[i][2]])
... | merge-triplets-to-form-target-triplet | [Python3🐍]|| Greedy || Easy-Understanding 🚀 | mukul_79 | 0 | 64 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,877 |
https://leetcode.com/problems/merge-triplets-to-form-target-triplet/discuss/1268703/Python3-greedy | class Solution:
def mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool:
x = y = z = -inf
for a, b, c in triplets:
if a <= target[0] and b <= target[1] and c <= target[2]:
x, y, z = max(x, a), max(y, b), max(z, c)
return [x, y, z] == targe... | merge-triplets-to-form-target-triplet | [Python3] greedy | ye15 | 0 | 30 | merge triplets to form target triplet | 1,899 | 0.644 | Medium | 26,878 |
https://leetcode.com/problems/the-earliest-and-latest-rounds-where-players-compete/discuss/1268788/Python3-bit-mask-dp | class Solution:
def earliestAndLatest(self, n: int, firstPlayer: int, secondPlayer: int) -> List[int]:
firstPlayer, secondPlayer = firstPlayer-1, secondPlayer-1 # 0-indexed
@cache
def fn(k, mask):
"""Return earliest and latest rounds."""
can = deque()
... | the-earliest-and-latest-rounds-where-players-compete | [Python3] bit-mask dp | ye15 | 7 | 265 | the earliest and latest rounds where players compete | 1,900 | 0.518 | Hard | 26,879 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1446385/Python-3-or-Binary-Search-or-Explanation | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
m, n = len(mat), len(mat[0])
l, r = 0, n
while l <= r:
mid = (l + r) // 2
cur_max, left = 0, False
for i in range(m):
if i > 0 and mat[i-1][mid] >= mat[i][mid]:
... | find-a-peak-element-ii | Python 3 | Binary Search | Explanation | idontknoooo | 17 | 2,100 | find a peak element ii | 1,901 | 0.532 | Medium | 26,880 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1958684/Python-oror-Binary-search | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
left, right = 0, len(mat[0]) - 1
while left <= right:
midCol = (left + right)//2
maxRow = 0
for i in range(len(mat)):
maxRow = i if mat[i][midCol] > ma... | find-a-peak-element-ii | Python || Binary search | silviyavelani | 2 | 223 | find a peak element ii | 1,901 | 0.532 | Medium | 26,881 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1491197/Python3-simple-solution-or-explained | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
n = len(mat)
m = len(mat[0])
for i in range(n):
for j in range(m):
if i-1 < 0: # checking up
up = -1
else:
up = mat[i-1][j]
... | find-a-peak-element-ii | Python3 simple solution | explained | FlorinnC1 | 2 | 325 | find a peak element ii | 1,901 | 0.532 | Medium | 26,882 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1275466/Python-3-100-time-and-Space-oror-Explained | class Solution:
def __init__(self):
self.mat = 0
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
self.mat = mat
m = len(mat)
n = len(mat[0])
i, j = 0, 0
while i < m:
while j < n:
if (self.mat_val(i, j-1)<self.mat_val(i, j)
... | find-a-peak-element-ii | Python 3, 100% time and Space || Explained | satyamsinha93 | 1 | 353 | find a peak element ii | 1,901 | 0.532 | Medium | 26,883 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1273220/Python3-Binary-search-on-columns | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
self.r=0
self.c=0
rows=len(mat)
col=len(mat[0])
def helper(l,r):
if l>=r:
return False
mid=l+r>>1
for x in range(rows):
top=mat[x-1][... | find-a-peak-element-ii | [Python3] Binary search on columns | abhinav4202 | 1 | 191 | find a peak element ii | 1,901 | 0.532 | Medium | 26,884 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/2789579/Simple-Python-Solution-oror-Easy-Understanding | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
def check(mat, i, j, r, c):
if (i-1 >= 0 and i-1 < r):
if (mat[i][j] < mat[i-1][j]): return False
if (i+1 >= 0 and i+1 < r):
if (mat[i][j] < mat[i+1][j]): return False
... | find-a-peak-element-ii | Simple Python Solution || Easy Understanding | avinashdoddi2001 | 0 | 6 | find a peak element ii | 1,901 | 0.532 | Medium | 26,885 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/2664188/Find-a-Peak-Element-II | class Solution:
def is_peak_ele(self, mat, a, row, col,m,n):
# checking the edge condition
di = [-1,1,0,0]
dj = [0,0,-1,1]
check_dir = []
# check up is possible
if row != 0:
check_dir.append(0)
# check Down is possible
if row != m-1:
... | find-a-peak-element-ii | Find a Peak Element II | Ninjaac | 0 | 20 | find a peak element ii | 1,901 | 0.532 | Medium | 26,886 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/2610908/Python3-or-Solved-Using-Binary-Search-on-Search-Space-Based-on-Rows-Runtime(O(nlog(m)) | class Solution:
#Time-Complexity: O(log(m) * n)
#Space-Complexity: O(1)
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
#Approach: You can think of this problem in two ways! Either column-based or row-based!
#Idea is that we perform binary serach on mat grid and ... | find-a-peak-element-ii | Python3 | Solved Using Binary Search on Search Space Based on Rows Runtime(O(nlog(m)) | JOON1234 | 0 | 56 | find a peak element ii | 1,901 | 0.532 | Medium | 26,887 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/2495165/Python3-clever-solution-oror-Easy-to-understand | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
m, n = len(mat), len(mat[0])
l, r = 0, n
while l <= r:
mid = (l + r) // 2
cur_max, left = 0, False
for i in range(m):
if i > 0 and mat[i-1][mid] >= mat[i][mid]:
... | find-a-peak-element-ii | ✔️ [Python3] clever solution || Easy to understand | Omegang | 0 | 91 | find a peak element ii | 1,901 | 0.532 | Medium | 26,888 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/2396608/simple-oror-python | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
m=[]
for i in range(len(mat)):
for j in range(len(mat[0])):
m.append(mat[i][j])
ma=max(m)
print(ma)
for i in range(len(mat)):
for j in range(len(mat[0])):
... | find-a-peak-element-ii | simple || python | Sneh713 | 0 | 121 | find a peak element ii | 1,901 | 0.532 | Medium | 26,889 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1279122/Intuitive-approach-by-DFS | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
m, n = len(mat), len(mat[0])
vset = set()
def dfs(i, j):
v = mat[i][j]
vset.add((i, j))
for ni, nj in filter(
lambda t: t[0] >= 0 and t[0] < m and t[1] >= 0 and t[1]... | find-a-peak-element-ii | Intuitive approach by DFS | puremonkey2001 | 0 | 150 | find a peak element ii | 1,901 | 0.532 | Medium | 26,890 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1276998/Python3-divide-and-conquer-O(MlogN) | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
m, n = len(mat), len(mat[0]) # dimensions
def fn(lo, hi):
"""Return a peak element between column lo (inclusive) and hi (exlusive)."""
if lo == hi: return
mid = lo + hi >> 1
... | find-a-peak-element-ii | [Python3] divide & conquer O(MlogN) | ye15 | 0 | 184 | find a peak element ii | 1,901 | 0.532 | Medium | 26,891 |
https://leetcode.com/problems/find-a-peak-element-ii/discuss/1273663/Python3%3A-find-row-by-bisection | class Solution:
def findPeakGrid(self, mat: List[List[int]]) -> List[int]:
M = len(mat)
N = len(mat[0])
@cache
def rmax(r):
return max(mat[r])
l,r = 0,M
while r-l>1:
m = l+(r-l)//2
assert(m>0)
if rmax(m)>rmax(m-1):
... | find-a-peak-element-ii | Python3: find row by bisection | vsavkin | 0 | 97 | find a peak element ii | 1,901 | 0.532 | Medium | 26,892 |
https://leetcode.com/problems/largest-odd-number-in-string/discuss/1338138/PYTHON-3%3A-99.34-FASTER-EASY-EXPLANATION | class Solution:
def largestOddNumber(self, num: str) -> str:
for i in range(len(num) - 1, -1, -1) :
if num[i] in {'1','3','5','7','9'} :
return num[:i+1]
return '' | largest-odd-number-in-string | PYTHON 3: 99.34% FASTER, EASY EXPLANATION | rohitkhairnar | 30 | 1,400 | largest odd number in string | 1,903 | 0.557 | Easy | 26,893 |
https://leetcode.com/problems/largest-odd-number-in-string/discuss/1284227/Python3-Simple-Readable-Solution-With-Comments-(Finding-Leftmost-odd-number) | class Solution:
def largestOddNumber(self, num: str) -> str:
# We have to just find the last index of an odd number, then slice the number upto that index, becuase an odd number always ends with a number which is not divisible by 2 :)
# Lets take the last index of an odd number as... | largest-odd-number-in-string | [Python3] Simple, Readable Solution With Comments (Finding Leftmost odd number) | VoidCupboard | 4 | 473 | largest odd number in string | 1,903 | 0.557 | Easy | 26,894 |
https://leetcode.com/problems/largest-odd-number-in-string/discuss/1284268/Python3-greedy | class Solution:
def largestOddNumber(self, num: str) -> str:
ii = -1
for i, x in enumerate(num):
if int(x) & 1: ii = i
return num[:ii+1] | largest-odd-number-in-string | [Python3] greedy | ye15 | 2 | 100 | largest odd number in string | 1,903 | 0.557 | Easy | 26,895 |
https://leetcode.com/problems/largest-odd-number-in-string/discuss/1284268/Python3-greedy | class Solution:
def largestOddNumber(self, num: str) -> str:
for i in reversed(range(len(num))):
if int(num[i]) & 1: return num[:i+1]
return "" | largest-odd-number-in-string | [Python3] greedy | ye15 | 2 | 100 | largest odd number in string | 1,903 | 0.557 | Easy | 26,896 |
https://leetcode.com/problems/largest-odd-number-in-string/discuss/2242822/Easy-to-understand-or-Python3-Solution | class Solution:
def largestOddNumber(self, num: str) -> str:
res = -1
for i in range(len(num)):
if int(num[i]) % 2 == 1:
res = i
if res == -1:
return ""
else:
return str(num[0:res+1]) | largest-odd-number-in-string | Easy to understand | Python3 Solution | irapandey | 1 | 147 | largest odd number in string | 1,903 | 0.557 | Easy | 26,897 |
https://leetcode.com/problems/largest-odd-number-in-string/discuss/1539701/EASY-BEGINNER-FRIENDLY-SOLN | class Solution:
def largestOddNumber(self, num: str):
i = 1
while True:
if i > len(num):
return ""
break
n = num[-i]
if n in '02468':
i += 1
continue
elif n not in '02468':
... | largest-odd-number-in-string | EASY BEGINNER FRIENDLY SOLN | anandanshul001 | 1 | 108 | largest odd number in string | 1,903 | 0.557 | Easy | 26,898 |
https://leetcode.com/problems/largest-odd-number-in-string/discuss/1395663/python-soln-oror-Beginners-oror-easy-oror | class Solution:
def largestOddNumber(self, num: str) -> str:
ans=""
lst=[]
for i in range(len(num)-1,-1,-1):
if int(num[i])%2 !=0:
return num[:i+1]
return ans | largest-odd-number-in-string | python soln || Beginners || easy || | minato_namikaze | 1 | 100 | largest odd number in string | 1,903 | 0.557 | Easy | 26,899 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.