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/substrings-of-size-three-with-distinct-characters/discuss/1383632/Python3-%3A-simple-93-faster
class Solution: def countGoodSubstrings(self, s: str) -> int: count=0 for i in range(0,len(s)-2): if len(set(s[i:i+3])) == 3: count+=1 return count
substrings-of-size-three-with-distinct-characters
Python3 : simple 93% faster
p_a
0
52
substrings of size three with distinct characters
1,876
0.703
Easy
26,600
https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/discuss/1339461/Python-O(n)-Sliding-Window-Technique-Hashmap
class Solution(object): def countGoodSubstrings(self, s): """ :type s: str :rtype: int """ if len(s) < 3: return 0 count = 0 i, j = 0, 0 has = {} while j < len(s): if j-i == 3: count += 1 i += 1 continue if (s[j] not in has) or (s[j] in has and has[s[j]] < i): has[s[j]] = j else: if j-i == 3: count += 1 i = has[s[j]] + 1 has[s[j]] = j j += 1 if j-i == 3: count += 1 return count
substrings-of-size-three-with-distinct-characters
Python O(n) Sliding Window Technique Hashmap
Sibu0811
0
145
substrings of size three with distinct characters
1,876
0.703
Easy
26,601
https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/discuss/1327994/Python-Easy-Simple-O(n)
class Solution(object): def countGoodSubstrings(self, s): count=0 for each in range(2,len(s)+1): if len(set(s[each-3:each])) == 3: count+=1 return count
substrings-of-size-three-with-distinct-characters
Python Easy Simple O(n)
akashadhikari
0
50
substrings of size three with distinct characters
1,876
0.703
Easy
26,602
https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/discuss/1255635/Python3-or-Generalized-Solution-or-o(n)
class Solution: def countGoodSubstrings(self, s: str) -> int: seen = set() req_len = 3 start = 0 ans = 0 for i in range(len(s)): if i-start == req_len: seen.discard(s[start]) start+=1 while s[i] in seen: seen.discard(s[start]) start += 1 seen.add(s[i]) if len(seen) == req_len: ans += 1 return ans
substrings-of-size-three-with-distinct-characters
Python3 | Generalized Solution | o(n)
Sanjaychandak95
0
30
substrings of size three with distinct characters
1,876
0.703
Easy
26,603
https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/discuss/1238893/PythonPython3-solution-in-6-lines-with-explanation
class Solution: def countGoodSubstrings(self, s: str) -> int: cnt = 0 #to count the distinct character substring of length 3 for i in range(len(s)-2): subStr = s[i:i+3] #compute the substring if len(set(subStr)) == 3: #if set of subStr length is equal to 3 then increment cnt by 1 cnt += 1 return cnt
substrings-of-size-three-with-distinct-characters
Python/Python3 solution in 6 lines with explanation
prasanthksp1009
0
41
substrings of size three with distinct characters
1,876
0.703
Easy
26,604
https://leetcode.com/problems/substrings-of-size-three-with-distinct-characters/discuss/1238864/Python%3A-Find-all-substrings-of-length-3-and-then-find-unique.
class Solution: def countGoodSubstrings(self, s: str) -> int: substring = [] for i in range(0,len(s)-2): a = s[i:i+3] substring.append(a) ans = 0 for i in substring: if len(set(i)) == 3: ans += 1 return ans
substrings-of-size-three-with-distinct-characters
Python: Find all substrings of length 3 and then find unique.
harshhx
0
437
substrings of size three with distinct characters
1,876
0.703
Easy
26,605
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2087728/Python-Easy-To-Understand-Code-oror-Beginner-Friendly-oror-Brute-Force
class Solution: def minPairSum(self, nums: List[int]) -> int: pair_sum = [] nums.sort() for i in range(len(nums)//2): pair_sum.append(nums[i]+nums[len(nums)-i-1]) return max(pair_sum)
minimize-maximum-pair-sum-in-array
Python Easy To Understand Code || Beginner Friendly || Brute Force
Shivam_Raj_Sharma
5
207
minimize maximum pair sum in array
1,877
0.803
Medium
26,606
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1725067/Python-or-Sort-and-Two-Pointers
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() i = 0 j = len(nums) - 1 res = 0 while i < j: res = max(res, nums[i] + nums[j]) i += 1 j -= 1 return res
minimize-maximum-pair-sum-in-array
Python | Sort and Two Pointers
jgroszew
4
258
minimize maximum pair sum in array
1,877
0.803
Medium
26,607
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1292471/Python-fast-and-pythonic
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() return max([value+nums[-index] for index, value in enumerate(nums[:len(nums)//2], 1)])
minimize-maximum-pair-sum-in-array
[Python] fast and pythonic
cruim
2
340
minimize maximum pair sum in array
1,877
0.803
Medium
26,608
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2327399/Python-or-Easy-and-Fast-Solution-or-Two-pointer
class Solution: def minPairSum(self, nums: List[int]) -> int: ans = 0 nums.sort() l, r = 0, len(nums)-1 while l<r: ans = max(ans, nums[l]+nums[r]) l += 1 r -= 1 return ans
minimize-maximum-pair-sum-in-array
Python | Easy & Fast Solution | Two pointer
desalichka
1
46
minimize maximum pair sum in array
1,877
0.803
Medium
26,609
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1653815/Python-simple-two-pointers-solution-after-sort
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() n = len(nums) res = 0 l, r = 0, n-1 while l < r: res = max(res, nums[l] + nums[r]) l += 1 r -= 1 return res
minimize-maximum-pair-sum-in-array
Python simple two-pointers solution after sort
byuns9334
1
72
minimize maximum pair sum in array
1,877
0.803
Medium
26,610
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1359976/Sort-and-zip-98-speed
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() half_len_nums = len(nums) // 2 return max(a + b for a, b in zip(nums[:half_len_nums:], nums[-1:half_len_nums - 1: -1]))
minimize-maximum-pair-sum-in-array
Sort and zip, 98% speed
EvgenySH
1
157
minimize maximum pair sum in array
1,877
0.803
Medium
26,611
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1276736/Python3-simple-solution-using-sorting-and-single-while-loop-beats-90-users
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() i,j = 0, len(nums)-1 res = [] while i < j: res.append(nums[i]+nums[j]) i += 1 j -= 1 return max(res)
minimize-maximum-pair-sum-in-array
Python3 simple solution using sorting and single while loop beats 90% users
EklavyaJoshi
1
68
minimize maximum pair sum in array
1,877
0.803
Medium
26,612
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1245842/python3-Simple-solution-beats-99.43-of-python3-submissions.
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() return max([nums[x]+nums[-x-1] for x in range(len(nums)//2)])
minimize-maximum-pair-sum-in-array
[python3] Simple solution, beats 99.43 % of python3 submissions.
SushilG96
1
181
minimize maximum pair sum in array
1,877
0.803
Medium
26,613
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1238919/Python-oror-sort
class Solution: def minPairSum(self, nums: List[int]) -> int: pairs = [] nums = sorted(nums) n = len(nums) for i in range(len(nums)//2): a = [nums[i],nums[n-i-1]] pairs.append(a) sum_ = [] for i,j in pairs: sum_.append(i+j) return max(sum_)
minimize-maximum-pair-sum-in-array
Python || sort
harshhx
1
87
minimize maximum pair sum in array
1,877
0.803
Medium
26,614
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1238865/PythonPython3-solution-in-5-lines-with-explanation
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() # sort the numbers lis = [] # to store the res and it takes O(n) space complexity for i in range(len(nums)//2): # traverse the loop to length(nums)/2 times lis.append(nums[i]+nums[~i]) #add the indexes 0+(-1),1+(-2)...goes on till n//2 times return max(lis) # return the maximum element in the list
minimize-maximum-pair-sum-in-array
Python/Python3 solution in 5 lines with explanation
prasanthksp1009
1
95
minimize maximum pair sum in array
1,877
0.803
Medium
26,615
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1238865/PythonPython3-solution-in-5-lines-with-explanation
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort()# sort the numbers maxi = 0 # to store the maximum value and it takes only O(1) space complexity for i in range(len(nums)//2):# traverse the loop to length(nums)/2 times maxi = max(maxi,nums[i]+nums[~i])#add the indexes 0+(-1),1+(-2)...goes on till n//2 times and compute the maxi value simultaneously return maxi
minimize-maximum-pair-sum-in-array
Python/Python3 solution in 5 lines with explanation
prasanthksp1009
1
95
minimize maximum pair sum in array
1,877
0.803
Medium
26,616
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2845420/Python-easy-solution
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() n=len(nums) ot=[] for i in range(n//2): ot.append(nums[i]+nums[n-i-1]) return max(ot)
minimize-maximum-pair-sum-in-array
Python easy solution
patelhet050603
0
2
minimize maximum pair sum in array
1,877
0.803
Medium
26,617
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2834978/Python3-2-liner-beats-97.2888.60
class Solution: def minPairSum(self, nums): nums.sort() return max(nums[i]+nums[-1*i-1] for i in range(len(nums)))
minimize-maximum-pair-sum-in-array
[Python3] 2-liner, beats 97.28%/88.60%
U753L
0
3
minimize maximum pair sum in array
1,877
0.803
Medium
26,618
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2821014/Simple-two-pointers-solution
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() i = 0 j = len(nums)-1 max_sum = 0 while i < j: max_sum = max(max_sum, nums[i] + nums[j]) i += 1 j -= 1 return max_sum
minimize-maximum-pair-sum-in-array
Simple two pointers solution
khaled_achech
0
1
minimize maximum pair sum in array
1,877
0.803
Medium
26,619
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2805309/Python-Solution-EASY-TO-UNDERSTAND
class Solution: def minPairSum(self, nums: List[int]) -> int: m=0 nums.sort() n=len(nums) for i in range(n//2): m=max(m,nums[i]+nums[n-i-1]) return m
minimize-maximum-pair-sum-in-array
Python Solution - EASY TO UNDERSTAND
T1n1_B0x1
0
4
minimize maximum pair sum in array
1,877
0.803
Medium
26,620
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2801513/Fast-and-memory-efficient-solution
class Solution: def minPairSum(self, nums: List[int]) -> int: h = [] heapq.heapify(nums) for i in range(len(nums)): h.append(heapq.heappop(nums)) right = len(h)-1 m = 0 for left in range(len(h)//2): m = max(m, (h[left]+h[right])) right -= 1 return m
minimize-maximum-pair-sum-in-array
Fast and memory efficient solution
AndreySmirnov
0
1
minimize maximum pair sum in array
1,877
0.803
Medium
26,621
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2785585/Python3-solution
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() res = [] i, j = 0, len(nums) - 1 while i < j: res.append(nums[i] + nums[j]) i += 1 j -= 1 return max(res)
minimize-maximum-pair-sum-in-array
Python3 solution
mediocre-coder
0
2
minimize maximum pair sum in array
1,877
0.803
Medium
26,622
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2782495/Python3-Solution-with-explanation-beats-99-in-memory
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() max_sum=0 for i in range(len(nums)//2): max_sum = max(max_sum, nums.pop(0)+nums.pop(len(nums)-1)) return max_sum
minimize-maximum-pair-sum-in-array
Python3 Solution with explanation, beats 99% in memory
sipi09
0
2
minimize maximum pair sum in array
1,877
0.803
Medium
26,623
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2777553/Python-simple-solution-using-sort
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() n = len(nums) maxi = 0 for i in range(n//2): print(nums[n-1]) if nums[i]+nums[n-1-i]>maxi: maxi = nums[i]+nums[n-1-i] return maxi
minimize-maximum-pair-sum-in-array
Python simple solution using sort
Rajeev_varma008
0
2
minimize maximum pair sum in array
1,877
0.803
Medium
26,624
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2719124/Python-Sorting-O(nlogn)
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() ans = [] for i in range(len(nums)//2): ans.append(nums[i] + nums[~i]) return max(ans)
minimize-maximum-pair-sum-in-array
Python Sorting O(nlogn)
axce1
0
6
minimize maximum pair sum in array
1,877
0.803
Medium
26,625
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2689639/Simple-Python-Solution-or-Sorting-or-Two-Pointers
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() maxi=0 n=len(nums) for i in range(n//2): maxi=max(maxi, nums[i]+nums[-i-1]) return maxi
minimize-maximum-pair-sum-in-array
Simple Python Solution | Sorting | Two Pointers
Siddharth_singh
0
7
minimize maximum pair sum in array
1,877
0.803
Medium
26,626
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2643880/Python-or-Simple-Solution
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() maxVal = 0 j = len(nums)-1 for i in range(len(nums)//2): maxVal = max(maxVal, nums[i]+nums[j]) j-=1 return maxVal
minimize-maximum-pair-sum-in-array
Python | Simple Solution
naveenraiit
0
4
minimize maximum pair sum in array
1,877
0.803
Medium
26,627
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2410988/Simple-python-code-with-explanation
class Solution: #using sorting and two pointers approach def minPairSum(self, nums: List[int]) -> int: #create a new list to store sum of pairs sumofpairs = [] #sort the elements nums.sort() #let l pointer be at 0th index l = 0 #let r pointer be at last index r = len(nums)-1 #(l<r) is the Condition to break while l < r: #add sum of first element and last element to sumofpairs list sumofpairs.append(nums[l] + nums[r]) #increase the l pointer by 1 l = l + 1 #decrease the r pointer by 1 r = r - 1 #return the maximum of sumof pairs-->list return max(sumofpairs)
minimize-maximum-pair-sum-in-array
Simple python code with explanation
thomanani
0
14
minimize maximum pair sum in array
1,877
0.803
Medium
26,628
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2242405/Python-Solution
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() return max([nums[i]+nums[~i] for i in range(len(nums)//2)])
minimize-maximum-pair-sum-in-array
Python Solution
SakshiMore22
0
39
minimize maximum pair sum in array
1,877
0.803
Medium
26,629
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2175328/Python-or-Easy-solution-using-two-pointers-technique
class Solution: def minPairSum(self, nums: List[int]) -> int: # ///// TC: O(nlogn) and SC: O(n) //// nums.sort() res = [] l,r = 0, len(nums) - 1 while l < r: pairSum = nums[l] + nums[r] res.append(pairSum) l += 1 r -= 1 return max(res)
minimize-maximum-pair-sum-in-array
Python | Easy solution using two pointers technique
__Asrar
0
33
minimize maximum pair sum in array
1,877
0.803
Medium
26,630
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2174776/Python3-Very-simple-solution-with-sort
class Solution: def minPairSum(self, nums: List[int]) -> int: ## RC ## ## APPROACH: MATH ## nums.sort() res = 0 n = len(nums) for i in range(n//2): res = max(nums[i] + nums[n-1-i], res) return res
minimize-maximum-pair-sum-in-array
[Python3] Very simple solution with sort
101leetcode
0
21
minimize maximum pair sum in array
1,877
0.803
Medium
26,631
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1991533/Python-Solution-or-Sorting-and-Two-Pointers-or-Clean-Code
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() N = len(nums) maxPairSum = 0 left = 0 right = N-1 while left < right: maxPairSum = max(maxPairSum,nums[left] + nums[right]) left += 1 right -= 1 return maxPairSum
minimize-maximum-pair-sum-in-array
Python Solution | Sorting and Two Pointers | Clean Code
Gautam_ProMax
0
41
minimize maximum pair sum in array
1,877
0.803
Medium
26,632
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1706581/Understandable-code-for-beginners-like-me-in-python-!!
class Solution: def minPairSum(self, nums: List[int]) -> int: pairsum,maxSum=0,0 nums.sort() nums_len=len(nums) half_len=nums_len//2 for index in range(half_len): pairsum=nums[index]+nums[nums_len-index-1] if(pairsum>maxSum): maxSum=pairsum return maxSum
minimize-maximum-pair-sum-in-array
Understandable code for beginners like me in python !!
kabiland
0
64
minimize maximum pair sum in array
1,877
0.803
Medium
26,633
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1705074/Simple-python3-solution-with-description-and-example
class Solution: def minPairSum(self, nums: List[int]) -> int: #eg - [3,5,2,3] nums = sorted(nums) # sort list in ascending order => [2,3,3,5] i = 0 # two pointer i and j => nums[i] = 2 and nums[j] = 5 j = len(nums)-1 lis = [] while(i<j): lis.append(nums[i]+nums[j]) # sum ith and jth element (2,5), (3,3) pairs i+=1 j-=1 return max(lis) # return maximum number in list => lis= [2+5, 3+3], [7,6] => ans = 7
minimize-maximum-pair-sum-in-array
Simple python3 solution with description and example
KratikaRathore
0
61
minimize maximum pair sum in array
1,877
0.803
Medium
26,634
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1561707/Py3-Simple-solution-using-zip
class Solution: def minPairSum(self, nums: List[int]) -> int: res = 0 n = len(nums) if n%2 == 0: nums.sort() for x, y in zip(nums[:n//2], nums[n//2:][::-1]): res = max(res, x+y) return res
minimize-maximum-pair-sum-in-array
[Py3] Simple solution using zip
ssshukla26
0
66
minimize maximum pair sum in array
1,877
0.803
Medium
26,635
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1521050/Python-Heap
class Solution: def minPairSum(self, nums: List[int]) -> int: max_heap, min_heap = [-i for i in nums], nums heapify(min_heap) heapify(max_heap) return max([ -heappop(max_heap) + heappop(min_heap) for i in range(len(nums) // 2) ])
minimize-maximum-pair-sum-in-array
[Python] Heap
dev-josh
0
62
minimize maximum pair sum in array
1,877
0.803
Medium
26,636
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1494755/Python-3-oror-Faster-than-95-ororSimple-2-ptr
class Solution: def minPairSum(self, nums: List[int]) -> int: n=len(nums) i,j = 0,n-1 nums.sort() max_sum = float("-inf") while(i<n//2): max_sum = max(nums[i]+nums[j],max_sum) i+=1 j-=1 return max_sum
minimize-maximum-pair-sum-in-array
Python 3 || Faster than 95% ||Simple 2 ptr
ana_2kacer
0
113
minimize maximum pair sum in array
1,877
0.803
Medium
26,637
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1459604/Python3-Solution-with-using-sorting
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() _max = 0 for idx in range(len(nums) // 2): _max = max(_max, nums[idx] + nums[len(nums) - 1 - idx]) return _max
minimize-maximum-pair-sum-in-array
[Python3] Solution with using sorting
maosipov11
0
131
minimize maximum pair sum in array
1,877
0.803
Medium
26,638
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1387779/Python-oror-O(n)-oror-Count-Sort-oror-Easy-Solution-oror-beat-100-speed-and-memory
class Solution: def minPairSum(self, nums: List[int]) -> int: self.myCountSort(nums) asc = nums[0:len(nums)//2] desc = nums[len(nums)//2:][::-1] max_val, temp = 0, 0 for asc_val,desc_val in zip(asc,desc): temp = asc_val+desc_val max_val = max(max_val, temp) return max_val def myCountSort(self, the_list): max_val = max(the_list) count = [0] * (max_val+1) for item in the_list: count[item] += 1 index = 0 for i in range(len(count)): while count[i] > 0: the_list[index] = i index += 1 count[i] -= 1 return the_list
minimize-maximum-pair-sum-in-array
Python || O(n) || Count Sort || Easy Solution || beat 100% speed and memory
zafarman
0
173
minimize maximum pair sum in array
1,877
0.803
Medium
26,639
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1268312/Python-faster-than-95-O(nlogn)
class Solution: def minPairSum(self, nums: List[int]) -> int: nums = sorted(nums) ans = nums[0] for i in range(len(nums)//2): pair_sum = nums[i] + nums[len(nums) -i - 1] if pair_sum > ans: ans = pair_sum return ans
minimize-maximum-pair-sum-in-array
Python faster than 95% O(nlogn)
user5573CJ
0
84
minimize maximum pair sum in array
1,877
0.803
Medium
26,640
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1239052/Python3-greedy
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() return max(nums[i] + nums[~i] for i in range(len(nums)//2))
minimize-maximum-pair-sum-in-array
[Python3] greedy
ye15
0
35
minimize maximum pair sum in array
1,877
0.803
Medium
26,641
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1239052/Python3-greedy
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() ans = 0 for i in range(len(nums)//2): ans = max(ans, nums[i] + nums[~i]) return ans
minimize-maximum-pair-sum-in-array
[Python3] greedy
ye15
0
35
minimize maximum pair sum in array
1,877
0.803
Medium
26,642
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/2309773/Python-oror-Time-O(n)-two-pointer-solution
class Solution: def minPairSum(self, nums: List[int]) -> int: res = 0 nums.sort() i,j = 0 , len(nums)-1 while(i<j): res = max(res , nums[i]+nums[j]) i+=1 j-=1 return res
minimize-maximum-pair-sum-in-array
Python || Time O(n) two-pointer solution
ronipaul9972
-1
34
minimize maximum pair sum in array
1,877
0.803
Medium
26,643
https://leetcode.com/problems/minimize-maximum-pair-sum-in-array/discuss/1657614/Python-oror-O(nlogn)-time-oror-O(1)-spaceoror-sorting-oror-2-pointers
class Solution: def minPairSum(self, nums: List[int]) -> int: nums.sort() start, end = 0, len(nums) - 1 max_sum = 0 while start <= end: curr_sum = nums[start] + nums[end] max_sum = max(max_sum,curr_sum) start += 1 end -= 1 return max_sum #TC -> O(n*logn) #SC -> O(1)
minimize-maximum-pair-sum-in-array
Python || O(nlogn) time || O(1) space|| sorting || 2 pointers
s_m_d_29
-1
95
minimize maximum pair sum in array
1,877
0.803
Medium
26,644
https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/discuss/1239929/python-oror-100-faster-oror-well-explained-oror-Simple-approach
class Solution: def getBiggestThree(self, grid: List[List[int]]) -> List[int]: def calc(l,r,u,d): sc=0 c1=c2=(l+r)//2 expand=True for row in range(u,d+1): if c1==c2: sc+=grid[row][c1] else: sc+=grid[row][c1]+grid[row][c2] if c1==l: expand=False if expand: c1-=1 c2+=1 else: c1+=1 c2-=1 return sc m=len(grid) n=len(grid[0]) heap=[] for i in range(m): for j in range(n): l=r=j d=i while l>=0 and r<=n-1 and d<=m-1: sc=calc(l,r,i,d) l-=1 r+=1 d+=2 if len(heap)<3: if sc not in heap: heapq.heappush(heap,sc) else: if sc not in heap and sc>heap[0]: heapq.heappop(heap) heapq.heappush(heap,sc) heap.sort(reverse=True) return heap
get-biggest-three-rhombus-sums-in-a-grid
🐍 {python} || 100% faster || well-explained || Simple approach
abhi9Rai
6
721
get biggest three rhombus sums in a grid
1,878
0.464
Medium
26,645
https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/discuss/1442967/Python-3-or-DP-Matrix-Padding-Prefix-Sum-or-Explanation
class Solution: def getBiggestThree(self, grid: List[List[int]]) -> List[int]: m, n = len(grid), len(grid[0]) dp = [[[0, 0]] * (n+2) for _ in range(m+2)] ans = [] for i in range(1, m+1): for j in range(1, n+1): # [i, j] will be the bottom vertex ans.append(grid[i-1][j-1]) dp[i][j] = [grid[i-1][j-1], grid[i-1][j-1]] dp[i][j][0] += dp[i-1][j-1][0] # dp: major diagonal dp[i][j][1] += dp[i-1][j+1][1] # dp: minor diagonal for win in range(1, min(m, n)): x1, y1 = i-win, j-win # left vertex x2, y2 = i-win, j+win # right vertex x3, y3 = i-win-win, j # top vertex if not (all(1 <= x < m+1 for x in [x1, x2, x3]) and all(1 <= y < n+1 for y in [y1, y2, y3])): break b2l = dp[i][j][0] - dp[x1-1][y1-1][0] # bottom node to left node (node sum), major diagonal b2r = dp[i][j][1] - dp[x2-1][y2+1][1] # bottom node to right node (node sum), minor diagonal l2t = dp[x1][y1][1] - dp[x3-1][y3+1][1] # left node to top node (node sum), minor diagonal r2t = dp[x2][y2][0] - dp[x3-1][y3-1][0] # right node to top node (node sum), major diagonal vertices_sum = grid[i-1][j-1] + grid[x1-1][y1-1] + grid[x2-1][y2-1] + grid[x3-1][y3-1] cur = b2l + b2r + l2t + r2t - vertices_sum # sum(edges) - sum(4 vertices) ans.append(cur) return sorted(set(ans), reverse=True)[:3] # unique + sort reverse + keep only first 3
get-biggest-three-rhombus-sums-in-a-grid
Python 3 | DP, Matrix Padding, Prefix Sum | Explanation
idontknoooo
2
659
get biggest three rhombus sums in a grid
1,878
0.464
Medium
26,646
https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/discuss/1360208/Brute-force-75-speed
class Solution: def getBiggestThree(self, grid: List[List[int]]) -> List[int]: first = second = third = 0 def update_sums(val): nonlocal first, second, third if val > first: third = second second = first first = val elif first > val > second: third = second second = val elif second > val > third: third = val rows, cols = len(grid), len(grid[0]) max_size = max(rows // 2, cols // 2) + 1 for r in range(rows): for c in range(cols): update_sums(grid[r][c]) for n in range(1, max_size): if c + 2 * n < cols and r - n >= 0 and r + n < rows: sum_rhombus = (grid[r][c] + grid[r][c + 2 * n] + grid[r - n][c + n] + grid[r + n][c + n]) end_c = c + 2 * n for i in range(1, n): sum_rhombus += (grid[r + i][c + i] + grid[r - i][c + i] + grid[r + i][end_c - i] + grid[r - i][end_c - i]) update_sums(sum_rhombus) else: break biggest = {first, second, third} - {0} return sorted(biggest, reverse=True)
get-biggest-three-rhombus-sums-in-a-grid
Brute force, 75% speed
EvgenySH
1
337
get biggest three rhombus sums in a grid
1,878
0.464
Medium
26,647
https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/discuss/1242382/1878.-Get-Biggest-Three-Rhombus-Sums-in-a-Grid-oror-python-solution
class Solution(object): def getBiggestThree(self, grid): def calc(l,r,u,d): ssum=0 expand=True c1=c2=(l+r)//2 for row in range(u,d+1): if c1==c2: ssum+=grid[row][c1] else : ssum+=grid[row][c1]+grid[row][c2] if c1==l: expand=False if expand: c1-=1 c2+=1 else : c1+=1 c2-=1 return ssum m=len(grid) n=len(grid[0]) pq=[] for i in range(m): for j in range(n): l=r=j d=i while l>=0 and r<n and d<m: ssum=calc(l,r,i,d) l-=1 r+=1 d+=2 if len(pq)<3: if ssum not in pq: heapq.heappush(pq,ssum) else : if ssum not in pq and ssum>pq[0]: heapq.heappop(pq) heapq.heappush(pq,ssum) pq.sort(reverse=True) return pq ```
get-biggest-three-rhombus-sums-in-a-grid
1878. Get Biggest Three Rhombus Sums in a Grid || python solution
aayush_chhabra
1
511
get biggest three rhombus sums in a grid
1,878
0.464
Medium
26,648
https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/discuss/1463534/Python3-Passes-116117-cases-please-help
class Solution: def getBiggestThree(self, grid: List[List[int]]) -> List[int]: run = set() n = len(grid) m = len(grid[0]) # Loop through every grid item for i in range(n): for j in range(m): # Calculate the max rhombus around the current grid item res = self.count(grid, i, j, len(grid), len(grid[0])) # Add to list of sums run.add(res) res = [] # Stupid way of getting biggest 3, # a heap would work better but the problem # isn't here return sorted(run, reverse=True)[:3] # This function calculates the width of the largest # rhombus that can be made around the given grid row and col. # Then it calculates each rhombus that can be made up until that max width, # keeping track of what the largest sum is amongst all the created rhombuses, # and returns the max def count(self, grid, row, col, n, m): # Calculate how wide the largest rhombus can be. # it is the smaller number of how close are you to the # nearest edge of row, or nearest edge of column distance = min(n - row, m - col) # set the max perimeter sum to the current number global_max = grid[row][col] # From 1 to the width of the biggest rhombus that can be made for i in range(1, distance): # check 4 corners, if not 4 corners, no rhombus can be made at current distance if row - i >= 0 and row + i < n and col - i >= 0 and col + i < m: top_point = row - i bottom_point = row + i # Add up the vertices (points) local_max = grid[row-i][col] + grid[row+i][col] + grid[row][col-i] + grid[row][col+i] # For 1 up to the width of the current rhombus, # add up the perimeter for j in range(1,i): local_max += grid[top_point + j][col - j] + grid[top_point + j][col+j] local_max += grid[bottom_point - j][col-j] + grid[bottom_point - j][col + j] # Save the bigger perimeter sum global_max = max(global_max, local_max) else: break return global_max
get-biggest-three-rhombus-sums-in-a-grid
Python3 Passes 116/117 cases, please help
walshyb
0
290
get biggest three rhombus sums in a grid
1,878
0.464
Medium
26,649
https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/discuss/1239060/Python3-prefix-sums
class Solution: def getBiggestThree(self, grid: List[List[int]]) -> List[int]: m, n = len(grid), len(grid[0]) # dimensions anti, diag = {}, {} for i in range(m): for j in range(n): key = i+j if key not in anti: anti[key] = [0] anti[key].append(anti[key][-1] + grid[i][j]) key = i-j if key not in diag: diag[key] = [0] diag[key].append(diag[key][-1] + grid[i][j]) def fn(i, j, k): """Return sum of k diagonal elements starting from (i, j)""" if i >= j: return diag[i-j][j+k] - diag[i-j][j] return diag[i-j][i+k] - diag[i-j][i] def gn(i, j, k): """Return sum of k anti-diagonal elements starting from (i, j)""" if i+j < n: return anti[i+j][i+k] - anti[i+j][i] return anti[i+j][n-1-j+k] - anti[i+j][n-1-j] ans = set() for i in range(m): for j in range(n): ans.add(grid[i][j]) for ii in range(i+2, m, 2): r = (ii-i)//2 if j-r < 0 or j+r >= n: break val = 0 val += fn(i, j, r+1) val += gn(i, j, r+1) val += fn((ii+i)//2, j-r, r+1) val += gn((ii+i)//2, j+r, r+1) val -= grid[i][j] + grid[(ii+i)//2][j-r] + grid[(ii+i)//2][j+r] + grid[ii][j] ans.add(val) return sorted(ans, reverse=True)[:3]
get-biggest-three-rhombus-sums-in-a-grid
[Python3] prefix sums
ye15
0
111
get biggest three rhombus sums in a grid
1,878
0.464
Medium
26,650
https://leetcode.com/problems/minimum-xor-sum-of-two-arrays/discuss/1238641/Bit-Mask
class Solution: def minimumXORSum(self, a: List[int], b: List[int]) -> int: @cache def dp(mask: int) -> int: i = bin(mask).count("1") if i >= len(a): return 0 return min((a[i] ^ b[j]) + dp(mask + (1 << j)) for j in range(len(b)) if mask &amp; (1 << j) == 0) return dp(0)
minimum-xor-sum-of-two-arrays
Bit Mask
votrubac
103
6,400
minimum xor sum of two arrays
1,879
0.448
Hard
26,651
https://leetcode.com/problems/minimum-xor-sum-of-two-arrays/discuss/1239072/Python3-bit-mask-dp
class Solution: def minimumXORSum(self, nums1: List[int], nums2: List[int]) -> int: n = len(nums1) @cache def fn(mask, k): """Return min xor sum.""" if not mask: return 0 ans = inf for i in range(n): if mask &amp; (1<<i): ans = min(ans, (nums1[i]^nums2[k]) + fn(mask^(1<<i), k+1)) return ans return fn((1<<n)-1, 0)
minimum-xor-sum-of-two-arrays
[Python3] bit-mask dp
ye15
1
60
minimum xor sum of two arrays
1,879
0.448
Hard
26,652
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1241968/Minus-49
class Solution: def isSumEqual(self, first: str, second: str, target: str) -> bool: def op(s: str): return "".join(chr(ord(ch) - 49) for ch in s) return int(op(first)) + int(op(second)) == int(op(target))
check-if-word-equals-summation-of-two-words
Minus 49
votrubac
18
1,200
check if word equals summation of two words
1,880
0.738
Easy
26,653
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1241973/Python3-or-Time%3A-O(n)-or-Space%3A-O(1)-or-Clear.-Explanation!
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: mapping = { 'a':'0', 'b':'1', 'c':'2', 'd':'3', 'e':'4', 'f':'5', 'g':'6', 'h':'7', 'i':'8', 'j':'9' } def decoding(s): nonlocal mapping return int(''.join(list(map((lambda i:mapping[i]),list(s))))) return decoding(firstWord) + decoding(secondWord) == decoding(targetWord)
check-if-word-equals-summation-of-two-words
Python3 | Time: O(n) | Space: O(1) | Clear. Explanation!
antonyakovlev
9
683
check if word equals summation of two words
1,880
0.738
Easy
26,654
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1239984/Python-oror-simple-using-ascii-conversion
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: a, b, c = [],[],[] a_,b_,c_="","","" base = ord("a") def getList(l,s): for i in s: l.append(ord(i)-base) return l def getString(x,l): for i in l: x += str(i) return x a = getList(a,firstWord) b = getList(b,secondWord) c = getList(c,targetWord) a_ = getString(a_,a) b_ = getString(b_,b) c_ = getString(c_,c) return(( int(a_)+int(b_)) == int(c_))
check-if-word-equals-summation-of-two-words
Python || simple using ascii conversion
harshhx
4
492
check if word equals summation of two words
1,880
0.738
Easy
26,655
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1357032/Easy-Python-Solutions-(3-Approaches-Speed-98-Memory-100)
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] target_val = 0 temp = "" for i in targetWord: temp += str(alphabets.index(i)) target_val = int(temp) temp = "" for i in firstWord: temp += str(alphabets.index(i)) target_val -= int(temp) temp = "" for i in secondWord: temp += str(alphabets.index(i)) target_val -= int(temp) if target_val: return False else: return True
check-if-word-equals-summation-of-two-words
Easy Python Solutions (3 Approaches - Speed 98%, Memory 100%)
the_sky_high
3
108
check if word equals summation of two words
1,880
0.738
Easy
26,656
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1357032/Easy-Python-Solutions-(3-Approaches-Speed-98-Memory-100)
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: alphabets = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] target_val = 0 temp = "" for i in targetWord: temp += str(alphabets.index(i)) target_val = int(temp) temp = "" for i in firstWord: temp += str(alphabets.index(i)) target_val -= int(temp) temp = "" for i in secondWord: temp += str(alphabets.index(i)) target_val -= int(temp) if target_val: return False else: return True
check-if-word-equals-summation-of-two-words
Easy Python Solutions (3 Approaches - Speed 98%, Memory 100%)
the_sky_high
3
108
check if word equals summation of two words
1,880
0.738
Easy
26,657
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1357032/Easy-Python-Solutions-(3-Approaches-Speed-98-Memory-100)
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: alphabets = {'a': '0', 'b': '1', 'c': '2', 'd': '3', 'e': '4', 'f': '5', 'g': '6', 'h': '7', 'i': '8', 'j': '9'} target_val = 0 temp = "" for i in targetWord: temp += alphabets[i] target_val = int(temp) temp = "" for i in firstWord: temp += alphabets[i] target_val -= int(temp) temp = "" for i in secondWord: temp += alphabets[i] target_val -= int(temp) if target_val: return False else: return True
check-if-word-equals-summation-of-two-words
Easy Python Solutions (3 Approaches - Speed 98%, Memory 100%)
the_sky_high
3
108
check if word equals summation of two words
1,880
0.738
Easy
26,658
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2186388/Check-if-Word-Equals-Summation-of-Two-Words
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: wordList = [firstWord, secondWord, targetWord] sumList = [] for word in wordList: sumList.append(self.calcSum(word)) return sumList[0]+sumList[1]==sumList[2] def calcSum(self, word): s = "" for letter in word: s+=str(ord(letter)-97) return int(s)
check-if-word-equals-summation-of-two-words
Check if Word Equals Summation of Two Words
pratik_patra
1
31
check if word equals summation of two words
1,880
0.738
Easy
26,659
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1791063/Simple-python3-solution-or-82-faster-or-Easy-to-understand
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: s = "abcdefghij" fir = str() sec = str() tar = str() for i in firstWord: fir += str(s.index(i)) for i in secondWord: sec += str(s.index(i)) for i in targetWord: tar += str(s.index(i)) return int(fir)+int(sec) == int(tar)
check-if-word-equals-summation-of-two-words
Simple python3 solution | 82% faster | Easy to understand
Coding_Tan3
1
36
check if word equals summation of two words
1,880
0.738
Easy
26,660
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1698961/inner-function-based
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: def get_number(s): num = 0 for c in s: num = num * 10 + ord(c) - ord('a') return num return get_number(firstWord) + get_number(secondWord) == get_number(targetWord)
check-if-word-equals-summation-of-two-words
inner function based
snagsbybalin
1
17
check if word equals summation of two words
1,880
0.738
Easy
26,661
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1266027/Python3-O(mn)-time-O(1)-space
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: dictionary = ['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'] firstWordConvert, secondWordConvert, targetWordConvert = '', '', '' for letter in firstWord: firstWordConvert += str(dictionary.index(letter)) for letter in secondWord: secondWordConvert += str(dictionary.index(letter)) for letter in targetWord: targetWordConvert += str(dictionary.index(letter)) return True if int(firstWordConvert) + int(secondWordConvert) == int(targetWordConvert) else False
check-if-word-equals-summation-of-two-words
Python3 O(mn) time O(1) space
peterhwang
1
157
check if word equals summation of two words
1,880
0.738
Easy
26,662
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2825043/Python-Simple-Solution
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: sum1 = "" for i in range(0, len(firstWord)): if firstWord[i] == 'a': if sum1 != "0": sum1 += str(ord(firstWord[i]) - 97) else: sum1 += str(ord(firstWord[i]) - 97) sum2 = "" for i in range(0, len(secondWord)): if secondWord[i] == 'a': if sum2 != "0": sum2 += str(ord(secondWord[i]) - 97) else: sum2 += str(ord(secondWord[i]) - 97) sum3 = "" for i in range(0, len(targetWord)): if targetWord[i] == 'a': if sum3 != "0": sum3 += str(ord(targetWord[i]) - 97) else: sum3 += str(ord(targetWord[i]) - 97) return int(sum1) + int(sum2) == int(sum3)
check-if-word-equals-summation-of-two-words
Python Simple Solution
PranavBhatt
0
1
check if word equals summation of two words
1,880
0.738
Easy
26,663
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2812302/Python-or-simple-solution
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: def encode(s): return int("".join([str(ord(char) - 97) for char in s])) return encode(firstWord) + encode(secondWord) == encode(targetWord)
check-if-word-equals-summation-of-two-words
Python | simple solution
kawamataryo
0
1
check if word equals summation of two words
1,880
0.738
Easy
26,664
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2773715/Python-or-LeetCode-or-1880.-Check-if-Word-Equals-Summation-of-Two-Words
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: map1 = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9} s1 = "" s2 = "" s3 = "" for i in firstWord: s1 += str(map1[i]) for j in secondWord: s2 += str(map1[j]) for k in targetWord: s3 += str(map1[k]) return int(s1) + int(s2) == int(s3)
check-if-word-equals-summation-of-two-words
Python | LeetCode | 1880. Check if Word Equals Summation of Two Words
UzbekDasturchisiman
0
1
check if word equals summation of two words
1,880
0.738
Easy
26,665
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2773715/Python-or-LeetCode-or-1880.-Check-if-Word-Equals-Summation-of-Two-Words
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: firstNum, secondNum, targetNum = "", "", "" for char in firstWord: firstNum += str(ord(char) - ord('a')) for char in secondWord: secondNum += str(ord(char) - ord('a')) for char in targetWord: targetNum += str(ord(char) - ord('a')) return int(firstNum) + int(secondNum) == int(targetNum)
check-if-word-equals-summation-of-two-words
Python | LeetCode | 1880. Check if Word Equals Summation of Two Words
UzbekDasturchisiman
0
1
check if word equals summation of two words
1,880
0.738
Easy
26,666
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2773715/Python-or-LeetCode-or-1880.-Check-if-Word-Equals-Summation-of-Two-Words
class Solution: def f(self, word: str) -> int: wordNum = "" for i in word: wordNum += str(ord(i) - ord('a')) return int(wordNum) def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: return self.f(firstWord) + self.f(secondWord) == self.f(targetWord)
check-if-word-equals-summation-of-two-words
Python | LeetCode | 1880. Check if Word Equals Summation of Two Words
UzbekDasturchisiman
0
1
check if word equals summation of two words
1,880
0.738
Easy
26,667
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2710939/Python-oror-Simple-Approach-using-dictionary-oror-Beats-88
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: v={'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,'i':8,'j':9} l=[] l1=[] l2=[] for i in firstWord: l.append(v.get(i)) for i in secondWord: l1.append(v.get(i)) for i in targetWord: l2.append(v.get(i)) res=int("".join(map(str,l))) res1=int("".join(map(str,l1))) fin=int("".join(map(str,l2))) if(res+res1==fin): return True else: return False
check-if-word-equals-summation-of-two-words
Python || Simple Approach using dictionary || Beats 88%
shivammenda2002
0
4
check if word equals summation of two words
1,880
0.738
Easy
26,668
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2609661/Solution
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: fn=fs=tw = "" for i in range(len(firstWord)): fn += str(ord(firstWord[i])-97) for j in range(len(secondWord)): fs += str(ord(secondWord[j])-97) for k in range(len(targetWord)): tw += str(ord(targetWord[k])-97) return ((int(fn)+int(fs)) == int(tw))
check-if-word-equals-summation-of-two-words
Solution
fiqbal997
0
8
check if word equals summation of two words
1,880
0.738
Easy
26,669
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2520949/Easy-Python-Solution-for-Beginners
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: #Creating a map to convert alphabets to numbers dicAlpha = { 'a':'0','b':'1','c':'2','d':'3','e':'4','f':'5','g':'6','h':'7','i':'8','j':'9' } newFirstWord = "" newSecondWord = "" newTargetWord = "" # Converting alphabets to numbers , example this loop will convert "abc" -> "021" for i in range(len(firstWord)): newFirstWord+=dicAlpha[firstWord[i]] for i in range(len(secondWord)): newSecondWord+=dicAlpha[secondWord[i]] for i in range(len(targetWord)): newTargetWord+=dicAlpha[targetWord[i]] if int(newFirstWord) + int(newSecondWord) == int(newTargetWord): return True else: return False
check-if-word-equals-summation-of-two-words
Easy Python Solution for Beginners
Ron99
0
23
check if word equals summation of two words
1,880
0.738
Easy
26,670
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2324275/Python-Simple
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: num1 = '' num2 = '' for i in firstWord: num1+=str(ord(i)-ord('a')) for i in secondWord: num2+=str(ord(i)-ord('a')) target='' for i in targetWord: target+=str(ord(i)-ord('a')) return int(target) == (int(num1)+int(num2))
check-if-word-equals-summation-of-two-words
Python Simple
sunakshi132
0
17
check if word equals summation of two words
1,880
0.738
Easy
26,671
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2298827/PYTHON-oror-FAASTER-THAN-88-oror-SPACE-LESS-THAN-93oror-BASIC
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: def num(a): n=0 for f in a: n=n*10 +(ord(f)-97) return n if num(targetWord)==num(firstWord)+num(secondWord): return(True) else: return (False)
check-if-word-equals-summation-of-two-words
PYTHON || FAASTER THAN 88% || SPACE LESS THAN 93%|| BASIC
vatsalg2002
0
12
check if word equals summation of two words
1,880
0.738
Easy
26,672
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2215263/MINUS-97
'''class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: ans=False first='' second='' target='' for i in firstWord: first=first+str(ord(i)-97) for i in secondWord: second=second+str(ord(i)-97) for i in targetWord: target=target+str(ord(i)-97) add=int(first)+int(second) if add==int(target): ans=True return ans pritn(isSumEqual(firstWord,secondWord,targetWord))'''
check-if-word-equals-summation-of-two-words
MINUS 97
keertika27
0
10
check if word equals summation of two words
1,880
0.738
Easy
26,673
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2152519/Python-or-Very-Easy-elegant-and-intuitive-approach-using-cashing
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: table = {'a':0,'b':1,'c':2,'d':3,'e':4,'f':5,'g':6,'h':7,'i':8,'j':9} num1 = 0 for i in firstWord: num1 = num1 * 10 + table[i] # print(num1) num2 = 0 for i in secondWord: num2 = num2 * 10 + table[i] # print(num2) target = 0 for i in targetWord: target = target * 10 + table[i] if num1 + num2 == target: return True return False
check-if-word-equals-summation-of-two-words
Python | Very Easy, elegant and intuitive approach using cashing
__Asrar
0
30
check if word equals summation of two words
1,880
0.738
Easy
26,674
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/2045091/Python-simple-solution
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: def convert_word(word): from string import ascii_lowercase as al converted = '' for i in word: converted += str(al.index(i)) return int(converted) return convert_word(firstWord) + convert_word(secondWord) == convert_word(targetWord)
check-if-word-equals-summation-of-two-words
Python simple solution
StikS32
0
24
check if word equals summation of two words
1,880
0.738
Easy
26,675
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1942280/Python-Clean-and-Simple-%2B-One-Liner
class Solution: def isSumEqual(self, w1, w2, target): def val(w): return int("".join([str(ord(c)-ord("a")) for c in w])) return val(w1)+val(w2) == val(target)
check-if-word-equals-summation-of-two-words
Python - Clean and Simple + One-Liner
domthedeveloper
0
41
check if word equals summation of two words
1,880
0.738
Easy
26,676
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1942280/Python-Clean-and-Simple-%2B-One-Liner
class Solution: def isSumEqual(self, w1, w2, target): return (lambda val : val(w1)+val(w2) == val(target))(lambda w : int("".join([str(ord(c)-ord("a")) for c in w])))
check-if-word-equals-summation-of-two-words
Python - Clean and Simple + One-Liner
domthedeveloper
0
41
check if word equals summation of two words
1,880
0.738
Easy
26,677
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1887290/Python-one-liner-with-memory-usage-less-than-82
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: return int(''.join(str(ord(x)-97) for x in firstWord)) + int(''.join(str(ord(x)-97) for x in secondWord)) == int(''.join(str(ord(x)-97) for x in targetWord))
check-if-word-equals-summation-of-two-words
Python one liner with memory usage less than 82%
alishak1999
0
39
check if word equals summation of two words
1,880
0.738
Easy
26,678
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1868904/Python-dollarolution
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: s, count = '', 0 for i in firstWord: s += str(ord(i)-97) count += int(s) s = '' for i in secondWord: s += str(ord(i)-97) count += int(s) s = '' for i in targetWord: s += str(ord(i)-97) return count == int(s)
check-if-word-equals-summation-of-two-words
Python $olution
AakRay
0
33
check if word equals summation of two words
1,880
0.738
Easy
26,679
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1849669/python3orsimpleorshortorO(N)or
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: int_str = lambda s: int(''.join([str(ord(letter) - ord('a')) for letter in s])) return int_str(firstWord) + int_str(secondWord) == int_str(targetWord)
check-if-word-equals-summation-of-two-words
python3|simple|short|O(N)|🐍🐍
YaBhiThikHai
0
29
check if word equals summation of two words
1,880
0.738
Easy
26,680
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1846959/Easiest-Python3-Solution-oror-100-Faster-oror-Easy-to-understand-Python-code
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: x=0 y=0 z=0 valueAlpha=0 alpha="" for i in firstWord: alpha=i valueAlpha=ord(alpha)-97 x=x*10+valueAlpha for i in secondWord: alpha=i valueAlpha=ord(alpha)-97 y=y*10+valueAlpha for i in targetWord: alpha=i valueAlpha=ord(alpha)-97 z=z*10+valueAlpha return x+y==z
check-if-word-equals-summation-of-two-words
Easiest Python3 Solution || 100% Faster || Easy to understand Python code
RatnaPriya
0
36
check if word equals summation of two words
1,880
0.738
Easy
26,681
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1718566/python3-or-one-line-solution-or-faster-than-71.43
class Solution: def generate_num(self, words) -> int: return int("".join([str(ord(l) % 97) for l in words])) def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: return (self.generate_num(firstWord) + self.generate_num(secondWord)) == self.generate_num(targetWord)
check-if-word-equals-summation-of-two-words
python3 | one line solution | faster than 71.43%
khalidhassan3011
0
43
check if word equals summation of two words
1,880
0.738
Easy
26,682
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1534691/String-translate-method-90-speed
class Solution: d = {97 + i: 48 + i for i in range(10)} def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: return (int(firstWord.translate(Solution.d)) + int(secondWord.translate(Solution.d)) == int(targetWord.translate(Solution.d)))
check-if-word-equals-summation-of-two-words
String translate method, 90% speed
EvgenySH
0
65
check if word equals summation of two words
1,880
0.738
Easy
26,683
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1503964/3-line-solution-wo-explicit-type-casting-in-Python
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: a = ord('a') to_num = lambda s: sum((ord(c) - a) * (10 ** i) for i, c in enumerate(reversed(s))) return sum(map(to_num, (firstWord, secondWord))) == to_num(targetWord)
check-if-word-equals-summation-of-two-words
3-line solution w/o explicit type-casting in Python
mousun224
0
53
check if word equals summation of two words
1,880
0.738
Easy
26,684
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1496330/Python-Unicode
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: first, second, target_tot = 0, 0, 0 for fw in firstWord: first = first * 10 + (ord(fw) - ord('a')) for sw in secondWord: second = second * 10 + (ord(sw) - ord('a')) for tw in targetWord: target_tot = target_tot * 10 + (ord(tw) - ord('a')) return first + second == target_tot
check-if-word-equals-summation-of-two-words
Python Unicode
jlee9077
0
60
check if word equals summation of two words
1,880
0.738
Easy
26,685
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1406726/Python3-Faster-then-84-of-the-Solutions
class Solution: def convert(self,s): x = '' for i in s: x = x + str(ord(i)-97) return int(x) def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: return self.convert(firstWord)+self.convert(secondWord)==self.convert(targetWord)
check-if-word-equals-summation-of-two-words
Python3 - Faster then 84% of the Solutions
harshitgupta323
0
78
check if word equals summation of two words
1,880
0.738
Easy
26,686
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1302642/Python3-Simple-solution-beats-97-of-the-submissions
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: charMap = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4 , 'f': 5, 'g': 6, 'h': 7, 'i':8, 'j': 9} firstWordMap = ''.join([ str(charMap[x]) for x in firstWord ]) secondWordMap = ''.join( [ str(charMap[x]) for x in secondWord ] ) targetWordMap = ''.join( [ str(charMap[x]) for x in targetWord ] ) return bool(int(firstWordMap) + int(secondWordMap) == int(targetWordMap))
check-if-word-equals-summation-of-two-words
[Python3] Simple solution, beats 97% of the submissions
GauravKK08
0
38
check if word equals summation of two words
1,880
0.738
Easy
26,687
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1281996/Python-Simple
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: return self.word_to_int(firstWord) + self.word_to_int(secondWord) == self.word_to_int(targetWord) def word_to_int(self, s): return int(''.join(str(ord(char) - 97) for char in s))
check-if-word-equals-summation-of-two-words
Python Simple
peatear-anthony
0
72
check if word equals summation of two words
1,880
0.738
Easy
26,688
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1275996/Python-3-one-liner!-Use-ord-function(28-ms-faster-than-91.33)
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: return (int("".join([str(ord(i)-97) for i in firstWord]))+int("".join([str(ord(i)-97) for i in secondWord]))) == int("".join([str(ord(i)-97) for i in targetWord]))
check-if-word-equals-summation-of-two-words
Python 3 one liner! Use ord function(28 ms, faster than 91.33%)
lin11116459
0
45
check if word equals summation of two words
1,880
0.738
Easy
26,689
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1275996/Python-3-one-liner!-Use-ord-function(28-ms-faster-than-91.33)
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: a=int("".join([str(ord(i)-97) for i in firstWord])) b=int("".join([str(ord(i)-97) for i in secondWord])) c=int("".join([str(ord(i)-97) for i in targetWord])) return (a+b) == c
check-if-word-equals-summation-of-two-words
Python 3 one liner! Use ord function(28 ms, faster than 91.33%)
lin11116459
0
45
check if word equals summation of two words
1,880
0.738
Easy
26,690
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1266966/Easy-and-Efficient-Python-Solution
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: li = [chr(i) for i in range(97, 107)] def calculate(word): ans = '' for i in word: ans += str(li.index(i)) return int(ans) sum1 = calculate(firstWord) sum2 = calculate(secondWord) sum3 = calculate(targetWord) return sum1+sum2 == sum3
check-if-word-equals-summation-of-two-words
Easy & Efficient Python Solution
sanu2sid
0
81
check if word equals summation of two words
1,880
0.738
Easy
26,691
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1265351/or-Python-or-Solution-using-String-Methods
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: words = [firstWord, secondWord, targetWord] for i in range(len(words)): convert = words[i].maketrans('abcdefghij', '0123456789') words[i] = words[i].translate(convert) return int(words[0])+int(words[1]) == int(words[2])
check-if-word-equals-summation-of-two-words
| Python | Solution using String Methods
bruadarach
0
46
check if word equals summation of two words
1,880
0.738
Easy
26,692
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1260062/Python-Solutions-and-Explanations-Noobie-version-Equivalent-Lambda-Version-and-extra-thoughts.
class Solution(object): def getWordValue(self, word): """ Return a new string such that each character is represented by it's numeric counter described in the problem statement""" newWord='' for letter in word: newWord+=(str(ord(letter)-97)) return newWord def isSumEqual(self, firstWord, secondWord, targetWord): """ :type firstWord: str :type secondWord: str :type targetWord: str :rtype: bool """ # 1. Get the sum of the firstWord &amp; secondWord sumValue = int(self.getWordValue(firstWord))+int(self.getWordValue(secondWord)) # 2. Get the value of the targetWord targetValue = int(self.getWordValue(targetWord)) # 3. return comparison boolean return sumValue == targetValue
check-if-word-equals-summation-of-two-words
Python Solutions & Explanations - Noobie version, Equivalent Lambda Version & extra thoughts.
antonmdv
0
48
check if word equals summation of two words
1,880
0.738
Easy
26,693
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1260062/Python-Solutions-and-Explanations-Noobie-version-Equivalent-Lambda-Version-and-extra-thoughts.
class Solution(object): def isSumEqual(self, firstWord, secondWord, targetWord): """ :type firstWord: str :type secondWord: str :type targetWord: str :rtype: bool """ numeric_value = lambda s: int(''.join([str(ord(letter)-97) for letter in s])) return numeric_value(firstWord) + numeric_value(secondWord) == numeric_value(targetWord)
check-if-word-equals-summation-of-two-words
Python Solutions & Explanations - Noobie version, Equivalent Lambda Version & extra thoughts.
antonmdv
0
48
check if word equals summation of two words
1,880
0.738
Easy
26,694
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1259787/python-3-%3A-super-easy-solution-%3A-)
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: f = "".join([str(ord(i)-97) for i in firstWord ]) # ord("a") = 97 s = "".join([str(ord(i)-97) for i in secondWord ]) t = "".join([str(ord(i)-97) for i in targetWord ]) return int(f) + int(s) == int(t)
check-if-word-equals-summation-of-two-words
python 3 : super easy solution : )
rohitkhairnar
0
118
check if word equals summation of two words
1,880
0.738
Easy
26,695
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1255097/python-3-using-ord()
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: def val(s): res="" for i in range(len(s)): res+=str(ord(s[i])-ord('a')) return int(res) return (val(targetWord)==val(firstWord)+val(secondWord))
check-if-word-equals-summation-of-two-words
python 3 using ord()
janhaviborde23
0
86
check if word equals summation of two words
1,880
0.738
Easy
26,696
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1242418/Python3-easy-solution
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: s = "abcdefghij" x1 = '' x2 = '' x3 = '' for i in firstWord: x1 += str(s.index(i)) x1 = int(x1) for i in secondWord: x2 += str(s.index(i)) x2 = int(x2) for i in targetWord: x3 += str(s.index(i)) x3 = int(x3) if x1+x2==x3:a return True else: return False
check-if-word-equals-summation-of-two-words
Python3 easy solution
Sanyamx1x
0
35
check if word equals summation of two words
1,880
0.738
Easy
26,697
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1242016/Python-simple-or-Hashmap
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: memo = {'a':'0', 'b':'1', 'c':'2', 'd':'3','e':'4', 'f':'5', 'g':'6', 'h':'7', 'i':'8','j':'9'} def manipulate(word, value): for i in word: value += memo[i] return int(value) return manipulate(firstWord, "") + manipulate(secondWord,"") == manipulate(targetWord,"")
check-if-word-equals-summation-of-two-words
Python simple | Hashmap
dee7
0
50
check if word equals summation of two words
1,880
0.738
Easy
26,698
https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/discuss/1241607/PythonPython3-solution-with-explanation
class Solution: def isSumEqual(self, firstWord: str, secondWord: str, targetWord: str) -> bool: alpha = 'abcdefghijklmnopqrstuvwxyz' firstNum,secondNum,targetNum = '','','' for i in firstWord: firstNum += str(alpha.index(i)) for i in secondWord: secondNum += str(alpha.index(i)) for i in targetWord: targetNum += str(alpha.index(i)) #print(firstNum,secondNum,targetNum) return int(firstNum)+int(secondNum) == int(targetNum)
check-if-word-equals-summation-of-two-words
Python/Python3 solution with explanation
prasanthksp1009
0
74
check if word equals summation of two words
1,880
0.738
Easy
26,699