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/queries-on-number-of-points-inside-a-circle/discuss/1353057/One-liner-78-speed
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: return [sum(pow(x - xc, 2) + pow(y - yc, 2) - r * r <= 0 for x, y in points) for xc, yc, r in queries]
queries-on-number-of-points-inside-a-circle
One liner, 78% speed
EvgenySH
1
193
queries on number of points inside a circle
1,828
0.864
Medium
26,100
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2835422/python-code
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: m=len(points) n=len(queries) ans=[] for i in range(n): count=0 for j in range(m): if (queries[i][0]-points[j][0])**2 + (queries[i][1]-points[j][1])**2 <= queries[i][2]**2: count+=1 ans.append(count) return ans
queries-on-number-of-points-inside-a-circle
python code
ayushigupta2409
0
5
queries on number of points inside a circle
1,828
0.864
Medium
26,101
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2799913/Python-beats-80-(Clean-solution)
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: innerPointsCount = [] for i, q in enumerate(queries): count = 0 for j, p in enumerate(points): if ((p[0] - q[0]) ** 2) + ((p[1] - q[1]) ** 2) <= q[2] ** 2: count += 1 innerPointsCount.append(count) return innerPointsCount
queries-on-number-of-points-inside-a-circle
Python beats 80% (Clean solution)
farruhzokirov00
0
4
queries on number of points inside a circle
1,828
0.864
Medium
26,102
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2692623/Python3-Simple-Solution
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: res = [] for Cx, Cy, r in queries: count = 0 for x, y in points: if (Cx - x)**2 + (Cy - y)**2 <= r**2: count += 1 res.append(count) return res
queries-on-number-of-points-inside-a-circle
Python3 Simple Solution
mediocre-coder
0
5
queries on number of points inside a circle
1,828
0.864
Medium
26,103
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2663463/Python-Easy-understanding
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: result = [] for i in range(len(queries)): cx = queries[i][0] cy = queries[i][1] r = queries[i][2] total = 0 for j in range(len(points)): x = points[j][0] y = points[j][1] distance = (cx - x)**2 + (cy-y)**2 distance = distance**(1/2) if distance <= r: total += 1 result.append(total) return result
queries-on-number-of-points-inside-a-circle
Python Easy understanding
Noisy47
0
12
queries on number of points inside a circle
1,828
0.864
Medium
26,104
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2657456/Python3-Keeping-It-Integer
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: c = [0 for i in range(len(queries))] for i in range(len(queries)): q = queries[i] r2 = q[-1]*q[-1] for p in points: d2 = (q[0]-p[0])**2 + (q[1]-p[1])**2 if d2 <= r2: c[i] += 1 return c
queries-on-number-of-points-inside-a-circle
Python3 Keeping It Integer
godshiva
0
2
queries on number of points inside a circle
1,828
0.864
Medium
26,105
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2615317/Python-Basic-Math-(Iterative-solution)
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: l=[] for circle in range(len(queries)): count=0 for point in range(len(points)): if (queries[circle][0]-points[point][0])**2 + (queries[circle][1]-points[point][1])**2 <= queries[circle][2]**2: count+=1 l.append(count) return l
queries-on-number-of-points-inside-a-circle
Python - Basic Math (Iterative solution)
utsa_gupta
0
38
queries on number of points inside a circle
1,828
0.864
Medium
26,106
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2583760/Python-One-Liner-for-fun
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: return [sum(((px-rx)**2 + (py-ry)**2 <= r**2) for px, py in points) for rx, ry, r in queries]
queries-on-number-of-points-inside-a-circle
[Python] - One-Liner for fun
Lucew
0
29
queries on number of points inside a circle
1,828
0.864
Medium
26,107
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2491260/Simple-python-solution
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: res = [] for circle in queries: x,y,r = circle count = 0 for point in points: xi,yi = point distance = sqrt((xi - x)**2 + (yi - y)**2) if distance <=r: count += 1 res.append(count) return res
queries-on-number-of-points-inside-a-circle
Simple python solution
aruj900
0
50
queries on number of points inside a circle
1,828
0.864
Medium
26,108
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2227446/python-solution-oror-one-liner-oror-My-first-one-liner
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: return [sum([math.dist(point, [query[0], query[1]]) <= query[2] for point in points]) for query in queries]
queries-on-number-of-points-inside-a-circle
python solution || one liner || My first one-liner
lamricky11
0
44
queries on number of points inside a circle
1,828
0.864
Medium
26,109
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2212612/Python-Euclidean-distance-solution
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: # Euclidean distance should be less than or equal to radius res = [] for query in queries: count = 0 for point in points: if sqrt(pow((query[0] - point[0]), 2) + pow((query[1] - point[1]), 2)) <= query[2]: count += 1 res.append(count) return res
queries-on-number-of-points-inside-a-circle
Python Euclidean distance solution
Gp05
0
30
queries on number of points inside a circle
1,828
0.864
Medium
26,110
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1769788/Queries-on-Number-of-Points-Inside-a-Circle-python-solution
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: fans = [] count = 0 for i in range(len(queries)): for j in range(len(points)): if (points[j][0]-queries[i][0])**2 + (points[j][1]-queries[i][1])**2 <= (queries[i][2])**2: count+=1 fans.append(count) answer = [fans[0]] for x in range(1,len(fans)): answer.append(fans[x] - fans[x-1]) return answer
queries-on-number-of-points-inside-a-circle
Queries on Number of Points Inside a Circle python solution
seabreeze
0
78
queries on number of points inside a circle
1,828
0.864
Medium
26,111
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1309676/Python-Simple-Mathor-Memory-lesser-than-90
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: #(x-x1)**2+(y-y1)**2<=r**2 for point to lie inside a circle res=[0]*(len(queries)) i=0 for x,y,r in queries: for x1,y1 in points: if (x-x1)**2+(y-y1)**2<=r**2: res[i]+=1 i+=1 return res
queries-on-number-of-points-inside-a-circle
Python Simple Math| Memory lesser than 90%
ana_2kacer
0
105
queries on number of points inside a circle
1,828
0.864
Medium
26,112
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1275658/Python3-simple-%22one-liner%22-solution
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: return [sum([1 for j in points if (i[0]-j[0])**2+(i[1]-j[1])**2-i[2]**2 <= 0]) for i in queries]
queries-on-number-of-points-inside-a-circle
Python3 simple "one-liner" solution
EklavyaJoshi
0
86
queries on number of points inside a circle
1,828
0.864
Medium
26,113
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1163145/Python3-brute-force
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: ans = [] for x, y, r in queries: val = 0 for xx, yy in points: if (x-xx)**2 + (y-yy)**2 <= r**2: val += 1 ans.append(val) return ans
queries-on-number-of-points-inside-a-circle
[Python3] brute-force
ye15
0
39
queries on number of points inside a circle
1,828
0.864
Medium
26,114
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1163125/Python-Solution
class Solution: def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]: res = [] for x,y,r in queries: rsq = pow(r,2) count = 0 for px,py in points: ans = pow(px-x,2)+pow(py-y,2) if ans<= rsq: count += 1 res.append(count) return res
queries-on-number-of-points-inside-a-circle
Python Solution
SaSha59
0
104
queries on number of points inside a circle
1,828
0.864
Medium
26,115
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1281679/Python3-solution-using-single-for-loop
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: res = [] for i in range(1,len(nums)): res.append(2**maximumBit - 1 - nums[i-1]) nums[i] = nums[i-1]^nums[i] res.append(2**maximumBit - 1 - nums[-1]) return res[::-1]
maximum-xor-for-each-query
Python3 solution using single for loop
EklavyaJoshi
3
111
maximum xor for each query
1,829
0.769
Medium
26,116
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1167144/Python-3-One-liner-faster-than-100
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: return list(accumulate([nums[0] ^ 2 ** maximumBit - 1] + nums[1:], ixor))[::-1]
maximum-xor-for-each-query
[Python 3] One-liner faster than 100%
kingjonathan310
3
160
maximum xor for each query
1,829
0.769
Medium
26,117
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1167144/Python-3-One-liner-faster-than-100
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: return list(accumulate([nums[0] ^ (1 << maximumBit) - 1] + nums[1:], ixor))[::-1]
maximum-xor-for-each-query
[Python 3] One-liner faster than 100%
kingjonathan310
3
160
maximum xor for each query
1,829
0.769
Medium
26,118
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/2771136/Simple-solution-beats-99
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: ans = [0] * len(nums) x = (2**maximumBit-1) for i, n in enumerate(nums): x = x ^ n ans[-1-i] = x return ans
maximum-xor-for-each-query
Simple solution beats 99%
Mencibi
1
23
maximum xor for each query
1,829
0.769
Medium
26,119
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/2845941/Python-or-2-line-or-o(n)-or-well-commented-or-prefix-sum-or-one-pass-or-bit-manipulation
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: m,prefix_xor = 2**maximumBit - 1 , list(accumulate(nums,xor))[::-1] return (i^m for i in prefix_xor) """ 2 3 4 7 ( Given ) 010 011 100 111 (given in binary) 010 001 101 010 (since constrain is high &amp;&amp; we have to repeatively calculate xor we should use prefix-xor) ^ k k k k (k'th val to xor to get all set bit i.e 111) 111 111 111 111 ( this is result and we have to find val of k for each query) NOTE: i ^ k = res, then i ^ res = k So take the prefix-xor and xor every ele with all set bit. all set-bit = pow(2,maximumBit) - 1 prefix-xor = accumulate(nums,xor) make sure to use prefix-xor in reverse order because in question we have asked xor of complete list in first query """
maximum-xor-for-each-query
Python | 2-line | o(n) | well-commented | prefix-sum | one-pass | bit-manipulation
YaBhiThikHai
0
1
maximum xor for each query
1,829
0.769
Medium
26,120
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/2646520/Python3-or-Prefix-Sum-With-Bit-Manip.-Fact-Max-XOR-2maximumBit-1
class Solution: #Let n = len(nums)! #Time-Complexity: O(n + n) -> O(N) #Space-Complexity: O(N) def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: #Approach: #1. First, initialize prefix sum array of exclusive or results up to each index position! prefix_sum = [nums[0]] for a in range(1, len(nums)): prefix_sum.append(prefix_sum[len(prefix_sum)-1] ^ nums[a]) #2.For each query, take the prefix sum of current index starting from the end and moving left, and #utilize binary search on search space of possible values for non-negative integer k, that is #maximal and satisfies the inequality! comparison = 2 ** maximumBit ans = [] #for each query for i in range(len(prefix_sum)-1, -1, -1): #get the res so far! current_res = prefix_sum[i] #largest XOR is going to be 2^maximumBit - (1)! #Thus, knowing current_res prefix result and largest possible XOR, #if we exclusive or btw the two, we will be able to find #non-negative k that maximizes XOR for current query! res = current_res ^ (comparison - 1) ans.append(res) return ans
maximum-xor-for-each-query
Python3 | Prefix Sum With Bit Manip. Fact Max XOR = 2^maximumBit - 1
JOON1234
0
21
maximum xor for each query
1,829
0.769
Medium
26,121
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1571069/Python-solution
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: prefix = [nums[0]] for idx in range(1, len(nums)): prefix.append(prefix[idx-1] ^ nums[idx]) print(prefix) ans = [] maxValue = 2 ** maximumBit for idx in range(len(nums)-1, -1, -1): k=prefix[idx] ^ (maxValue-1) ans.append(k) return ans
maximum-xor-for-each-query
Python solution
akshaykumar19002
0
62
maximum xor for each query
1,829
0.769
Medium
26,122
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1527716/Python-or-O(n)-Solution-or-Prefix-array-or-Simple-approach
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: pre=[] x=0 ans=[] for i in range(len(nums)): x=x^nums[i] pre.append(x) bit=2**maximumBit for i in range(len(nums)-1,-1,-1): k=pre[i]^(bit-1) ans.append(k) return ans
maximum-xor-for-each-query
Python | O(n) Solution | Prefix array | Simple approach
meghanakolluri
0
108
maximum xor for each query
1,829
0.769
Medium
26,123
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1234115/O(N)-solution-WIth-Concept-of-XORING-Explained
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: list_arr,xor = [],0 for i in range(0,len(nums)) : xor ^= nums[i] list_arr.append(xor ^ ((1 << maximumBit)-1)) return list_arr[::-1]
maximum-xor-for-each-query
O(N) solution WIth Concept of XORING Explained
lankesh
0
76
maximum xor for each query
1,829
0.769
Medium
26,124
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1165473/Python3-O(n)-Solution-with-Explanation-and-Comments-100-fast-and-100-memory-efficient
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: ''' 1. The maximum value achieved from a number of maximumBit is 2^(maximumBit)-1 2. Need to find the d in the equation a XOR b XOR c XOR d = x 3. If a XOR b XOR c XOR d = x, then a XOR b XOR c XOR x = d 4. Starting from index 0, XOR nums[i] with 2^(maximumBit)-1 and store in the list 5. Up until the last element, XOR nums[i] with the previous XOR result and append to the list 6. Return the list in reverse order ''' maxm = 2**maximumBit - 1 #the maximum value of maxiumBit count res = [nums[0]^maxm] #store the initial xor result in res list XOR = res[0] if len(nums)>=2: for num in nums[1:]: XOR^=num #bitwise XOR of previous xor result with nums[i] res.append(XOR) return res[::-1] #return the reverse list
maximum-xor-for-each-query
Python3 O(n) Solution with Explanation and Comments, 100% fast and 100% memory efficient
bPapan
0
44
maximum xor for each query
1,829
0.769
Medium
26,125
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1164591/100-faster-100-less-time-python-solution
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: res = reduce(operator.xor, nums) # taking the xor of 1st n elements lim = (1<<maximumBit)-1 # store = [] for val in nums[::-1]: store.append(res^lim) res = res^val return store
maximum-xor-for-each-query
100% faster, 100% less time python solution
deleted_user
0
41
maximum xor for each query
1,829
0.769
Medium
26,126
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1163923/Simple-Python3-solution-with-O(n)-DP-one-time-list-walkthrough
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: # Compute XOR for each query # e.g., [0, 1, 1, 3] # first query k: k XOR (0 XOR 1 XOR 1 XOR 3) = 2**(maximumBit)-1 # => k = 2**(maxiumBit)-1 XOR (0 XOR 1 XOR 1 XOR 3) # second query k: k XOR (0 XOR 1 XOR 1) = 2**(maximumBit)-1 # => k = 2**(maxiumBit)-1 XOR (0 XOR 1 XOR 1) for i in range(len(nums)): if i == 0: nums[i] = nums[i] ^ (2**(maximumBit)-1) continue nums[i] = nums[i] ^ nums[i-1] return nums[::-1]
maximum-xor-for-each-query
Simple Python3 solution with O(n) DP one-time list walkthrough
tkuo-tkuo
0
34
maximum xor for each query
1,829
0.769
Medium
26,127
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1163431/Python3-Solution
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: maxiNum = 2**maximumBit ans = [] xor = 0 for i in nums: xor ^= i while len(nums) != 0: num,sum_ = 0,0 for i in range(32): num = 1<<i if (num<=(maxiNum-1)): if not xor&amp;num: sum_ += num else: break ans.append(sum_) last = nums.pop() xor ^= last return ans
maximum-xor-for-each-query
Python3 Solution
swap2001
0
34
maximum xor for each query
1,829
0.769
Medium
26,128
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1163217/Python3-1-pass
class Solution: def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: ans = [0]*len(nums) prefix = 0 for i, x in enumerate(nums): prefix ^= x ans[~i] = prefix ^ ((1 << maximumBit) -1) return ans
maximum-xor-for-each-query
[Python3] 1-pass
ye15
0
38
maximum xor for each query
1,829
0.769
Medium
26,129
https://leetcode.com/problems/maximum-xor-for-each-query/discuss/1163115/Python-Solution
class Solution: ''' Step 1: Building a xor array. eg :[0,1,1,3] xor = [0] now 0 xor 1 [0,1] now 1 xor 1 [0,1,0] finally 0 xor 3 [0,1,0,3] step 2: Now to find the value of k at each query we just want to take the len(2^maxbit-1 )so here its 2 digit(maxBit =2 so 2^2 = 4 ) . no.of bits in 3 are 2 value of k will be inverse of xor value[i] eg : when i = 0 xor[i] = 0 what will be the value of k in this case when bits are 2 00 xor inverse(00) inverse(00) = 11 hence k = 3 ''' def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]: xor = [] maxb = len(bin(pow(2,maximumBit)-1)[2:]) n = len(nums) xor.append(nums[0]) for i in range(1,n): #step 1 xor.append(nums[i]^xor[i-1]) res = [] for xor_val in xor: bin_xor_val = list(bin(xor_val)[2:]) temp = [] for i in range(maxb-len(bin_xor_val)): temp.append('1') for bit in bin_xor_val: #performing inverse of the xor value if bit == '0': temp.append('1') else: temp.append('0') res.append(int(''.join(temp),2)) res.reverse() return res
maximum-xor-for-each-query
Python Solution
SaSha59
0
54
maximum xor for each query
1,829
0.769
Medium
26,130
https://leetcode.com/problems/minimum-number-of-operations-to-make-string-sorted/discuss/1202007/Python3-math-solution
class Solution: def makeStringSorted(self, s: str) -> int: freq = [0]*26 for c in s: freq[ord(c) - 97] += 1 MOD = 1_000_000_007 fac = cache(lambda x: x*fac(x-1)%MOD if x else 1) ifac = cache(lambda x: pow(fac(x), MOD-2, MOD)) # Fermat's little theorem (a**(p-1) = 1 (mod p)) ans, n = 0, len(s) for c in s: val = ord(c) - 97 mult = fac(n-1) for k in range(26): mult *= ifac(freq[k]) for k in range(val): ans += freq[k] * mult n -= 1 freq[val] -= 1 return ans % MOD
minimum-number-of-operations-to-make-string-sorted
[Python3] math solution
ye15
1
240
minimum number of operations to make string sorted
1,830
0.491
Hard
26,131
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2712076/Multiple-solution-in-python
class Solution: def checkIfPangram(self, sentence: str) -> bool: lst=[0]*26 for i in sentence: lst[ord(i)-ord('a')]+=1 return 0 not in lst
check-if-the-sentence-is-pangram
Multiple solution in python
shubham_1307
19
732
check if the sentence is pangram
1,832
0.839
Easy
26,132
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2712076/Multiple-solution-in-python
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence))==26
check-if-the-sentence-is-pangram
Multiple solution in python
shubham_1307
19
732
check if the sentence is pangram
1,832
0.839
Easy
26,133
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1166400/Simple-Python-solution_O(n)
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence)) == 26
check-if-the-sentence-is-pangram
Simple Python solution_O(n)
smaranjitghose
11
732
check if the sentence is pangram
1,832
0.839
Easy
26,134
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1277373/Python-2-different-approaches-or-beats-96-time-O(1)-solution!
class Solution: def checkIfPangram(self, sentence: str) -> bool: # naive approach - 1 # freq = {} # for i in sentence: # freq[i] = freq.get(i, 0) + 1 # if len(freq) == 26: return True # return False # optimized approach - 2 occurred = 0 for i in sentence: temp = ord(i) - ord('a') occurred |= (1 << temp) if occurred == (1 << 26) - 1: return True return False
check-if-the-sentence-is-pangram
Python 2 different approaches | beats 96% time, O(1) solution!
vanigupta20024
8
684
check if the sentence is pangram
1,832
0.839
Easy
26,135
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2573442/SIMPLE-PYTHON3-SOLUTION-ONE-LINE-FASTEr
class Solution: def checkIfPangram(self, sentence: str) -> bool: return(len(set(list(sentence))) == 26)
check-if-the-sentence-is-pangram
✅✔ SIMPLE PYTHON3 SOLUTION ✅✔ ONE-LINE FASTEr
rajukommula
7
158
check if the sentence is pangram
1,832
0.839
Easy
26,136
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2250518/Python3-O(n)-oror-O(1)-or-O(26)-Runtime%3A-40ms-71.99-oror-Memory%3A-13.9mb-54.83
class Solution: # O(n) || O(1) because we are dealing with lower case english alphabets O(26) # Runtime: 40ms 71.99% || Memory: 13.9mb 54.83% def checkIfPangram(self, sentence: str) -> bool: allAlpha = [False] * 26 for char in sentence: index = ord(char) - ord('a') allAlpha[index] = True return all(allAlpha[i] for i in range(26))
check-if-the-sentence-is-pangram
Python3 O(n) || O(1) or O(26) # Runtime: 40ms 71.99% || Memory: 13.9mb 54.83%
arshergon
4
96
check if the sentence is pangram
1,832
0.839
Easy
26,137
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2715601/Python-solution-using-list
class Solution: def checkIfPangram(self, sentence: str) -> bool: counter = [0 for _ in range(97, 123)] for i in sentence: counter[ord(i)-97] += 1 for i in counter: if i == 0: return False return True
check-if-the-sentence-is-pangram
📌 Python solution using list
croatoan
2
55
check if the sentence is pangram
1,832
0.839
Easy
26,138
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714052/Easy-Python-or-One-liner
class Solution: def checkIfPangram(self, sentence: str) -> bool: return(len(set(sentence))==26)
check-if-the-sentence-is-pangram
Easy Python | One-liner
tusharkhanna575
2
47
check if the sentence is pangram
1,832
0.839
Easy
26,139
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1867123/Python-solution-faster-than-95-using-sets
class Solution: def checkIfPangram(self, sentence: str) -> bool: if len(set(sentence)) == 26: return True return False
check-if-the-sentence-is-pangram
Python solution faster than 95%, using sets
alishak1999
2
105
check if the sentence is pangram
1,832
0.839
Easy
26,140
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1552514/TWO-LINER-SOLUTION-using-sorted()-and-set()-(faster-than-99.49)
class Solution: def checkIfPangram(self, sentence: str) -> bool: sentence, string = sorted(set(sentence)), "abcdefghijklmnopqrstuvwxyz" return sentence == list(string)
check-if-the-sentence-is-pangram
TWO LINER SOLUTION using sorted() and set() (faster than 99.49%)
anandanshul001
2
87
check if the sentence is pangram
1,832
0.839
Easy
26,141
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714393/Python-one-liner-easy-solution-93.35-faster
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence))==26
check-if-the-sentence-is-pangram
Python one-liner easy solution 93.35% faster
mg_112002
1
24
check if the sentence is pangram
1,832
0.839
Easy
26,142
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2713272/Python-oror-O(n)-oror-Easy-Understanding
class Solution: def checkIfPangram(self, s: str) -> bool: l = [0]*26 for i in range(len(s)): l[ord(s[i])-ord('a')] = 1 return sum(l)==26
check-if-the-sentence-is-pangram
Python || O(n) || Easy Understanding
its_iterator
1
24
check if the sentence is pangram
1,832
0.839
Easy
26,143
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2712420/python3oror-one-lineoror-O(N)
class Solution: def checkIfPangram(self, sentence: str) -> bool: return 26==len(set(sentence))
check-if-the-sentence-is-pangram
[python3|| one line|| O(N)]
Sneh713
1
4
check if the sentence is pangram
1,832
0.839
Easy
26,144
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2712300/Easy-Python-1-liner.-Beats-91
class Solution: def checkIfPangram(self, sentence: str) -> bool: return set('abcdefghijklmnopqrstuvwxyz') == set(sentence)
check-if-the-sentence-is-pangram
Easy Python 1 liner. Beats 91%
sukumar-satapathy
1
48
check if the sentence is pangram
1,832
0.839
Easy
26,145
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1688489/Python-One-Liner
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence)) == 26
check-if-the-sentence-is-pangram
Python One Liner
pratushah
1
85
check if the sentence is pangram
1,832
0.839
Easy
26,146
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1585063/Python-oror-28ms-oror-Simple-hashmap-oror-Method-2%3A-set
class Solution: def checkIfPangram(self, sentence: str) -> bool: english = "qwertyuiopasdfghjklzxcvnmb" di = {ch:1 for ch in english} for ch in sentence: di[ch]+=1 for ch in english: if di[ch]<2: return False return True
check-if-the-sentence-is-pangram
Python || 28ms || Simple hashmap || Method 2: set
ana_2kacer
1
114
check if the sentence is pangram
1,832
0.839
Easy
26,147
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1585063/Python-oror-28ms-oror-Simple-hashmap-oror-Method-2%3A-set
class Solution: def checkIfPangram(self, sentence: str) -> bool: check = set(sentence) if len(check)==26: return True return False
check-if-the-sentence-is-pangram
Python || 28ms || Simple hashmap || Method 2: set
ana_2kacer
1
114
check if the sentence is pangram
1,832
0.839
Easy
26,148
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1520060/Another-Python-one-liner
class Solution: def checkIfPangram(self, sentence: str) -> bool: return set(sentence) == set('abcdefghijklmnopqrstuvwxyz')
check-if-the-sentence-is-pangram
Another Python one-liner
SmittyWerbenjagermanjensen
1
63
check if the sentence is pangram
1,832
0.839
Easy
26,149
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1387091/Python-3-Solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: s = "abcdefghijklmnopqrstuvwxyz" for i in range(len(s)): if s[i] in sentence: flag= 1 else: flag = 0 break if flag==0: return False else: return True
check-if-the-sentence-is-pangram
Python 3 Solution
deleted_user
1
102
check if the sentence is pangram
1,832
0.839
Easy
26,150
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1236650/ONE-LINER-PYTHON-CODE-EASY-TO-UNDERSTAND-FASTER-THAN-90
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(list(sentence))) == 26 ````
check-if-the-sentence-is-pangram
ONE LINER PYTHON CODE EASY TO UNDERSTAND FASTER THAN 90%
shubhamdec10
1
151
check if the sentence is pangram
1,832
0.839
Easy
26,151
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/1231889/Python-Simply-Easy-Solution-1-Line-Faster-than-97
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence)) >= 26
check-if-the-sentence-is-pangram
Python Simply Easy Solution 1 Line Faster than 97%
Inesh
1
104
check if the sentence is pangram
1,832
0.839
Easy
26,152
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2843072/lessless-python-on-line-very-easy-solution-greatergreater
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence)) == 26;
check-if-the-sentence-is-pangram
<<-- python on line very easy solution -->>
seifsoliman
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,153
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2841887/Logic-way
class Solution: def checkIfPangram(self, sentence: str) -> bool: d = {} c = 0 for i in sentence: if not d.get(i): d[i] = True c += 1 return c == 26
check-if-the-sentence-is-pangram
Logic way
Abraha111
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,154
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2826298/Beats-99-Easy-Python-Solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: if len(sentence) < 26: return False else: for i in range(97, 123): if chr(i) not in sentence: return False return True
check-if-the-sentence-is-pangram
Beats 99% - Easy Python Solution
PranavBhatt
0
4
check if the sentence is pangram
1,832
0.839
Easy
26,155
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2793295/python-one-liner
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence))==26
check-if-the-sentence-is-pangram
[python]--one liner
user9516zM
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,156
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2792708/Python-or-Easy-or-Faster-than-99.33
class Solution: def checkIfPangram(self, sentence: str) -> bool: # For iterating over range of characters from a to z for i in range(97, 123): # Check if each character is present in sentence or not if chr(i) not in sentence: # If any character is not present in sentence, then return False and stop further processing return False # return True if all the characters are present return True
check-if-the-sentence-is-pangram
Python | Easy | Faster than 99.33%
pawangupta
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,157
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2771286/GolangRustpython-solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: if len(set(list(sentence))) == 26: return True return False
check-if-the-sentence-is-pangram
Golang,Rust,python solution
anshsharma17
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,158
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2757444/Python-solution-using-set-to-check-if-the-letters-are-unique-in-a-sentence
class Solution: def checkIfPangram(self, sentence: str) -> bool: set_sentence = set(sentence) if len(set_sentence) == 26: return True return False
check-if-the-sentence-is-pangram
Python solution using set to check if the letters are unique in a sentence
samanehghafouri
0
2
check if the sentence is pangram
1,832
0.839
Easy
26,159
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2754769/Python3-Solution-oror-Set-oror-One-Liner-Solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence)) == 26
check-if-the-sentence-is-pangram
Python3 Solution || Set || One-Liner Solution
shashank_shashi
0
2
check if the sentence is pangram
1,832
0.839
Easy
26,160
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2744562/Python-Set-Easy
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence))==26
check-if-the-sentence-is-pangram
Python Set Easy
ben_wei
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,161
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2737292/Python-Two-Solutions-(Including-One-Liner)
class Solution: #Most Time Efficient def checkIfPangram(self, sentence: str) -> bool: checked = [] for s in sentence: if s not in checked: checked.append(s) return len(checked) == 26 #Most Space Efficient def checkIfPangram(self, sentence: str) -> bool: return len(set(list(sentence)))==26
check-if-the-sentence-is-pangram
Python Two Solutions (Including One-Liner)
keioon
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,162
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2731698/solution-in-python-3
class Solution: def checkIfPangram(self, sentence: str) -> bool: ascii = [] for x in range(97, 123, 1): ascii.append(x) for y in sentence: if ord(y) in ascii: ascii.remove(ord(y)) if len(ascii) != 0: return False else: return True
check-if-the-sentence-is-pangram
solution in python 3
ramana721
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,163
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2731683/Panagram-solution-with-string.ascii_lowercase-python
class Solution: def checkIfPangram(self, sentence: str) -> bool: for i in string.ascii_lowercase: if i not in sentence: return False return True
check-if-the-sentence-is-pangram
Panagram solution with string.ascii_lowercase, python
arshadali7860
0
2
check if the sentence is pangram
1,832
0.839
Easy
26,164
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2724167/Simple-Python-Solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: alphabets = dict() for i in range(26): alphabets[chr(i + ord('a'))] = 0 for c in sentence: alphabets[c] += 1 for i in range(26): if alphabets[chr(i + ord('a'))] == 0: return False return True
check-if-the-sentence-is-pangram
Simple Python Solution
mansoorafzal
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,165
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2721237/Python-Simple-Python-Solution-By-Checking-all-Character
class Solution: def checkIfPangram(self, sentence: str) -> bool: alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] check = False for char in alpha: if char not in sentence: return False return True
check-if-the-sentence-is-pangram
[ Python ] ✅✅ Simple Python Solution By Checking all Character 🥳✌👍
ASHOK_KUMAR_MEGHVANSHI
0
2
check if the sentence is pangram
1,832
0.839
Easy
26,166
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2717355/Simple-One-Liner-or-Python
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(sentence))==26
check-if-the-sentence-is-pangram
Simple One Liner | Python
Abhi_-_-
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,167
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2715771/Python3-using-hash-table.
class Solution: def __init__(self) -> None: self.d = {} def checkIfPangram(self, sentence: str) -> bool: count = 0 for s in sentence: if s not in self.d: self.d[s] = True count += 1 return count == 26
check-if-the-sentence-is-pangram
Python3 using hash table.
parryrpy
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,168
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2715688/Python3-solution-memory-beats%3A-99.80
class Solution: def checkIfPangram(self, sentence: str) -> bool: char_dict = {chr(i):0 for i in range(97,123)} for i in sentence: char_dict[i] += 1 return min(char_dict.values())
check-if-the-sentence-is-pangram
Python3 solution - memory beats: 99.80%
sipi09
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,169
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2715507/Python-or-Faster-than-97-or-Easy-3-line-Solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: if len(sentence) < 26 : return False res = set(list(sentence)) return not len(res) < 26
check-if-the-sentence-is-pangram
✔Python | Faster than 97% | Easy 3 line Solution
sarveshmantri200
0
4
check if the sentence is pangram
1,832
0.839
Easy
26,170
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2715391/Python3!-1-Line-solution.
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(collections.Counter(sentence)) == 26
check-if-the-sentence-is-pangram
😎Python3! 1 Line solution.
aminjun
0
4
check if the sentence is pangram
1,832
0.839
Easy
26,171
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2715337/Beginner-Friendly-and-Fast-Solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: alpha = "abcdefghijklmnopqrstuvwxyz" sentence_alpha = "" for i in sentence: if i not in sentence_alpha: sentence_alpha += i return True if alpha == ''.join(sorted(sentence_alpha)) else False
check-if-the-sentence-is-pangram
Beginner Friendly and Fast Solution
user6770yv
0
2
check if the sentence is pangram
1,832
0.839
Easy
26,172
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714970/PYTHON-SOLUTION-USING-SET
class Solution: def checkIfPangram(self, sentence: str) -> bool: if len(set(sentence))==26: return True else: return False
check-if-the-sentence-is-pangram
PYTHON SOLUTION USING SET
mritunjayyy
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,173
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714907/Simple-solution-in-Python
class Solution: def checkIfPangram(self, sentence: str) -> bool: return (len(set(sentence))== 26 ) # occurred = 0 # for i in sentence: # temp = ord(i) - ord('a') # occurred |= (1 << temp) # if occurred == (1 << 26) - 1: # return True # return False
check-if-the-sentence-is-pangram
Simple solution in Python
Baboolal
0
2
check if the sentence is pangram
1,832
0.839
Easy
26,174
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714777/one-Line-code-in-python-best-Solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: lst = list(sentence) return len(set(lst))==26
check-if-the-sentence-is-pangram
one Line code in python best Solution
kartik_5051
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,175
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714743/PYHTON-oror-ONE-LINER
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(set(list(sentence)))==26
check-if-the-sentence-is-pangram
[PYHTON] || ONE LINER
SuganthSugi
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,176
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714642/Python-or-Beats-98-in-Time-and-Space-Complexity
class Solution: def checkIfPangram(self, sentence: str) -> bool: alphabet = set() for char in sentence: alphabet.add(char) return len(alphabet) >= 26
check-if-the-sentence-is-pangram
Python | Beats 98% in Time & Space Complexity
rschevenin
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,177
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714586/python3-shortest-and-elegant-solution
class Solution: def checkIfPangram(self, sentence: str) -> bool: return len(Counter(sentence))==26
check-if-the-sentence-is-pangram
python3 shortest and elegant solution
benon
0
3
check if the sentence is pangram
1,832
0.839
Easy
26,178
https://leetcode.com/problems/check-if-the-sentence-is-pangram/discuss/2714542/python-easy-solution-using-set
class Solution: def checkIfPangram(self, sentence: str) -> bool: s=set(sentence) if len(s)==26: return True return False
check-if-the-sentence-is-pangram
python easy solution using set
lalli307
0
1
check if the sentence is pangram
1,832
0.839
Easy
26,179
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1165500/Python3-with-Explanation-100-faster-and-100-memory-efficient
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: ''' 1. If the minimum of all costs is greater than amount of coins, the boy can't buy any bar, return 0 2. Else, sort the list of costs in a non-decreasing order 3. For each 'cost' in costs, if the cost is less than current coins -increase the count of ice cream bars that can be bought by 1 -decrease the current coins amount by 'cost' 4. If the cost is greater than current coins, return the ice cream bar count value ''' if min(costs)>coins: #minimum cost is greater than the coins available return 0 #can't buy any ice cream bar costs=sorted(costs) #sort the list of costs in a non-decreasing order res = 0 #the resultant count of ice cream bars that can be bought for cost in costs: if cost<=coins: #in this case, the boy can buy the ice cream bar res+=1 #increase the ice cream bar count coins-=cost #spent an amount equal to 'cost', decrease current coins amount by cost else: break #not enough coins, return the bars count return res
maximum-ice-cream-bars
Python3 with Explanation, 100% faster and 100% memory efficient
bPapan
3
279
maximum ice cream bars
1,833
0.656
Medium
26,180
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2490078/Easy-Python-Solution.....Faster-than-100
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: result=0 costs.sort() for i in costs: if coins<i: break result+=1 coins-=i return result
maximum-ice-cream-bars
Easy Python Solution.....Faster than 100%
guneet100
1
76
maximum ice cream bars
1,833
0.656
Medium
26,181
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1175446/Python3-simple-solution-using-two-approaches
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: return len([i for i in itertools.accumulate(sorted(costs)) if i <= coins])
maximum-ice-cream-bars
Python3 simple solution using two approaches
EklavyaJoshi
1
74
maximum ice cream bars
1,833
0.656
Medium
26,182
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1175446/Python3-simple-solution-using-two-approaches
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs.sort() l = [costs[0]] c = costs[0] for i in range(1,len(costs)): c += costs[i] l.append(c) return len([i for i in l if i <= coins])
maximum-ice-cream-bars
Python3 simple solution using two approaches
EklavyaJoshi
1
74
maximum ice cream bars
1,833
0.656
Medium
26,183
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2834166/Simple-or-Python3-or-C%2B%2B
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs = sorted(costs) total, ans = 0, 0 for cost in costs: if total + cost <= coins: total += cost ans += 1 else: break return ans
maximum-ice-cream-bars
Simple | Python3 | C++
joshua_mur
0
1
maximum ice cream bars
1,833
0.656
Medium
26,184
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2755610/Simple-and-Efficient-Python-Solution-Greedy-Approach
class Solution: def maxIceCream(self, cost: List[int], coins: int) -> int: cost.sort(); count = 0 for i in cost: if (coins >= i): count += 1; coins -= i; else: break return count
maximum-ice-cream-bars
Simple and Efficient Python Solution } Greedy Approach
avinashdoddi2001
0
3
maximum ice cream bars
1,833
0.656
Medium
26,185
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2743204/Python3-No-direct-Sort-Unique-Costs-and-Heap
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: # we can count the elements cn = collections.Counter(costs) # we can do a min heap from the costs costs = list(cn.keys()) heapq.heapify(costs) # pop the elements ans = 0 for _ in range(len(costs)): # pop the costs cost = heapq.heappop(costs) # get the amount of costs fit = coins // cost # subtract the costs if cn[cost] < fit: ans += cn[cost] coins -= cn[cost]*cost else: ans += fit break return ans
maximum-ice-cream-bars
[Python3] - No direct Sort - Unique Costs and Heap
Lucew
0
1
maximum ice cream bars
1,833
0.656
Medium
26,186
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2729452/Python-O(NlogN)-O(N)
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: heap = [] left = coins for cost in costs: if cost <= left: heapq.heappush(heap, -cost) left -= cost continue if heap and -heap[0] > cost: left += -heapq.heappop(heap) heapq.heappush(heap, -cost) left -= cost return len(heap)
maximum-ice-cream-bars
Python - O(NlogN), O(N)
Teecha13
0
2
maximum ice cream bars
1,833
0.656
Medium
26,187
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2713955/Python3-sort%2Bgreedy
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs.sort() if costs[0] > coins: return 0 i = 0 while i < len(costs) and coins > 0: if costs[i] > coins: break coins -= costs[i] i += 1 return i
maximum-ice-cream-bars
Python3 sort+greedy
skrrtttt
0
2
maximum ice cream bars
1,833
0.656
Medium
26,188
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2673594/Python-solution
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs.sort() count = 0 for i in costs: if i <= coins: count+=1 coins = coins-i return count
maximum-ice-cream-bars
Python solution
divyanshikathuria
0
3
maximum ice cream bars
1,833
0.656
Medium
26,189
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2610626/Python-easy-solution
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs.sort() res = 0 for i in range(len(costs)): if coins >= costs[i]: coins -= costs[i] res +=1 return res
maximum-ice-cream-bars
Python easy solution
anshsharma17
0
6
maximum ice cream bars
1,833
0.656
Medium
26,190
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/2538119/easy-python-solution
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: if sum(costs) <= coins : return len(costs) else : costs.sort() counter = 0 for ice in costs : if ice > coins : return counter counter += 1 coins -= ice return counter
maximum-ice-cream-bars
easy python solution
sghorai
0
14
maximum ice cream bars
1,833
0.656
Medium
26,191
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1500808/Python-O(nlogn)-time-O(1)-space-solution
class Solution(object): def maxIceCream(self, arr, target): """ :type costs: List[int] :type coins: int :rtype: int """ n = len(arr) arr.sort(reverse=True) res = 0 while len(arr) > 0 and target > 0: p = arr.pop() if p <= target: target -= p res += 1 else: break return res
maximum-ice-cream-bars
Python O(nlogn) time, O(1) space solution
byuns9334
0
84
maximum ice cream bars
1,833
0.656
Medium
26,192
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1420038/Python3-or-explained-or-easy-solution
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: # you have to get as much ice cream you can buy # so the best idea is to sort the list in order to have the smallest values from the start # count them while iterating and subtract the price after buying the ice cream costs.sort() n = len(costs) count = 0 for i in range(n): if costs[i] <= coins: count += 1 coins -= costs[i] else: break return count
maximum-ice-cream-bars
Python3 | explained | easy solution
FlorinnC1
0
86
maximum ice cream bars
1,833
0.656
Medium
26,193
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1353114/Sort-and-loop-84-speed
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: spend_coins = 0 costs.sort() for i, cost in enumerate(costs): if spend_coins + cost <= coins: spend_coins += cost else: return i return len(costs)
maximum-ice-cream-bars
Sort and loop, 84% speed
EvgenySH
0
43
maximum ice cream bars
1,833
0.656
Medium
26,194
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1206168/python3-easy-solution
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs.sort() count=0 for i in range(len(costs)): coins-=costs[i] if coins>=0: count+=1 else: break return count
maximum-ice-cream-bars
python3 easy solution
akashmaurya001
0
68
maximum ice cream bars
1,833
0.656
Medium
26,195
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1199204/Simple-Python-Sorting-and-Greedy-approach-O(n)-time-and-O(1)-space
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: costs.sort() # sort the array in increasing order # starting from 0th elem greedily pick ice-cream bars untill we run out of coins n, idx = len(costs), 0 while(idx < n and coins-costs[idx] >= 0): coins -= costs[idx] idx+=1 return idx
maximum-ice-cream-bars
Simple Python Sorting and Greedy approach O(n) time and O(1) space
thecoder_elite
0
59
maximum ice cream bars
1,833
0.656
Medium
26,196
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1166920/Python3-greedy
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: for i, x in enumerate(sorted(costs)): if x <= coins: coins -= x else: return i return len(costs)
maximum-ice-cream-bars
[Python3] greedy
ye15
0
42
maximum ice cream bars
1,833
0.656
Medium
26,197
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1166920/Python3-greedy
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: ans = 0 for x in sorted(costs): if x <= coins: ans += 1 coins -= x else: break return ans
maximum-ice-cream-bars
[Python3] greedy
ye15
0
42
maximum ice cream bars
1,833
0.656
Medium
26,198
https://leetcode.com/problems/maximum-ice-cream-bars/discuss/1164270/Python3-Heap-Solution
class Solution: def maxIceCream(self, costs: List[int], coins: int) -> int: result = 0 min_heap = [] heapq.heapify(min_heap) for cost in costs: heapq.heappush(min_heap,cost) while min_heap and coins: temp = heapq.heappop(min_heap) if temp <= coins: coins -= temp result += 1 return result
maximum-ice-cream-bars
[Python3] Heap Solution
pratushah
0
42
maximum ice cream bars
1,833
0.656
Medium
26,199