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/count-subarrays-with-fixed-bounds/discuss/2715901/Python3-The-Way-That-Makes-Sense-To-Me-O(n)
class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: bad, mi, ma, t = -1, -1, -1, 0 for right in range(len(nums)): if nums[right] == minK: mi=right if nums[right] == maxK: ma=right if nums[right] > maxK or nums[right] < minK: bad=right elif mi >= 0 and ma >= 0: lmin = bad + 1 lmax = min(mi, ma) if lmin<=lmax: t+=1 + lmax-lmin return t
count-subarrays-with-fixed-bounds
Python3 The Way That Makes Sense To Me O(n)
godshiva
0
23
count subarrays with fixed bounds
2,444
0.432
Hard
33,500
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2710881/Python3-sliding-window
class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: ans = 0 ii = imin = imax = -1 for i, x in enumerate(nums): if minK <= x <= maxK: if minK == x: imin = i if maxK == x: imax = i ans += max(0, min(imax, imin) - ii) else: ii = i return ans
count-subarrays-with-fixed-bounds
[Python3] sliding window
ye15
0
21
count subarrays with fixed bounds
2,444
0.432
Hard
33,501
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2710552/Python3-Easy-Solution
```class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: def solve(arr): M=len(arr) minx=collections.deque() maxx=collections.deque() for i in range(M): if arr[i]==minK: minx.append(i) if arr[i]==maxK: maxx.append(i) total=0 for i in range(M): while len(minx)>0 and minx[0]<i: minx.popleft() while len(maxx)>0 and maxx[0]<i: maxx.popleft() if len(minx)==0 or len(maxx)==0: break nx=max(minx[0],maxx[0]) total+=M-nx return total total=0 for g,t in groupby(nums,key=lambda x:minK<=x<=maxK): if g: total+=solve(list(t)) return total
count-subarrays-with-fixed-bounds
Python3 Easy Solution
Motaharozzaman1996
0
19
count subarrays with fixed bounds
2,444
0.432
Hard
33,502
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2709454/Python3-or-Sliding-Window
class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: dq=deque() n=len(nums) mn,mx=-1,-1 ans=0 for i in range(n): if minK<=nums[i]<=maxK: dq.append(i) if nums[i]==minK: mn=i if nums[i]==maxK: mx=i if mn!=-1 and mx!=-1: ans+=min(mn,mx)-dq[0]+1 else: while dq: dq.popleft() mn,mx=-1,-1 return ans
count-subarrays-with-fixed-bounds
[Python3] | Sliding Window
swapnilsingh421
0
14
count subarrays with fixed bounds
2,444
0.432
Hard
33,503
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2708477/Python-Easy-to-understand-O(n)-time-O(1)-space.
class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: n = len(nums) # store indices of previous minK, maxK, outliers prev_min, prev_max, prev_out = -1, -1, -1 cnt = 0 for i in range(n): if nums[i] < minK or nums[i] > maxK: prev_out = i continue if nums[i] == minK: prev_min = i if nums[i] == maxK: prev_max = i # count subarrays, minK <= nums[i] <= maxK if prev_out < prev_max and prev_out < prev_min: cnt += min(prev_max, prev_min) - prev_out return cnt
count-subarrays-with-fixed-bounds
[Python] Easy to understand, O(n) time, O(1) space.
YYYami
0
14
count subarrays with fixed bounds
2,444
0.432
Hard
33,504
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2708411/Python3-O(N)-dp-solution
class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: ans = 0 # kmin: number of subarrays ending at last pos that contains minK # kmax: number of subarrays ending at last pos that contains maxK # start: pos of previous invalid number (namely > maxK or < minK) kmin, kmax, start = 0, 0, -1 for i, num in enumerate(nums): if num < minK or num > maxK: kmin, kmax, start = 0, 0, i else: if num == minK: kmin = i - start if num == maxK: kmax = i - start ans += min(kmin, kmax) return ans
count-subarrays-with-fixed-bounds
[Python3] O(N) dp solution
caijun
0
26
count subarrays with fixed bounds
2,444
0.432
Hard
33,505
https://leetcode.com/problems/count-subarrays-with-fixed-bounds/discuss/2708344/Sliding-Window-with-Explanation-oror-O(N)-time
class Solution: def countSubarrays(self, nums: List[int], minK: int, maxK: int) -> int: i = 0 # left index j = 0 # right index ans = 0 minn = [] # store the indices of minK in a window which have no element less than minK and greater than maxK maxx = [] # store the indices of maxK in a window which have no element less than minK and greater than maxK while j<len(nums): if nums[j]==minK: minn.append(j) if nums[j]==maxK: maxx.append(j) if nums[j]<minK or nums[j]>maxK: # conflict a,b = 0,0 # indices of minn and maxx array while a<len(minn) and b<len(maxx): m = max(minn[a],maxx[b]) # max index which should keep in subbarray necessarily ans+=j-m # add how many subarray can create such that they start from nums[i] if nums[i]==minK: a+=1 if nums[i]==maxK: b+=1 i+=1 # there is a conflict on indix j so clear minn and maxx array minn.clear() maxx.clear() i = j+1 # set left pointer to j+1 (searching for new window which can start from j+1) j+=1 # after reaching j on last indix check if there is a window which is already created a,b = 0,0 while a<len(minn) and b<len(maxx): m = max(minn[a],maxx[b]) ans+=j-m if nums[i]==minK: a+=1 if nums[i]==maxK: b+=1 i+=1 return ans
count-subarrays-with-fixed-bounds
Sliding Window with Explanation || O(N) time
Laxman_Singh_Saini
0
42
count subarrays with fixed bounds
2,444
0.432
Hard
33,506
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2744018/Python-Elegant-and-Short
class Solution: """ Time: O(1) Memory: O(1) """ def haveConflict(self, a: List[str], b: List[str]) -> bool: a_start, a_end = a b_start, b_end = b return b_start <= a_start <= b_end or \ b_start <= a_end <= b_end or \ a_start <= b_start <= a_end or \ a_start <= b_end <= a_end
determine-if-two-events-have-conflict
Python Elegant & Short
Kyrylo-Ktl
3
79
determine if two events have conflict
2,446
0.494
Easy
33,507
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2774277/Easy-Python-Solution
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: e1s=int(event1[0][:2])*60 + int(event1[0][3:]) e1e=int(event1[1][:2])*60 + int(event1[1][3:]) e2s=int(event2[0][:2])*60 + int(event2[0][3:]) e2e=int(event2[1][:2])*60 + int(event2[1][3:]) if e1s<=e2s<=e1e: return True if e2s<=e1s<=e2e: return True if e1s<=e2e<=e1e: return True if e2s<=e1e<=e2e: return True else: return False
determine-if-two-events-have-conflict
Easy Python Solution
Vistrit
2
54
determine if two events have conflict
2,446
0.494
Easy
33,508
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734341/Python3-1-line
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: return event1[0] <= event2[0] <= event1[1] or event2[0] <= event1[0] <= event2[1]
determine-if-two-events-have-conflict
[Python3] 1-line
ye15
2
70
determine if two events have conflict
2,446
0.494
Easy
33,509
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734202/Python3-Straight-Forward-Clean-and-Concise
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: start1 = int(event1[0][:2]) * 60 + int(event1[0][3:]) end1 = int(event1[1][:2]) * 60 + int(event1[1][3:]) start2 = int(event2[0][:2]) * 60 + int(event2[0][3:]) end2 = int(event2[1][:2]) * 60 + int(event2[1][3:]) return True if start1 <= start2 <= end1 or start2 <= start1 <= end2 else False
determine-if-two-events-have-conflict
[Python3] Straight-Forward, Clean & Concise
xil899
1
82
determine if two events have conflict
2,446
0.494
Easy
33,510
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734106/Simple-and-Easy-2-linesPython
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: arr = [[(int(event1[0][:2])*60)+int(event1[0][3:]) , (int(event1[1][:2])*60)+int(event1[1][3:])] , [(int(event2[0][:2])*60)+int(event2[0][3:]) , (int(event2[1][:2])*60)+int(event2[1][3:])]] return (arr[0][0] <= arr[1][1] <= arr[0][1] or arr[1][0] <= arr[0][1] <= arr[1][1])
determine-if-two-events-have-conflict
Simple and Easy 2 lines[Python]
CoderIsCodin
1
39
determine if two events have conflict
2,446
0.494
Easy
33,511
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2843230/Python3-Convert-to-minutes
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: def to_minutes(s): return int(s[:2])*60 + int(s[3:]) e1 = (to_minutes(event1[0]), to_minutes(event1[1])) e2 = (to_minutes(event2[0]), to_minutes(event2[1])) return e1[0] in range(e2[0],e2[1]+1) or e2[0] in range(e1[0],e1[1]+1)
determine-if-two-events-have-conflict
Python3 Convert to minutes
bettend
0
3
determine if two events have conflict
2,446
0.494
Easy
33,512
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2817649/My-solution-with-35ms
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: start1 = int(event1[0].replace(':','')) end1 = int(event1[1].replace(':','')) start2 = int(event2[0].replace(':','')) end2 = int(event2[1].replace(':','')) if end1 < start2 or end2 < start1: return False else: return True
determine-if-two-events-have-conflict
My solution with 35ms
letrungkienhd1308
0
6
determine if two events have conflict
2,446
0.494
Easy
33,513
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2780012/One-line-Python-Code
class Solution: def haveConflict(self, e1: List[str], e2: List[str]) -> bool: return e1[0] <= e2[0] <= e1[1] or e2[0] <= e1[0] <= e2[1]
determine-if-two-events-have-conflict
One line Python Code
dnvavinash
0
10
determine if two events have conflict
2,446
0.494
Easy
33,514
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2751301/Convert-to-minutes
class Solution: def haveConflict(self, e1: List[str], e2: List[str]) -> bool: return ((int(e1[0][:2]) * 60 + int(e1[0][3:])) <= (int(e2[1][:2]) * 60 + int(e2[1][3:])) and (int(e2[0][:2]) * 60 + int(e2[0][3:])) <= (int(e1[1][:2]) * 60 + int(e1[1][3:])))
determine-if-two-events-have-conflict
Convert to minutes
EvgenySH
0
10
determine if two events have conflict
2,446
0.494
Easy
33,515
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2749816/Python-easy-solution
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: st1=int(''.join(list(event1[0].split(":")))) et1=int(''.join(list(event1[1].split(":")))) st2=int(''.join(list(event2[0].split(":")))) et2=int(''.join(list(event2[1].split(":")))) if st1>=st2 and et2>=st1: return True elif st2>=st1 and et1>=st2: return True return False
determine-if-two-events-have-conflict
Python easy solution
AviSrivastava
0
12
determine if two events have conflict
2,446
0.494
Easy
33,516
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2735859/Python-one-liner
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: return not (event1[1] < event2[0] or event2[1] < event1[0])
determine-if-two-events-have-conflict
Python, one liner
blue_sky5
0
14
determine if two events have conflict
2,446
0.494
Easy
33,517
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2735209/Python-3-or-One-Liner-or-Easy
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: return (event1[0]<=event2[0] and event1[1]>=event2[0]) or (event1[0]>=event2[0] and event2[1]>=event1[0])
determine-if-two-events-have-conflict
Python 3 | One Liner | Easy
RickSanchez101
0
11
determine if two events have conflict
2,446
0.494
Easy
33,518
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734685/Python3
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: hour1a, minute1a = map(int, event1[0].split(':')) hour1b, minute1b = map(int, event1[1].split(':')) hour2a, minute2a = map(int, event2[0].split(':')) hour2b, minute2b = map(int, event2[1].split(':')) if hour2a == hour1a or hour2b == hour1b: return True if hour2a == hour1b: if minute2a <= minute1b: return True else: return False if hour2b == hour1a: if minute2b >= minute1a: return True else: return False for hh in range(hour2a, hour2b + 1): if hour1a <= hh <= hour1b: return True return False
determine-if-two-events-have-conflict
Python3
mediocre-coder
0
6
determine if two events have conflict
2,446
0.494
Easy
33,519
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734558/Python3-cast-time-to-minutes
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: def helper(time): hour, minute = int(time[:2]), int(time[3:]) return hour*60 + minute event1 = [helper(x) for x in event1] event2 = [helper(x) for x in event2] if event1[0] <= event2[0]: return event1[1] >= event2[0] else: return event2[1] >= event1[0]
determine-if-two-events-have-conflict
Python3 cast time to minutes
xxHRxx
0
10
determine if two events have conflict
2,446
0.494
Easy
33,520
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734527/Python-O(1)TC-solution
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: if event2[1]>=event1[0]: if event2[0]<=event1[1]: return True return False
determine-if-two-events-have-conflict
Python O(1)TC solution
sundram_somnath
0
4
determine if two events have conflict
2,446
0.494
Easy
33,521
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734362/Easy-Python3-code-with-explanation
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: a=int(event1[0][0]+event1[0][1]+event1[0][3]+event1[0][4]) b=int(event1[1][0]+event1[1][1]+event1[1][3]+event1[1][4]) c=int(event2[0][0]+event2[0][1]+event2[0][3]+event2[0][4]) d=int(event2[1][0]+event2[1][1]+event2[1][3]+event2[1][4]) return not(b<c or d<a)
determine-if-two-events-have-conflict
Easy Python3 code with explanation
shreyasjain0912
0
8
determine if two events have conflict
2,446
0.494
Easy
33,522
https://leetcode.com/problems/determine-if-two-events-have-conflict/discuss/2734298/EASY-PYTHON-SOLUTION-USING-IF-LOOP
class Solution: def haveConflict(self, event1: List[str], event2: List[str]) -> bool: if event1[1][0:2]==event2[0][0:2]: if event1[1][3:5]>=event2[0][3:5]: return True else: return False else: if event1[1][0:2]<event2[0][0:2] or event2[1][0:2]<event1[0][0:2]: return False elif event1[1][0:2]>event2[0][0:2]: return True
determine-if-two-events-have-conflict
EASY PYTHON SOLUTION USING IF LOOP
sowmika_chaluvadi
0
11
determine if two events have conflict
2,446
0.494
Easy
33,523
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734224/Python3-Brute-Force-%2B-Early-Stopping-Clean-and-Concise
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: n = len(nums) ans = 0 for i in range(n): temp = nums[i] for j in range(i, n): temp = math.gcd(temp, nums[j]) if temp == k: ans += 1 elif temp < k: break return ans
number-of-subarrays-with-gcd-equal-to-k
[Python3] Brute Force + Early Stopping, Clean & Concise
xil899
4
423
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,524
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2835238/Python-(Simple-Maths)
class Solution: def subarrayGCD(self, nums, k): n, count = len(nums), 0 for i in range(n): ans = nums[i] for j in range(i,n): ans = math.gcd(ans,nums[j]) if ans == k: count += 1 elif ans < k: break return count
number-of-subarrays-with-gcd-equal-to-k
Python (Simple Maths)
rnotappl
0
1
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,525
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2814449/2447.-Number-of-Subarrays-With-GCD-Equal-to-K-oror-Python3-oror-GCD-Recursive
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: c=0 for i in range(len(nums)): a=nums[i] for j in range(i,len(nums)): a=gcd(a,nums[j]) if a==k: c+=1 return c def gcd(a,b): if b==0: return abs(a) else: return gcd(b,a%b)
number-of-subarrays-with-gcd-equal-to-k
2447. Number of Subarrays With GCD Equal to K || Python3 || GCD Recursive
shagun_pandey
0
6
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,526
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2737230/Python3-or-Easy-Solution
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: n = len(nums) i = 0;j = 0;ans = 0 while(i<n): #print(gcd) gcd = nums[i] for j in range(i,n): gcd = GCD(nums[j],gcd) if(gcd==k): ans+=1 elif(gcd<k): break i+=1 return ans def GCD(a,b): if(b==0): return a else: return GCD(b,a%b)
number-of-subarrays-with-gcd-equal-to-k
Python3 | Easy Solution
ty2134029
0
26
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,527
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734815/number-of-subarrays-with-gcd-equal-to-k
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: c=0 for i in range(len(nums)): temp=nums[i] if temp==k: c=c+1 for j in range(i+1,len(nums)): temp=math.gcd(temp,nums[j]) if temp==k: c=c+1 return c
number-of-subarrays-with-gcd-equal-to-k
number-of-subarrays-with-gcd-equal-to-k
meenu155
0
14
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,528
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734764/Understandable-Python-Solution
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: count = 0 n=len(nums) for i in range(n): curr = 0 for j in range(i,n): curr = math.gcd(curr,nums[j]) # You can use math.gcd or gcd. Both will work. if(curr == k): count += 1 return count
number-of-subarrays-with-gcd-equal-to-k
Understandable Python Solution
Ayush_Kumar27
0
15
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,529
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734690/Python3-Brute-Force-with-a-little-optimization
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: def gcd(x, y): while y: x, y = y, x % y return x candidates = [_ % k for _ in nums] factor = [_ //k for _ in nums] segments = [] start = 0 inside = False while start < len(nums): if candidates[start] == 0: if not inside: inside = True segments.append(start) else: if inside: segments.append(start-1) inside = False start += 1 if len(segments) % 2 == 1: segments.append(len(nums)-1) res = 0 for i in range(len(segments) // 2): start, end = segments[i*2], segments[i*2+1] for t in range(start, end+1): temp_gcd = factor[t] for k in range(t, end+1): temp_gcd = gcd(temp_gcd, factor[k]) if temp_gcd == 1: res += (end - k + 1) break return res
number-of-subarrays-with-gcd-equal-to-k
Python3 Brute Force with a little optimization
xxHRxx
0
3
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,530
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734418/simple-python-solution
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: def find_gcd(x, y): while(y): x, y = y, x % y return x res=0 for i in range(len(nums)): gcd=nums[i] for j in range(i,len(nums)): gcd=find_gcd(gcd,nums[j]) print(gcd) if gcd==k: res+=1 return res
number-of-subarrays-with-gcd-equal-to-k
simple python solution
sundram_somnath
0
8
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,531
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734380/Python3-brute-force
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: ans = 0 for i in range(len(nums)): g = 0 for j in range(i, len(nums)): g = gcd(g, nums[j]) if g == k: ans += 1 return ans
number-of-subarrays-with-gcd-equal-to-k
[Python3] brute-force
ye15
0
7
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,532
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734194/Easy-Python3-Solution
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: def gcd(a,b): while b: a,b=b,a%b return a ans=0 for i in range(0,len(nums)): g=0 for j in range(i,len(nums)): g=gcd(g,nums[j]) if g==k: ans+=1 return ans
number-of-subarrays-with-gcd-equal-to-k
Easy Python3 Solution
shreyasjain0912
0
31
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,533
https://leetcode.com/problems/number-of-subarrays-with-gcd-equal-to-k/discuss/2734144/Python-or-brute-force
class Solution: def subarrayGCD(self, nums: List[int], k: int) -> int: def gcd(n1, n2): if n2==0: return n1 return gcd(n2, n1%n2) ans = 0 n = len(nums) for i in range(n): curr_gcd = 0 for j in range(i, n): curr_gcd = gcd(curr_gcd, nums[j]) if curr_gcd == k: ans += 1 return ans
number-of-subarrays-with-gcd-equal-to-k
Python | brute force
diwakar_4
0
13
number of subarrays with gcd equal to k
2,447
0.482
Medium
33,534
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734183/Python3-Weighted-Median-O(NlogN)-with-Explanations
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: arr = sorted(zip(nums, cost)) total, cnt = sum(cost), 0 for num, c in arr: cnt += c if cnt > total // 2: target = num break return sum(c * abs(num - target) for num, c in arr)
minimum-cost-to-make-array-equal
[Python3] Weighted Median O(NlogN) with Explanations
xil899
109
2,300
minimum cost to make array equal
2,448
0.346
Hard
33,535
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734625/DP-Solution.-Intuitive-and-Clear-or-Python
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: n = len(nums) # Sort by nums arr = sorted((nums[i], cost[i]) for i in range(n)) nums = [i[0] for i in arr] cost = [i[1] for i in arr] # Compute DP left to right left2right = [0] * n curr = cost[0] for i in range(1, n): left2right[i] = left2right[i - 1] + (nums[i] - nums[i - 1]) * curr curr += cost[i] # Compute DP right to left right2left = [0] * n curr = cost[-1] for i in range(n - 2, -1, -1): right2left[i] = right2left[i + 1] + (nums[i + 1] - nums[i]) * curr curr += cost[i] return min(left2right[i] + right2left[i] for i in range(n))
minimum-cost-to-make-array-equal
DP Solution. Intuitive and Clear | Python
alex391a
29
893
minimum cost to make array equal
2,448
0.346
Hard
33,536
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734089/Python-C%2B%2B-or-Binary-search-or-Clean-solution
class Solution: def calculateSum(self, nums, cost, target): res = 0 for n, c in zip(nums, cost): res += abs(n - target) * c return res def minCost(self, nums: List[int], cost: List[int]) -> int: s, e = min(nums), max(nums) while s < e: mid = (s + e) // 2 leftSum, rightSum = self.calculateSum(nums, cost, mid), self.calculateSum(nums, cost, mid + 1) if leftSum < rightSum: e = mid else: s = mid + 1 return self.calculateSum(nums, cost, s)
minimum-cost-to-make-array-equal
Python, C++ | Binary search | Clean solution
alexnik42
10
518
minimum cost to make array equal
2,448
0.346
Hard
33,537
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734499/Python3-Ternary-Search-or-O(NlogN)
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: def cnt(t): #function for calculating cost for Target "t" cur = cur_prev = cur_nxt = 0 #initialize the cost counting for i, el in enumerate(nums): cur += abs(el-t) * cost[i] #update the cost for target "t" cur_prev += abs(el-(t-1)) * cost[i] #update the cost for target "t-1" cur_nxt += abs(el-(t+1)) * cost[i] #update the cost for target "t+1" return cur, cur_prev, cur_nxt l, r = min(nums), max(nums) #lower and upper bound for searching ans = float('inf') while l <= r: m = (l+r) // 2 cur, cur_prev, cur_nxt = cnt(m) #call the counting function for target "m" if cur_prev >= cur <= cur_nxt: #if "m" if efficient than both "m-1" and "m+1" then cost for m is the ans return cur #update to efficient segment if cur_prev > cur_nxt: l = m+1 else: r = m-1 return cur
minimum-cost-to-make-array-equal
[Python3] Ternary Search | O(NlogN)
Parag_AP
2
30
minimum cost to make array equal
2,448
0.346
Hard
33,538
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734506/Python3-Sorting-%2B-Prefix_sum-and-postfix_sum-for-cost-O(nlogn)-Solution
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: n = len(nums) pairs = sorted(zip(nums, cost)) if pairs[0][0] == pairs[-1][0]: return 0 post_sum = [0] * (n + 1) res = 0 for i in range(n - 1, -1, -1): post_sum[i] = pairs[i][1] + post_sum[i + 1] res += (pairs[i][0] - pairs[0][0]) * pairs[i][1] pre_sum = pairs[0][1] for i in range(1, n): if pre_sum > post_sum[i]: return res diff = pairs[i][0] - pairs[i - 1][0] res -= (post_sum[i] - pre_sum) * diff pre_sum += pairs[i][1] return res
minimum-cost-to-make-array-equal
[Python3] Sorting + Prefix_sum and postfix_sum for cost, O(nlogn) Solution
celestez
1
43
minimum cost to make array equal
2,448
0.346
Hard
33,539
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734299/Python-3oror-Time%3A-3204-ms-Space%3A-42.6-MB
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: n=len(nums) pre=[0 for i in range(n)] suff=[0 for i in range(n)] z=list(zip(nums,cost)) z.sort() t=z[0][1] for i in range(1,n): pre[i]=pre[i-1]+(t*abs(z[i][0]-z[i-1][0])) t+=z[i][1] t=z[-1][1] for i in range(n-2,-1,-1): suff[i]=suff[i+1]+(t*abs(z[i][0]-z[i+1][0])) t+=z[i][1] ans=float('inf') for i in range(n): ans=min(ans,suff[i]+pre[i]) return ans
minimum-cost-to-make-array-equal
Python 3|| Time: 3204 ms , Space: 42.6 MB
koder_786
1
21
minimum cost to make array equal
2,448
0.346
Hard
33,540
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2786257/python-two-pointer
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: d = defaultdict(int) for i,num in enumerate(nums): d[num]+=cost[i] arr = [[key,val] for key,val in d.items()] arr.sort() res, i, j = 0, 0, len(arr)-1 while i<j: if arr[i][1]<=arr[j][1]: res+=arr[i][1]*(arr[i+1][0]-arr[i][0]) arr[i+1][1]+=arr[i][1] i+=1 else: res+=arr[j][1]*(arr[j][0]-arr[j-1][0]) arr[j-1][1]+=arr[j][1] j-=1 return res
minimum-cost-to-make-array-equal
python two pointer
Jeremy0923
0
6
minimum cost to make array equal
2,448
0.346
Hard
33,541
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2741476/python3-Prefix-calculation-increment-and-decrement-sol-for-reference.
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: N = len(nums) nc = sorted(zip(nums, cost)) inc = [0]*N dec = [0]*N rolling = nc[0][1] for i in range(1,N): inc[i] = ((nc[i][0]-nc[i-1][0])*rolling) + inc[i-1] rolling += nc[i][1] ans = inc[-1] rolling = nc[-1][1] for i in range(N-2,-1,-1): dec[i] = ((nc[i+1][0]-nc[i][0])*rolling) + dec[i+1] rolling += nc[i][1] if (inc[i] + dec[i]) < ans: ans = inc[i] + dec[i] return ans
minimum-cost-to-make-array-equal
[python3] Prefix calculation increment and decrement sol for reference.
vadhri_venkat
0
8
minimum cost to make array equal
2,448
0.346
Hard
33,542
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2740399/sorting-with-explanation
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: # sort nums and cost by nums cost = [x for _, x in sorted(zip(nums, cost))] nums = sorted(nums) # suppose x is the average: # while nums[0]<=x<=nums[1]: # min cost = x*cost[0] - nums[0]*cost[0] + # -x*(cost[1:end]) + (nums[1]*cost[1] + ... + nums[end]*cost[end]) # = x*(cost[0]-cost[1:end]) + fixed number # => x = nums[0] or nums[1] l = len(nums) pre_nums = [0]*l s = sum(cost) a = 0 num_cost = [0]*l for i in range(l): a += cost[i] s -= cost[i] pre_nums[i] = a - s num_cost[i] = nums[i]*cost[i] s = sum(num_cost) a = 0 pre_num_cost = [0]*l for i in range(l): a += num_cost[i] s -= num_cost[i] pre_num_cost[i] = s - a ans = nums[0]*pre_nums[0] + pre_num_cost[0] for i in range(1,l): x = nums[i]*pre_nums[i] + pre_num_cost[i] ans = x if x<ans else ans return ans
minimum-cost-to-make-array-equal
sorting with explanation
nuya
0
6
minimum cost to make array equal
2,448
0.346
Hard
33,543
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2737125/Python-3-or-prefix-sum-or-O(nlogn)O(n)
class Solution: def minCost(self, nums: List[int], costs: List[int]) -> int: sortedNums = sorted(zip(nums, costs)) costsPrefix, costsSuffix = 0, sum(costs) numsCost = res = sum(num * cost for num, cost in sortedNums) for num, cost in sortedNums: numsCost -= 2 * num * cost costsPrefix += cost costsSuffix -= cost res = min(res, numsCost + (costsPrefix - costsSuffix)*num) return res
minimum-cost-to-make-array-equal
Python 3 | prefix sum | O(nlogn)/O(n)
dereky4
0
22
minimum cost to make array equal
2,448
0.346
Hard
33,544
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2736676/PYTHON-or-MEDIAN-or-O(NlogN)-SOLUTION-or-CLEAN-CODE
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: n=sum(cost) arr=[] for i in range(len(nums)): arr.append((nums[i],cost[i])) arr=sorted(arr) index=n//2 # print(index) curr=0 x=nums[0] for i in range(len(arr)): el,count=arr[i] if curr+count<index: curr+=count else: x=arr[i][0] # print(x,i,"puppy") break ans=0 for i in range(len(nums)): ans+=cost[i]*(abs(x-nums[i])) return ans
minimum-cost-to-make-array-equal
PYTHON | MEDIAN | O(NlogN) SOLUTION | CLEAN CODE
VISHNU_Mali
0
12
minimum cost to make array equal
2,448
0.346
Hard
33,545
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2736111/Python3-prefix-and-suffix-sum-solution
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: data = [(x,y) for x, y in zip(nums, cost)] data.sort(key = lambda x : x[0]) prefix = [] suffix = [] start = 0 for _, cost in data: start += cost prefix.append(start) start = 0 for _, cost in data[::-1]: start += cost suffix.append(start) suffix = suffix[::-1] mini = sys.maxsize index = None current = 0 for i in range(len(nums)-1): src, tar = data[i][0], data[i+1][0] current += (-suffix[i+1] + prefix[i])*(tar - src) #print (current) if current < mini: mini = current index = i target = data[index+1][0] res = 0 for num, cost in data: res += (abs(num - target)*cost) return res
minimum-cost-to-make-array-equal
Python3 prefix and suffix sum solution
xxHRxx
0
7
minimum cost to make array equal
2,448
0.346
Hard
33,546
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2735353/Python-oror-fastest-oror-easy-to-understand-using-prefixSum-and-sorting
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: def find_cost(target): totalCost = 0 for i in range(len(nums)): totalCost += abs(nums[i] - target) * cost[i] return totalCost pairs = sorted(zip(nums, cost)) prefixCost = [0] for pair in pairs: prefixCost.append(prefixCost[-1] + pair[1]) currentCost = find_cost(pairs[0][0]) answer = currentCost for i in range(1, len(nums)): diff = pairs[i][0] - pairs[i-1][0] left = diff * prefixCost[i] right = diff * (prefixCost[-1] - prefixCost[i]) currentCost = currentCost + left - right answer = min(answer, currentCost) return answer
minimum-cost-to-make-array-equal
Python || fastest || easy to understand using prefixSum and sorting
Yared_betsega
0
21
minimum cost to make array equal
2,448
0.346
Hard
33,547
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734903/Python-Brute-Force-If-you-didn't-realize-this-is-convex-problem-we-can-still-do-it!
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: import collections start, end = min(nums), max(nums) pluscost = 0 currentcost = 0 d = collections.defaultdict(list) for idx, i in enumerate(nums): d[i].append(idx) currentcost += (i - start) * cost[idx] if i == start: pluscost += cost[idx] else: pluscost -= cost[idx] # intialize best_cost = currentcost # for i in range(start+1, end+1) will give you TLE, guess # leetcode OJ uses total time to judge but not same time budget # for each test case for i in sorted(d.keys())[1:]: currentcost += pluscost * (i - start) start = i best_cost = min(best_cost, currentcost) # if len(d[i]) != 0: for idx in d[i]: pluscost += 2 * cost[idx] return best_cost
minimum-cost-to-make-array-equal
[Python] Brute Force - If you didn't realize this is convex problem we can still do it!
A_Pinterest_Employee
0
13
minimum cost to make array equal
2,448
0.346
Hard
33,548
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734817/Python3-or-Prefix-and-Suffix-Sum
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: n=len(nums) arr=sorted(list(zip(nums,cost))) prefix=[0]*n suffix=[0]*n prefix[0]=arr[0][1] suffix[n-1]=arr[n-1][1] currCost,ans=0,float('inf') for i in range(1,n): prefix[i]=prefix[i-1]+arr[i][1] for i in range(n-2,-1,-1): suffix[i]=suffix[i+1]+arr[i][1] for i in range(1,n): currCost+=(arr[i][0]-arr[0][0])*arr[i][1] for i in range(1,n): diff=arr[i][0]-arr[i-1][0] currCost=currCost-diff*suffix[i]+diff*prefix[i-1] ans=min(ans,currCost) return ans
minimum-cost-to-make-array-equal
[Python3] | Prefix and Suffix Sum
swapnilsingh421
0
19
minimum cost to make array equal
2,448
0.346
Hard
33,549
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734383/Python3-Binary-Search
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: def get_cost(t): return sum([abs(num-t)*c for (num, c) in zip(nums, cost)]) l, r = min(nums), max(nums) while l < r: mid = (l+r)//2 if get_cost(mid) <= get_cost(mid+1): r = mid else: l = mid+1 return get_cost(l)
minimum-cost-to-make-array-equal
[Python3] Binary Search
teyuanliu
0
11
minimum cost to make array equal
2,448
0.346
Hard
33,550
https://leetcode.com/problems/minimum-cost-to-make-array-equal/discuss/2734356/Python3-Median
class Solution: def minCost(self, nums: List[int], cost: List[int]) -> int: nums, cost = zip(*sorted(zip(nums, cost))) total = sum(cost) prefix = 0 for i, x in enumerate(cost): prefix += x if prefix > total//2: break return sum(c*abs(x-nums[i]) for x, c in zip(nums, cost))
minimum-cost-to-make-array-equal
[Python3] Median
ye15
0
19
minimum cost to make array equal
2,448
0.346
Hard
33,551
https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/discuss/2734139/Python-or-Simple-OddEven-Sorting-O(nlogn)-or-Walmart-OA-India-or-Simple-Explanation
class Solution: def makeSimilar(self, A: List[int], B: List[int]) -> int: if sum(A)!=sum(B): return 0 # The first intuition is that only odd numbers can be chaged to odd numbers and even to even hence separate them # Now minimum steps to making the target to highest number in B is by converting max of A to max of B similarily # every number in A can be paired with a number in B by index hence sorting # now we need only the number of positives or number of negatives. oddA,evenA=[i for i in A if i%2],[i for i in A if i%2==0] oddB,evenB=[i for i in B if i%2],[i for i in B if i%2==0] oddA.sort(),evenA.sort() oddB.sort(),evenB.sort() res=0 for i,j in zip(oddA,oddB): if i>=j: res+=i-j for i,j in zip(evenA,evenB): if i>=j: res+=i-j return res//2
minimum-number-of-operations-to-make-arrays-similar
Python | Simple Odd/Even Sorting O(nlogn) | Walmart OA India | Simple Explanation
tarushfx
3
245
minimum number of operations to make arrays similar
2,449
0.649
Hard
33,552
https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/discuss/2737259/Python3-One-Liner-Sort
class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: return sum(map(lambda p:abs(p[1]-p[0]), zip(list(sorted([i + 10**9 * (i%2) for i in nums])), list(sorted([j + 10**9 * (j%2) for j in target])))))>>2
minimum-number-of-operations-to-make-arrays-similar
Python3 One Liner - Sort
godshiva
0
9
minimum number of operations to make arrays similar
2,449
0.649
Hard
33,553
https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/discuss/2736557/Easy-solution-using-odd-even-and-sorting
class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: nums.sort() target.sort() res=0 numseven=[] numsodd=[] targeteven=[] targetodd=[] for i in nums: if i%2==0: numseven.append(i) else: numsodd.append(i) for i in target: if i%2==0: targeteven.append(i) else: targetodd.append(i) for i in range(len(numseven)): if numseven[i]-targeteven[i]>0: res+=numseven[i]-targeteven[i] for i in range(len(numsodd)): if numsodd[i]-targetodd[i]>0: res+=numsodd[i]-targetodd[i] return res//2
minimum-number-of-operations-to-make-arrays-similar
Easy solution using odd, even and sorting
sundram_somnath
0
14
minimum number of operations to make arrays similar
2,449
0.649
Hard
33,554
https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/discuss/2735773/Python-oror-heap-oror-evenodd-separately
class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: evenNums = [] evenTargets = [] oddNums = [] oddTargets = [] for num, tar in zip(nums, target): evenNums.append(num) if not num &amp; 1 else oddNums.append(num) evenTargets.append(tar) if not tar &amp; 1 else oddTargets.append(tar) heapify(evenNums) heapify(evenTargets) answer = 0 while evenNums: first, second = heappop(evenNums), heappop(evenTargets) if first > second: answer += first - second heapify(oddNums) heapify(oddTargets) while oddNums: first, second = heappop(oddNums), heappop(oddTargets) if first > second: answer += first - second return answer // 2 # time and space complexity # time: O(nlog(n)) # space: O(n)
minimum-number-of-operations-to-make-arrays-similar
Python || heap || even/odd separately
Yared_betsega
0
11
minimum number of operations to make arrays similar
2,449
0.649
Hard
33,555
https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/discuss/2734657/JavaPython3-or-Separating-even-and-odd-or-Sorting
class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: nums.sort() target.sort() evenNums,oddNums=[],[] evenTarget,oddTarget=[],[] n=len(nums) for i in range(n): if nums[i]%2==0: evenNums.append(nums[i]) else: oddNums.append(nums[i]) if target[i]%2==0: evenTarget.append(target[i]) else: oddTarget.append(target[i]) ans=0 for i in range(len(evenNums)): ans+=abs(evenNums[i]-evenTarget[i])//2 for i in range(len(oddNums)): ans+=abs(oddNums[i]-oddTarget[i])//2 return ans//2
minimum-number-of-operations-to-make-arrays-similar
[Java/Python3] | Separating even and odd | Sorting
swapnilsingh421
0
16
minimum number of operations to make arrays similar
2,449
0.649
Hard
33,556
https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/discuss/2734440/Python3-Sorting
class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: nums.sort() target.sort() nums_even_odd = [[num for num in nums if num%2 == 0], [num for num in nums if num%2 == 1]] target_even_odd = [[num for num in target if num%2 == 0], [num for num in target if num%2 == 1]] num_addition = 0 for i in range(len(nums_even_odd)): ns, ts = nums_even_odd[i], target_even_odd[i] for (n, t) in zip(ns, ts): if n >= t: num_addition += (n-t)//2 return num_addition
minimum-number-of-operations-to-make-arrays-similar
[Python3] Sorting
teyuanliu
0
15
minimum number of operations to make arrays similar
2,449
0.649
Hard
33,557
https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/discuss/2734371/Python3-parity
class Solution: def makeSimilar(self, nums: List[int], target: List[int]) -> int: ne = sorted(x for x in nums if not x&amp;1) no = sorted(x for x in nums if x&amp;1) te = sorted(x for x in target if not x&amp;1) to = sorted(x for x in target if x&amp;1) return (sum(abs(x-y) for x, y in zip(ne, te)) + sum(abs(x-y) for x, y in zip(no, to)))//4
minimum-number-of-operations-to-make-arrays-similar
[Python3] parity
ye15
0
12
minimum number of operations to make arrays similar
2,449
0.649
Hard
33,558
https://leetcode.com/problems/odd-string-difference/discuss/2774188/Easy-to-understand-python-solution
class Solution: def oddString(self, words: List[str]) -> str: k=len(words[0]) arr=[] for i in words: l=[] for j in range(1,k): diff=ord(i[j])-ord(i[j-1]) l.append(diff) arr.append(l) for i in range(len(arr)): if arr.count(arr[i])==1: return words[i]
odd-string-difference
Easy to understand python solution
Vistrit
2
87
odd string difference
2,451
0.595
Easy
33,559
https://leetcode.com/problems/odd-string-difference/discuss/2844752/Python3-Builtin-Party
class Solution: def oddString(self, words: List[str]) -> str: # go through all of the words find and track all the diffs cn = collections.defaultdict(list) for idx, word in enumerate(words): # get the difference array diff_arr = Solution.difference_array(word) # append to the counter cn[diff_arr].append(idx) # get the searched element ele = min(cn.values(), key=len) return words[ele[0]] @staticmethod def difference_array(word: str): return tuple(map(lambda x: ord(word[x[0]]) - ord(x[1]), zip(range(1,len(word)), word[:-1])))
odd-string-difference
[Python3] - Builtin-Party
Lucew
0
2
odd string difference
2,451
0.595
Easy
33,560
https://leetcode.com/problems/odd-string-difference/discuss/2826031/Python-Simple-Solution-With-No-Hashmaps-and-EarlyStopping-(O(1)-Memory-and-O(N2)-Average-Runtime
class Solution: def oddString(self, words: List[str]) -> str: def getDiffArray(word): return [ord(word[i+1]) - ord(word[i]) for i in range(len(word) - 1)] diff1 = getDiffArray(words[0]) diff2 = getDiffArray(words[1]) for word in words[2:]: curDiff = getDiffArray(word) if curDiff != diff1 and curDiff != diff2: return word elif curDiff != diff1: return words[0] elif curDiff != diff2: return words[1]
odd-string-difference
[Python] Simple Solution With No Hashmaps and EarlyStopping (O(1) Memory and O(N/2) Average Runtime
dumbitdownJr
0
3
odd string difference
2,451
0.595
Easy
33,561
https://leetcode.com/problems/odd-string-difference/discuss/2809208/Python3-beats-97.13-using-defaultdict
class Solution: def oddString(self, words): d = defaultdict(list) for w in words: f = [ord(w[i+1])-ord(w[i]) for i in range(len(w)-1)] d[tuple(f)].append(w) for x in d: if len(d[x])==1: return d[x][0]
odd-string-difference
[Python3] beats 97.13% using defaultdict
U753L
0
9
odd string difference
2,451
0.595
Easy
33,562
https://leetcode.com/problems/odd-string-difference/discuss/2797704/Python3-34ms-13.9MB-Easy-to-read-solution
class Solution: def oddString(self, words: List[str]) -> str: # input: list of words with equal len # use ord(char) - 97 to get num for each char # then, we calculate each word element first through for loop # then we compare between each list element final_list = [] for i in range(len(words)): diff_list = [] for j in range(len(words[0]) - 1): diff_list.append(ord(words[i][j+1]) - ord(words[i][j])) final_list.append(diff_list) if str(final_list[0]) != str(final_list[1]): if str(final_list[0]) == str(final_list[2]): return words[1] elif str(final_list[1]) == str(final_list[2]): return words[0] else: for i in range(2, len(final_list)): if str(final_list[0]) != str(final_list[i]): return words[i]
odd-string-difference
[Python3] 34ms / 13.9MB - Easy-to-read solution
phucnguyen290198
0
8
odd string difference
2,451
0.595
Easy
33,563
https://leetcode.com/problems/odd-string-difference/discuss/2785999/Python-(Simple-Maths)
class Solution: def dfs(self,word): res = [] for i in range(1,len(word)): res.append(ord(word[i]) - ord(word[i-1])) return res def oddString(self, words): dict1 = defaultdict(list) for i in words: dict1[tuple(self.dfs(i))].append(i) for i in dict1: if len(dict1[i]) == 1: return dict1[i][0]
odd-string-difference
Python (Simple Maths)
rnotappl
0
9
odd string difference
2,451
0.595
Easy
33,564
https://leetcode.com/problems/odd-string-difference/discuss/2764216/odd-string-difference
class Solution: def oddString(self, words: List[str]) -> str: #print(ord('z')-96) #words = ["adc","wzy","abc"] mp=dict() for i in range(len(words)): diff=[] for j in range(len(words[i])-1): diff.append((ord(words[i][j+1])-96)-(ord(words[i][j])-96)) t=tuple(diff)#list converted to tuple so that we can map it into key part as list is unhasable so tuple is used as key if t not in mp: mp[t]=[words[i]] else: mp[t].append(words[i]) for val in mp.values(): if len(val)==1: #print(val[0]) return val[0] return -1
odd-string-difference
odd string difference
shivansh2001sri
0
11
odd string difference
2,451
0.595
Easy
33,565
https://leetcode.com/problems/odd-string-difference/discuss/2762929/Python-1-Brute-Force-Without-Hashmap-2Optimized-With-Hashmap
class Solution: def oddString(self, words: List[str]) -> str: # Brute Force difference=[] for word in words: temp=[] for j in range(len(word)-1): temp.append(ord(word[j+1])-ord(word[j])) difference.append(temp) #print(difference) # Checking if 1st word is odd in a list -> if difference[0]!=difference[1] and difference[1]==difference[2]: return words[0] # if it is odd return..! # If it is not.. than we can clearly say that the one which is not match with 1st one is the odd one difference_integer_array=difference[0] #storing difference integer array of 1st word for i in range(1,len(difference)): if difference[i]!=difference_integer_array: return words[i]
odd-string-difference
Python [1] Brute Force {Without Hashmap} [2]Optimized {With Hashmap}
mehtay037
0
18
odd string difference
2,451
0.595
Easy
33,566
https://leetcode.com/problems/odd-string-difference/discuss/2762929/Python-1-Brute-Force-Without-Hashmap-2Optimized-With-Hashmap
class Solution: def oddString(self, words: List[str]) -> str: hashmap=defaultdict(list) for word in words: difference=[] for i in range(len(word)-1): difference.append(ord(word[i+1])-ord(word[i])) hashmap[tuple(difference)].append(word) #print(hashmap) for key,list_of_word in hashmap.items(): if len(list_of_word)==1: return list_of_word[0]
odd-string-difference
Python [1] Brute Force {Without Hashmap} [2]Optimized {With Hashmap}
mehtay037
0
18
odd string difference
2,451
0.595
Easy
33,567
https://leetcode.com/problems/odd-string-difference/discuss/2762348/Python3-Convert-To-Number
class Solution: def oddString(self, words: List[str]) -> str: def v(s): x = 0 for i in range(0, len(s)-1): x+= (ord(s[i]) - ord(s[i+1]) + 26) * (54**i) return x x = [v(s) for s in words] c = Counter(x) for i in range(len(x)): if c[x[i]]==1: return words[i]
odd-string-difference
Python3 Convert To Number
godshiva
0
12
odd string difference
2,451
0.595
Easy
33,568
https://leetcode.com/problems/odd-string-difference/discuss/2759810/Early-loop-termination-using-dict-100-speed
class Solution: def oddString(self, words: List[str]) -> str: dict_diff = dict() for w in words: diff = tuple(ord(a) - ord(b) for a, b in zip(w, w[1:])) if diff in dict_diff: dict_diff[diff][0] += 1 else: dict_diff[diff] = [1, w] if (len(dict_diff) == 2 and any(lst[0] > 1 for lst in dict_diff.values())): for _, lst in dict_diff.items(): if lst[0] == 1: return lst[1] return ""
odd-string-difference
Early loop termination using dict, 100% speed
EvgenySH
0
12
odd string difference
2,451
0.595
Easy
33,569
https://leetcode.com/problems/odd-string-difference/discuss/2759296/Python-Simple-Python-Solution-Using-HashMap-or-Dictionary
class Solution: def oddString(self, words: List[str]) -> str: alpha = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} result = [] for word in words: current_result = [] for index in range(len(word)-1): start = alpha[word[index]] end = alpha[word[index+1]] current_result.append(end-start) result.append(current_result) for index in range(len(result)): if result.count(result[index]) == 1: return words[index]
odd-string-difference
[ Python ] ✅✅ Simple Python Solution Using HashMap | Dictionary🥳✌👍
ASHOK_KUMAR_MEGHVANSHI
0
20
odd string difference
2,451
0.595
Easy
33,570
https://leetcode.com/problems/odd-string-difference/discuss/2758863/Python3-30ms-Compare-in-Pairs-O(k*n)-Time-O(1)-Space
class Solution: def oddString(self, words: List[str]) -> str: k = len(words) n = len(words[0]) for i in range(0, k, 2): for j in range(n-1): a = ord(words[i%k][j+1]) - ord(words[i%k][j]) b = ord(words[(i+1)%k][j+1]) - ord(words[(i+1)%k][j]) if a != b: c = ord(words[(i+2)%k][j+1]) - ord(words[(i+2)%k][j]) if c == a: return words[(i+1)%k] else: return words[i%k] return None
odd-string-difference
[Python3] 30ms Compare in Pairs - O(k*n) Time, O(1) Space
rt500
0
19
odd string difference
2,451
0.595
Easy
33,571
https://leetcode.com/problems/odd-string-difference/discuss/2757841/Python3-Hashmap-Solution
class Solution: def oddString(self, words: List[str]) -> str: d = {} for word in words: arr = [] for i in range(len(word)-1): arr.append(ord(word[i + 1]) - ord(word[i])) t = tuple(arr) if t not in d: d[t] = [word] else: d[t].append(word) val = list(filter(lambda x: len(x) == 1 , d.values())) return val[0][0]
odd-string-difference
Python3 Hashmap Solution
theReal007
0
8
odd string difference
2,451
0.595
Easy
33,572
https://leetcode.com/problems/odd-string-difference/discuss/2757341/Python3-Simple-Solution
class Solution: def oddString(self, words: List[str]) -> str: n = len(words[0]) difference = defaultdict(list) for word in words: temp = "[" for j in range(0, n-1): temp += str(ord(word[j+1]) - ord(word[j])) + "," temp = temp[:-1] + "]" difference[temp].append(word) for v in difference.values(): if len(v) == 1: return v[0]
odd-string-difference
Python3 Simple Solution
mediocre-coder
0
8
odd string difference
2,451
0.595
Easy
33,573
https://leetcode.com/problems/odd-string-difference/discuss/2757199/Python-beats-100-easy-explained-with-comments
class Solution: def oddString(self, words: List[str]) -> str: def calculateDifference(word: str) -> tuple: # Calculate Difference between i and i + 1 of the word return tuple(ord(word[i + 1]) - ord(word[i]) for i in range(len(word) - 1)) differenceDict = collections.defaultdict(int) for word in words: # Count &amp; store the difference of the words into the hashmap differenceDict[calculateDifference(word)] += 1 for word in words: # Find the word which occurred once. if differenceDict[calculateDifference(word)] == 1: return word
odd-string-difference
✅ Python beats 100%, easy explained with comments
sezanhaque
0
12
odd string difference
2,451
0.595
Easy
33,574
https://leetcode.com/problems/odd-string-difference/discuss/2757127/Python3-freq-table
class Solution: def oddString(self, words: List[str]) -> str: mp = defaultdict(list) for word in words: diff = tuple(ord(word[i]) - ord(word[i-1]) for i in range(1, len(word))) mp[diff].append(word) return next(v[0] for v in mp.values() if len(v) == 1)
odd-string-difference
[Python3] freq table
ye15
0
8
odd string difference
2,451
0.595
Easy
33,575
https://leetcode.com/problems/odd-string-difference/discuss/2756851/Python
class Solution: def oddString(self, words: List[str]) -> str: diffs = list(map(lambda w: [ord(c1) - ord(c2) for c1, c2 in zip(w[1:], w)], words)) if diffs[0] != diffs[1] and diffs[0] != diffs[2]: return words[0] for i in range(1, len(words)): if diffs[i] != diffs[i-1]: return words[i]
odd-string-difference
Python
blue_sky5
0
9
odd string difference
2,451
0.595
Easy
33,576
https://leetcode.com/problems/odd-string-difference/discuss/2756727/Easy-Python-Solution
class Solution: def oddString(self, words: List[str]) -> str: d = defaultdict(list) for i in words: l = [] for j in range(1,len(i)): x = ord(i[j]) - ord(i[j - 1]) l.append(x) d[tuple(l)].append(i) for k,v in d.items(): if len(v) == 1: return v[0]
odd-string-difference
Easy Python Solution
a_dityamishra
0
8
odd string difference
2,451
0.595
Easy
33,577
https://leetcode.com/problems/odd-string-difference/discuss/2756692/Python3-O(n*length)-Solution
class Solution: def oddString(self, words: List[str]) -> str: size_t = len(words[0]) for t in range(size_t-1): dict1 = defaultdict(list) for i in range(len(words)): temp = ord(words[i][t]) - ord(words[i][t-1]) dict1[temp].append(i) if len(dict1) == 2: for key,value in dict1.items(): if len(value) == 1: return words[value[0]]
odd-string-difference
Python3 O(n*length) Solution
xxHRxx
0
9
odd string difference
2,451
0.595
Easy
33,578
https://leetcode.com/problems/odd-string-difference/discuss/2756675/Python3-Dictionary
class Solution: def oddString(self, words: List[str]) -> str: def wDif(w): return tuple(ord(a)-ord(b) for a,b in zip(w,w[1:])) d={} q=[(wDif(w),w) for w in words] for v,w in q: if v not in d: d[v]=[] d[v].append(w) for v,w in d.items(): if len(w)==1: return w[0]
odd-string-difference
Python3, Dictionary
Silvia42
0
5
odd string difference
2,451
0.595
Easy
33,579
https://leetcode.com/problems/odd-string-difference/discuss/2756650/Two-dicts
class Solution: def oddString(self, words: List[str]) -> str: def ret_int(s): ans = [] for i in range(1, len(s)): ans.append(ord(s[i]) - ord(s[i - 1])) return ' '.join(map(str, ans)) ans = {} count = {} for w in words: diff = ret_int(w) count[diff] = count.get(diff, 0) + 1 ans[diff] = w if len(count) == 2 and sum(count.values()) > 2: key = sorted(count.items(), key=lambda x: x[1])[0][0] return(ans[key])
odd-string-difference
Two dicts
evgen8323
0
6
odd string difference
2,451
0.595
Easy
33,580
https://leetcode.com/problems/odd-string-difference/discuss/2756536/Python3-or-Brute-Force
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: n,m=len(queries),len(dictionary) ans=[] for q in queries: for d in dictionary: cnt=0 i=0 while i<len(q): if q[i]!=d[i]: cnt+=1 i+=1 if cnt<=2: ans.append(q) break return ans
odd-string-difference
[Python3] | Brute Force
swapnilsingh421
0
12
odd string difference
2,451
0.595
Easy
33,581
https://leetcode.com/problems/odd-string-difference/discuss/2756394/Odd-String-Difference-or-PYTHON
class Solution: def oddString(self, words: List[str]) -> str: a="abcdefghijklmnopqrstuvwxyz" l=[] for i in range(0,len(words)): w=words[i] ans=[] for j in range(1,len(w)): s=a.index(w[j])-a.index(w[j-1]) ans.append(s) l.append(ans) for i in l: if l.count(i)==1: return words[l.index(i)]
odd-string-difference
Odd String Difference | PYTHON
saptarishimondal
0
13
odd string difference
2,451
0.595
Easy
33,582
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2757378/Python-Simple-HashSet-solution-O((N%2BM)-*-L3)
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: # T: ((N + M) * L^3), S: O(M * L^3) N, M, L = len(queries), len(dictionary), len(queries[0]) validWords = set() for word in dictionary: for w in self.wordModifications(word): validWords.add(w) ans = [] for word in queries: for w in self.wordModifications(word): if w in validWords: ans.append(word) break return ans def wordModifications(self, word): # T: O(L^3) L = len(word) for i in range(L): yield word[:i] + "*" + word[i+1:] for i, j in itertools.combinations(range(L), 2): yield word[:i] + "*" + word[i+1:j] + "*" + word[j+1:]
words-within-two-edits-of-dictionary
[Python] Simple HashSet solution O((N+M) * L^3)
rcomesan
2
45
words within two edits of dictionary
2,452
0.603
Medium
33,583
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2797299/Python-(Simple-Maths)
class Solution: def twoEditWords(self, queries, dictionary): n, ans = len(queries[0]), [] for i in queries: for j in dictionary: if sum(i[k] != j[k] for k in range(n)) < 3: ans.append(i) break return ans
words-within-two-edits-of-dictionary
Python (Simple Maths)
rnotappl
0
6
words within two edits of dictionary
2,452
0.603
Medium
33,584
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2779217/Python-Brute-Force-88-speed
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: def distance_le_2(a, b): d = 0 for i, j in zip(a, b): if i != j: d += 1 if d > 2: return False return True ans = [] for q in queries: if any(distance_le_2(q, d) for d in dictionary): ans.append(q) return ans
words-within-two-edits-of-dictionary
Python Brute Force 88% speed
very_drole
0
9
words within two edits of dictionary
2,452
0.603
Medium
33,585
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2767642/Python-Easy-and-Intuitive-Solution.
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: def difference(word1, word2): count = 0 for a, b in zip(word1, word2): if a != b: count += 1 return count res = [] for word in queries: for item in dictionary: x = difference(word, item) if x <= 2: res.append(word) break return res
words-within-two-edits-of-dictionary
Python Easy & Intuitive Solution.
MaverickEyedea
0
9
words within two edits of dictionary
2,452
0.603
Medium
33,586
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2765093/Python3-Brute-Force-Approach
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: # input: queries, dict # both have words with same length # e.g.: ["word", "note", "ants", "wood"] # ["wood", "joke", "moat"] # word -> wood: edit r -> o # note -> joke: edit n -> j, t -> k # ants -> ...: more than 2 edits # wood -> wood: 0 edits # loop through both queries and dictionary # we have counters for number of different letters between 2 words # and because they all have the same length, counters should work for every comparison output = [] # nested for loop for query in queries: for word in dictionary: i = 0 counter = 0 while i < len(word): if counter > 2: break if query[i] != word[i]: counter += 1 i += 1 if counter > 2: continue elif counter <= 2: break if counter <= 2: output.append(query) return output
words-within-two-edits-of-dictionary
[Python3] Brute Force Approach
phucnguyen290198
0
4
words within two edits of dictionary
2,452
0.603
Medium
33,587
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2762219/One-line-with-list-comprehension-100-speed
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: return [w for w in queries if any(sum(cw != cd for cw, cd in zip(w, d)) < 3 for d in dictionary)]
words-within-two-edits-of-dictionary
One line with list comprehension, 100% speed
EvgenySH
0
7
words within two edits of dictionary
2,452
0.603
Medium
33,588
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2761965/Python-Easy-To-Understand-Pythonic-Solution
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: res = [] for query in queries: for word in dictionary: # Idea is to get the count of difference of chars at the positions w = len([c for c in zip(query, word) if c[0] != c[1]]) if w <= 2: res.append(query) break return res
words-within-two-edits-of-dictionary
Python Easy To Understand Pythonic Solution
Advyat
0
4
words within two edits of dictionary
2,452
0.603
Medium
33,589
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2760648/Python-2-lines
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: # return True if only 2 differences between s1 and s2 f = lambda s1, s2: sum(a != b for a, b in zip(s1, s2)) <= 2 return [q for q in queries if any(f(q, word) for word in dictionary)]
words-within-two-edits-of-dictionary
Python 2 lines
SmittyWerbenjagermanjensen
0
8
words within two edits of dictionary
2,452
0.603
Medium
33,590
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2757796/Python-edit-distance-DP-solution
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: res = [] for wd1 in queries: for wd2 in dictionary: if self.editDistance(wd1, wd2): res.append(wd1) break return res def editDistance(self, wd1, wd2): n = len(wd1) dp = [0 for i in range(n+1)] for k in range(1, n+1): if wd1[k-1] == wd2[k-1]: dp[k] = dp[k-1] else: dp[k] = 1 + dp[k-1] if dp[k] > 2: return False return dp[-1] <= 2
words-within-two-edits-of-dictionary
Python edit-distance DP solution
sakshampandey273
0
15
words within two edits of dictionary
2,452
0.603
Medium
33,591
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2757370/Python-1-liner-beats-100-easy-explained-with-comments
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: return [q for q in queries if any(sum(i != j for i, j in zip(q, d)) <= 2 for d in dictionary)]
words-within-two-edits-of-dictionary
✅ Python 1 liner beats 100%, easy explained with comments
sezanhaque
0
9
words within two edits of dictionary
2,452
0.603
Medium
33,592
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2757370/Python-1-liner-beats-100-easy-explained-with-comments
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: def check(word1: str, word2: str) -> bool: # Check how many different character are between word1 &amp; word2 # Return True if difference is <= 2 return sum(1 for i, j in zip(word1, word2) if i != j) <= 2 ans = [] for q in queries: for d in dictionary: if check(q, d): ans.append(q) break return ans
words-within-two-edits-of-dictionary
✅ Python 1 liner beats 100%, easy explained with comments
sezanhaque
0
9
words within two edits of dictionary
2,452
0.603
Medium
33,593
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2757208/Python-3Trie-%2B-DFS
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: trie = {} for word in dictionary: node = trie for w in word: node = node.setdefault(w, {}) node['*'] = word def dfs(i, node, change): if change < 0: return False if i == len(queries[0]): return True return any(dfs(i+1, node[x], change-int(q[i] != x)) for x in node) ans = [] for q in queries: if dfs(0, trie, 2): ans.append(q) return ans
words-within-two-edits-of-dictionary
[Python 3]Trie + DFS
chestnut890123
0
29
words within two edits of dictionary
2,452
0.603
Medium
33,594
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2757144/Easy-Python-Solution
class Solution: def twoEditWords(self, queries: List[str], dictt: List[str]) -> List[str]: finalwords = []; n = len(queries[0]) for word in queries: for wrd in dictt: count = 0; for i in range(n): if (word[i] != wrd[i]): count += 1; if (count <= 2): break if (count <= 2): finalwords.append(word); return finalwords
words-within-two-edits-of-dictionary
Easy Python Solution
avinashdoddi2001
0
9
words within two edits of dictionary
2,452
0.603
Medium
33,595
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2757138/Python3-1-edit-for-dictionary-and-1-edit-for-queries
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: seen = set() for word in dictionary: for i in range(len(word)): for ch in ascii_lowercase: edit = word[:i] + ch + word[i+1:] seen.add(edit) ans = [] for word in queries: for i in range(len(word)): for ch in ascii_lowercase: edit = word[:i] + ch + word[i+1:] if edit in seen: ans.append(word) break else: continue break return ans
words-within-two-edits-of-dictionary
[Python3] 1 edit for dictionary & 1 edit for queries
ye15
0
12
words within two edits of dictionary
2,452
0.603
Medium
33,596
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756950/Python-Answer-Comparing-Strings
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: def match(word:str,d): t = 0 m = 2 for i,w in enumerate(word): if w != d[i]: m -=1 if m == -1: return False return True res = [] for word in queries: for d in dictionary: if match(word, d): res.append(word) break return res
words-within-two-edits-of-dictionary
[Python Answer🤫🐍🐍🐍] Comparing Strings
xmky
0
9
words within two edits of dictionary
2,452
0.603
Medium
33,597
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756821/Python-3-or-Brute-Force
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: ans=[] for i in queries: for j in dictionary: ctr=0 for k in range(len(i)): if i[k]!=j[k]: ctr+=1 if ctr<=2: ans.append(i) break return ans
words-within-two-edits-of-dictionary
Python 3 | Brute Force
RickSanchez101
0
6
words within two edits of dictionary
2,452
0.603
Medium
33,598
https://leetcode.com/problems/words-within-two-edits-of-dictionary/discuss/2756818/Python-or-Easy-to-Understand
class Solution: def twoEditWords(self, queries: List[str], dictionary: List[str]) -> List[str]: res=[] for i in queries: for j in dictionary: cnt=0 for char in range(len(i)): if i[char]!=j[char]: cnt+=1 if cnt<=2: res.append(i) break return res
words-within-two-edits-of-dictionary
Python | Easy to Understand
varun21vaidya
0
6
words within two edits of dictionary
2,452
0.603
Medium
33,599