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/minimum-initial-energy-to-finish-tasks/discuss/944714/Python-3-or-Sort-%2B-Greedy-and-Sort-%2B-Binary-Search-or-Explanation
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: tasks.sort(key=lambda x: x[0]-x[1]) def ok(mid): for actual, minimum in tasks: if minimum > mid or actual > mid: return False if minimum <= mid: mid -= actual return True l, r = 0, 10 ** 9 while l <= r: mid = (l+r) // 2 if ok(mid): r = mid - 1 else: l = mid + 1 return l
minimum-initial-energy-to-finish-tasks
Python 3 | Sort + Greedy & Sort + Binary Search | Explanation
idontknoooo
2
173
minimum initial energy to finish tasks
1,665
0.562
Hard
24,100
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/944714/Python-3-or-Sort-%2B-Greedy-and-Sort-%2B-Binary-Search-or-Explanation
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: tasks.sort(key=lambda x: x[0]-x[1]) ans = cur = 0 for cost, minimum in tasks: ans = min(cur-minimum, ans) cur -= cost return -ans
minimum-initial-energy-to-finish-tasks
Python 3 | Sort + Greedy & Sort + Binary Search | Explanation
idontknoooo
2
173
minimum initial energy to finish tasks
1,665
0.562
Hard
24,101
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/2551554/Python-solution-easy-without-heap-or-binary-search-just-sorting
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: t=tasks t.sort(key=lambda x:x[1]-x[0]) n=len(t) m=t[0][1] for i in range(n-1): m=max(m+t[i+1][0],t[i+1][1]) return m
minimum-initial-energy-to-finish-tasks
Python solution easy without heap or binary search just sorting
Gunbnelch
0
22
minimum initial energy to finish tasks
1,665
0.562
Hard
24,102
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/2424494/Python3-or-Binary-Search-%2B-Sorting-or-With-Intuition
class Solution: def isPossible(self,time,tasks): for f,r in tasks: if time<r: return False else: time-=f return time>=0 def minimumEffort(self, tasks: List[List[int]]) -> int: tasks.sort(key=lambda x:(x[1]-x[0]),reverse=True) sumTime=0 maxReq=0 for task in tasks: sumTime+=task[1] maxReq=max(maxReq,task[1]) low,high=maxReq,sumTime ans=0 while low<=high: mid=(low+high)>>1 if self.isPossible(mid,tasks): ans=mid high=mid-1 else: low=mid+1 return ans
minimum-initial-energy-to-finish-tasks
[Python3] | Binary Search + Sorting | With Intuition
swapnilsingh421
0
43
minimum initial energy to finish tasks
1,665
0.562
Hard
24,103
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/1533683/Python3-solution-comments
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: def cmp_items(a): #creating a custom sorting function (we want to sort by difference ~ from the biggest to the smallest) return a[0]-a[1] tasks.sort(key=cmp_items) my_energy = tasks[0][1] # how much we need to have at the start current_task = tasks[0][1] - tasks[0][0] # how much remains after we finish the first task for i in range(1, len(tasks)): if current_task < tasks[i][1]: my_energy += tasks[i][1] - current_task # how much we need to add in order to get the minimum to start the current task current_task += tasks[i][1] - current_task current_task -= tasks[i][0] # how much we have after finishing the current task return my_energy
minimum-initial-energy-to-finish-tasks
Python3 solution comments
FlorinnC1
0
65
minimum initial energy to finish tasks
1,665
0.562
Hard
24,104
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/1145204/Python3-Simple-Solution-faster-than-100
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: rem_energy = min_energy = sum(task[0] for task in tasks) #At first, minimum total energy=total actual energy tasks = sorted(tasks, key =lambda x:x[0]-x[1]) #Reverse sort the tasks based on the difference between the minimum and actual for task in tasks: if task[1]>rem_energy: #The minimum energy of the task is greater than the total remaining energy min_energy+=task[1]-rem_energy #So we need more energy rem_energy+=task[1]-rem_energy rem_energy-= task[0] #Some energy is spent to do the task, so reduce the amount of total remaining energy return min_energy
minimum-initial-energy-to-finish-tasks
Python3 Simple Solution, faster than 100%
bPapan
0
112
minimum initial energy to finish tasks
1,665
0.562
Hard
24,105
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/1100447/Python3-sorting
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: ans = val = 0 for x, y in sorted(tasks, key=lambda x: x[0]-x[1]): if val < y: ans += y - val val = y val -= x return ans
minimum-initial-energy-to-finish-tasks
[Python3] sorting
ye15
0
58
minimum initial energy to finish tasks
1,665
0.562
Hard
24,106
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/1100447/Python3-sorting
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: pq = [(x-y, y) for x, y in tasks] heapify(pq) ans = val = 0 while pq: x, y = heappop(pq) if val < y: ans += y - val val = y val -= x+y return ans
minimum-initial-energy-to-finish-tasks
[Python3] sorting
ye15
0
58
minimum initial energy to finish tasks
1,665
0.562
Hard
24,107
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/1068459/Python3-solution-faster-than-89.86-and-less-than-89.86
class Solution: def minimumEffort(self, tasks): tasks.sort(key = lambda x:x[1]-x[0], reverse = True) energy = tasks[0][1] remain = tasks[0][1] - tasks[0][0] for cost, threshold in tasks[1:]: if remain < threshold: energy += (threshold - remain) remain = threshold - cost else: remain -= cost return energy
minimum-initial-energy-to-finish-tasks
Python3 solution, faster than 89.86% and less than 89.86%
danieltseng
0
100
minimum initial energy to finish tasks
1,665
0.562
Hard
24,108
https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/945060/Python-very-Concise-Solution-oror-Dhruv-Vavliya
class Solution: def minimumEffort(self, tasks: List[List[int]]) -> int: energy=0 remain=0 ar=[] for task in range(len(tasks)): ar.append((tasks[task][1]-tasks[task][0],task)) ar.sort() for task in ar[::-1]: if tasks[task[1]][1]>remain: energy+=(tasks[task[1]][1]-remain) remain=task[0] else: remain-=tasks[task[1]][1] remain+=task[0] return energy
minimum-initial-energy-to-finish-tasks
Python -- very Concise Solution || Dhruv Vavliya
risky_coder
0
49
minimum initial energy to finish tasks
1,665
0.562
Hard
24,109
https://leetcode.com/problems/maximum-repeating-substring/discuss/1400359/Python3-Simple-Solution
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: i = 0 while word*(i+1) in sequence: i+=1 return i
maximum-repeating-substring
Python3, Simple Solution
Flerup
4
306
maximum repeating substring
1,668
0.396
Easy
24,110
https://leetcode.com/problems/maximum-repeating-substring/discuss/2192570/Python-simple-solution
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: for i in range(len(sequence)//len(word)+1,0,-1): if i*word in sequence: return i else: return 0
maximum-repeating-substring
Python simple solution
StikS32
1
134
maximum repeating substring
1,668
0.396
Easy
24,111
https://leetcode.com/problems/maximum-repeating-substring/discuss/1798591/Python3-solution-or-87-lesser-memory
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: c = 0 for i in range(1,len(sequence)//len(word)+1): if word*i in sequence: c += 1 continue break return c
maximum-repeating-substring
✔Python3 solution | 87% lesser memory
Coding_Tan3
1
203
maximum repeating substring
1,668
0.396
Easy
24,112
https://leetcode.com/problems/maximum-repeating-substring/discuss/1722457/Python-3-Short-and-Clean-using-find
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: n=len(sequence) m=len(word) c=0 for i in range(1,(n//m)+1): s=word*i if sequence.find(s)!=-1: c=i return c
maximum-repeating-substring
[Python 3] Short and Clean using find
akashmaurya001
1
95
maximum repeating substring
1,668
0.396
Easy
24,113
https://leetcode.com/problems/maximum-repeating-substring/discuss/1357665/KMP-True-O(n)
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: cnt = len(sequence)//len(word) repeat = word * cnt newstr = repeat + '#' + sequence lps = [0] maxi = 0 for i in range(1, len(newstr)): x = lps[-1] while newstr[x] != newstr[i]: if x == 0: x = -1 break x = lps[x-1] lps.append(x+1) if i>=len(repeat): maxi = max(maxi, x+1) return maxi//len(word)
maximum-repeating-substring
KMP True O(n)
deleted_user
1
174
maximum repeating substring
1,668
0.396
Easy
24,114
https://leetcode.com/problems/maximum-repeating-substring/discuss/1260385/python3-simple-solution
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: x = 0 while True: if word*(x+1) in sequence: x += 1 else: return x
maximum-repeating-substring
python3 simple solution
EklavyaJoshi
1
131
maximum repeating substring
1,668
0.396
Easy
24,115
https://leetcode.com/problems/maximum-repeating-substring/discuss/2726421/Python3-Linear-Masochist-Solution
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: # record the index of every match using kmp # then find the longest consecutive sequence (with diff = len(word)) # this is not an easy problem def kmp_failure(p): m = len(p) f = [0] * m i = 1 j = 0 while i < m: if p[j] == p[i]: f[i] = j+1 j += 1 i += 1 elif j > 0: j = f[j-1] else: f[i] = 0 i += 1 return f if len(word) > len(sequence): return 0 m = len(word) n = len(sequence) f = kmp_failure(word) i = 0 j = 0 res = 0 matches = dict() while i < n: if word[j] == sequence[i]: if j == m-1: if i-m in matches: matches[i] = matches[i-m] + 1 else: matches[i] = 1 if matches[i] > res: res = matches[i] # note that you shouldn't just go j += 1 here! # because you might skip a match if j > 0: j = f[j-1] else: i += 1 continue j += 1 i += 1 elif j > 0: j = f[j-1] else: i += 1 return res
maximum-repeating-substring
[Python3] Linear Masochist Solution
rt500
0
27
maximum repeating substring
1,668
0.396
Easy
24,116
https://leetcode.com/problems/maximum-repeating-substring/discuss/2643440/4-lines-python3-solution
class Solution: def maxRepeating(self, s: str, w: str) -> int: n =len(s)//len(w) for i in range(n,-1,-1): if w*i in s: return i
maximum-repeating-substring
4 lines python3 solution
abhayCodes
0
20
maximum repeating substring
1,668
0.396
Easy
24,117
https://leetcode.com/problems/maximum-repeating-substring/discuss/2601589/python-or-explanation-in-comments
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: seq_len = len(sequence) word_len = len(word) res, i = 0, 0 # return the number of times 'word' appears in continuation from index position 'idx' def get_k_reps(idx): acc = 1 while sequence[idx: idx + word_len * acc] == word * acc: acc += 1 return acc - 1 while i < seq_len - word_len + 1: # found match of word in the sliding window if sequence[i: i + word_len] == word: count = get_k_reps(i) res = max(count, res) i += 1 return res
maximum-repeating-substring
python | explanation in comments
sproq
0
28
maximum repeating substring
1,668
0.396
Easy
24,118
https://leetcode.com/problems/maximum-repeating-substring/discuss/2140008/Python-KMP-Simple-Solution
class Solution: def maxRepeating(self, sequence, word): maxCount_prefix = self.findMaxSubstring(word, sequence) maxCount_suffix = self.findMaxSubstring(word[::-1], sequence[::-1]) return max(maxCount_prefix, maxCount_suffix) def findMaxSubstring(self, pattern, text): lps = self.get_lps(pattern); currentSubstring, longestSubstring = 0, 0 i, j = 0, 0 while i < len(text): if text[i] == pattern[j]: i, j = i + 1, j + 1 if j == len(pattern): currentSubstring += 1 longestSubstring = max(currentSubstring, longestSubstring) j = 0 else: currentSubstring = 0 if j == 0: i += 1 else: j = lps[j - 1] return longestSubstring; def get_lps(self, pattern): lps = [0] * len(pattern) # first lps val will always be one prev_lps, i = 0, 1 while i < len(pattern): if pattern[i] == pattern[prev_lps]: lps[i] = prev_lps + 1 prev_lps, i = prev_lps + 1, i + 1 else: if prev_lps == 0: lps[i] = 0 i += 1 else: prev_lps = lps[prev_lps - 1] return lps
maximum-repeating-substring
Python - KMP Simple Solution
ErickMwazonga
0
84
maximum repeating substring
1,668
0.396
Easy
24,119
https://leetcode.com/problems/maximum-repeating-substring/discuss/2070486/Python-Two-Scans-Forward-And-Backward
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: def forward(): l, mx, current, i = len(word), 0, 0, 0 while i < len(sequence): if sequence[i : i + l] == word: current += 1 i += l - 1 elif current > 0: mx = max(mx, current) current = 0 i += 1 return max(mx, current) def backward(): l, mx, current, i = len(word), 0, 0, len(sequence) - 1 while i >= 0: w = sequence[i - l + 1 : i + 1] if w == word: current += 1 i -= l - 1 else: if current > 0: mx = max(mx, current) current = 0 i -= 1 return max(mx, current) return max(forward(), backward())
maximum-repeating-substring
Python Two Scans Forward And Backward
Hejita
0
86
maximum repeating substring
1,668
0.396
Easy
24,120
https://leetcode.com/problems/maximum-repeating-substring/discuss/1483628/While-loop-96-speed
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: count = 1 while word * count in sequence: count += 1 return count - 1
maximum-repeating-substring
While loop, 96% speed
EvgenySH
0
270
maximum repeating substring
1,668
0.396
Easy
24,121
https://leetcode.com/problems/maximum-repeating-substring/discuss/1118730/Python-easy-to-understand-with-find()
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: result = 0 for i in range(1, int(len(sequence) / len(word)) + 1): if sequence.find(word * i) != -1: result += 1 else: break return result
maximum-repeating-substring
[Python] easy to understand with find()
cruim
0
184
maximum repeating substring
1,668
0.396
Easy
24,122
https://leetcode.com/problems/maximum-repeating-substring/discuss/1093627/Python3-brute-force
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: ans = 0 for k in range(101): if word*k in sequence: ans = k return ans
maximum-repeating-substring
[Python3] brute-force
ye15
0
125
maximum repeating substring
1,668
0.396
Easy
24,123
https://leetcode.com/problems/maximum-repeating-substring/discuss/1093627/Python3-brute-force
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: if len(sequence) < len(word): return 0 # edge case pattern = word * (len(sequence)//len(word)) lps = [0] k = 0 for i in range(1, len(pattern)): while k and pattern[k] != pattern[i]: k = lps[k-1] if pattern[i] == pattern[k]: k += 1 lps.append(k) ans = k = 0 for i in range(len(sequence)): while k and pattern[k] != sequence[i]: k = lps[k-1] if pattern[k] == sequence[i]: k += 1 ans = max(ans, k//len(word)) if k == len(pattern): return ans return ans
maximum-repeating-substring
[Python3] brute-force
ye15
0
125
maximum repeating substring
1,668
0.396
Easy
24,124
https://leetcode.com/problems/maximum-repeating-substring/discuss/954431/Python-easy-and-efficient-solution
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: i = 0 n = len(word) m = len(sequence) c, k = 0, 0 # start traversing in the sequence while i < m: # if word found in sequence increase counter and increment loop by len(word) if sequence[i:i+n] == word: c += 1 i += n # edge-case # if end of sequence is reached and last letter is part of word assign k = max(k,c) if i == m: k = max(k,c) else: # assign k = max(previous max occurence of word , current max occurence) k = max(k,c) i += 1 c = 0 return k
maximum-repeating-substring
Python easy and efficient solution
kadarsh2k00
0
272
maximum repeating substring
1,668
0.396
Easy
24,125
https://leetcode.com/problems/maximum-repeating-substring/discuss/1763973/Python-dollarolution
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: if word not in sequence: return 0 i = 1 while len(word) * i < len(sequence)+1: if word*i in sequence: i += 1 else: break return i-1
maximum-repeating-substring
Python $olution
AakRay
-1
103
maximum repeating substring
1,668
0.396
Easy
24,126
https://leetcode.com/problems/maximum-repeating-substring/discuss/1761432/Python3-92-faster
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: count = 1 while True: if (word*count in sequence): count += 1 else: return count -1
maximum-repeating-substring
Python3 92% faster
ABinfinity
-1
81
maximum repeating substring
1,668
0.396
Easy
24,127
https://leetcode.com/problems/maximum-repeating-substring/discuss/955407/Newbie-Python3-Solution-%3A-24ms
class Solution: def maxRepeating(self, sequence: str, word: str) -> int: if word in sequence: replaced = sequence.replace(word, '0') else: return 0 flag, ans = 0, 0 for char in replaced: if char == '0': flag += 1 else: ans = max(ans, flag) flag = 0 ans = max(ans, flag) return ans
maximum-repeating-substring
[Newbie Python3 Solution : 24ms]
user6148Qk
-1
104
maximum repeating substring
1,668
0.396
Easy
24,128
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/1833998/Python3-oror-Explanation-and-Example
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: curr=list1 for count in range(b): if count==a-1: # travel to a node and --> step 1 start=curr # then save pointer in start curr=curr.next # continue travel to b node --> step 2 start.next=list2 # point start to list2 --> step3 while list2.next: # travel list2 --> step 4 list2=list2.next list2.next=curr.next # map end of list2 to b return list1
merge-in-between-linked-lists
Python3 || Explanation & Example
rushi_javiya
2
48
merge in between linked lists
1,669
0.745
Medium
24,129
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/1387631/Python3-greater85-2-Pointer-Solution.-O(N)-O(1)-Space
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: point1 = list1 point2 = list1 for _ in range(b - a): point2 = point2.next prev = None for _ in range(a): prev = point1 point1 = point1.next point2 = point2.next prev.next = list2 while list2.next: list2 = list2.next list2.next = point2.next return list1
merge-in-between-linked-lists
[Python3] >85% 2 Pointer Solution. O(N), O(1) Space
whitehatbuds
2
185
merge in between linked lists
1,669
0.745
Medium
24,130
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/2828012/python
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: dummynode = ListNode(-1, list1) curr = dummynode idx = 0 while curr.next: if idx == a: head = curr curr = curr.next head.next = list2 while list2.next: list2 = list2.next if idx == b: list2.next = curr.next break curr = curr.next idx += 1 return dummynode.next
merge-in-between-linked-lists
python
xy01
0
1
merge in between linked lists
1,669
0.745
Medium
24,131
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/2764595/Python3-Solution
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: temp = list1 x = None while a > 0: x = temp temp = temp.next a -= 1 temp1 = list1 while b > 0: temp1 = temp1.next b -= 1 temp2 = list2 while temp2.next != None: temp2 = temp2.next if x is not None: x.next = list2 else: list1 = list2 temp2.next = temp1.next return list1
merge-in-between-linked-lists
Python3 Solution
mediocre-coder
0
3
merge in between linked lists
1,669
0.745
Medium
24,132
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/2597438/Python3-solution-O(N)-time-complexity-O(1)-space-complexity-99-less-memory
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: prev, first, second = None, list1, list1 #Moves the second pointer forward while b - a > 0: second = second.next b -= 1 #Moves all pointers forward while a > 0: prev = first first = first.next second = second.next a -= 1 #prev is the tail in the first part of list1, link the next pointer to list2 head prev.next = list2 #Iterates through the second list curr = list2 while curr.next: curr = curr.next #Attaches to the tail of list2 the second part of list1 (second is the last node to be removed) curr.next = second.next return list1
merge-in-between-linked-lists
Python3 solution, O(N) time complexity, O(1) space complexity, 99% less memory
matteogianferrari
0
15
merge in between linked lists
1,669
0.745
Medium
24,133
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/2579606/Python-Readable-O(N%2BM)-pass
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: # keep the list head head = list1 # get to the first node for _ in range(a-1): list1 = list1.next # save the next node (to continue iterating list1) curr = list1.next # stitch together list1.next = list2 # go right after the second node for _ in range(b-a+1): curr = curr.next # get the end of list2 while list2.next is not None: list2 = list2.next # stitch together list2.next = curr return head
merge-in-between-linked-lists
[Python] - Readable O(N+M) pass
Lucew
0
13
merge in between linked lists
1,669
0.745
Medium
24,134
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/2519595/Python-or-Explained-2-pointer-Solution-or-Faster-than-99.87-or-Less-memory-than-93.79
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: l1, l2 = list1, list2 for _ in range(a - 1): l1 = l1.next temp = l1.next l1.next = list2 for _ in range(b - a + 1): temp = temp.next while l2.next: l2 = l2.next l2.next = temp return list1
merge-in-between-linked-lists
Python | Explained 2-pointer Solution | Faster than 99.87% | Less memory than 93.79%
ahmadheshamzaki
0
26
merge in between linked lists
1,669
0.745
Medium
24,135
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/2344596/Easy-python
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: #iterate on list2 to find last pointer curr=list2 while curr: if curr.next==None: last2 = curr curr=curr.next c=0 #iterate on list1 prev=list1 curr=list1.next while curr: if c==a-1: prev.next=list2 #point a-1th to list2 elif c==b: last2.next = curr #point last pointer after bth node prev=curr c+=1 curr=curr.next return list1
merge-in-between-linked-lists
Easy python
sunakshi132
0
15
merge in between linked lists
1,669
0.745
Medium
24,136
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/2274149/Simple-Python-Solution-Easy-to-Understand!
class Solution(object): def mergeInBetween(self, list1, indexA, indexB, list2): currentOne = temp = list1 currentTwo = list2 # find node before where A starts for _ in range(indexA-1): currentOne = currentOne.next # find node after where B ends for _ in range(indexB+1): temp = temp.next # find end of list2 while currentTwo.next is not None: currentTwo = currentTwo.next currentOne.next = list2 # connect list1 to the head of list2 where before A starts currentTwo.next = temp # connect the end of list2 to the rest of list1 where after B ends return list1 ```
merge-in-between-linked-lists
Simple [Python] Solution, Easy to Understand!
ufultra
0
27
merge in between linked lists
1,669
0.745
Medium
24,137
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/1999818/python-3-oror-simple-O(b-%2B-m)-solution
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: prevA = dummy1 = ListNode(0, list1) for _ in range(a): prevA = prevA.next nextB = prevA for _ in range(b - a + 2): nextB = nextB.next end2 = list2 while end2.next: end2 = end2.next prevA.next = list2 end2.next = nextB return dummy1.next
merge-in-between-linked-lists
python 3 || simple O(b + m) solution
dereky4
0
23
merge in between linked lists
1,669
0.745
Medium
24,138
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/1093472/Python3-2-pass
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: node = list1 for k in range(b+1): if k == a-1: start = node node = node.next end = node start.next = node = list2 while node.next: node = node.next node.next = end return list1
merge-in-between-linked-lists
[Python3] 2-pass
ye15
0
24
merge in between linked lists
1,669
0.745
Medium
24,139
https://leetcode.com/problems/merge-in-between-linked-lists/discuss/1071317/python-3-solution-beat-74
class Solution: def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode: head=list1 c=0 while(c<=b): if c==a-1: prev=list1 list1=list1.next prev.next=list2 else: list1=list1.next c+=1 while(list2.next): list2=list2.next list2.next=list1 return head
merge-in-between-linked-lists
python 3 solution beat 74%
AchalGupta
0
58
merge in between linked lists
1,669
0.745
Medium
24,140
https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/discuss/1543614/Python-oror-Easy-Solution
class Solution: def minimumMountainRemovals(self, lst: List[int]) -> int: l = len(lst) dp = [0] * l dp1 = [0] * l for i in range(l): # for increasing subsequence maxi = 0 for j in range(i): if lst[i] > lst[j]: if dp[j] > maxi: maxi = dp[j] dp[i] = maxi + 1 for i in range(l - 1, -1, -1): # for decreasing subsequence maxi1 = 0 for j in range(l - 1, i, -1): if lst[i] > lst[j]: if dp1[j] > maxi1: maxi1 = dp1[j] dp1[i] = maxi1 + 1 ans = 0 for i in range(l): if dp[i] > 1 and dp1[i] > 1: temp = dp[i] + dp1[i] - 1 if temp > ans: ans = temp return l - ans
minimum-number-of-removals-to-make-mountain-array
Python || Easy Solution
naveenrathore
2
209
minimum number of removals to make mountain array
1,671
0.425
Hard
24,141
https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/discuss/1722955/python3%3A-TIme-Complexity-O(n2)
class Solution: def minimumMountainRemovals(self, nums: List[int]) -> int: n = len(nums) left = [0 for i in range(n)] right = [0 for i in range(n)] for i in range(1, n): val = 0 for j in range(i): if nums[j] < nums[i]: val = max(val, left[j] + 1) left[i] = val for i in range(n - 2, -1, -1): val = 0 for j in range(i + 1, n): if nums[j] < nums[i]: val = max(val, right[j] + 1) right[i] = val ans = inf for i in range(1, n - 1): if left[i] > 0 and right[i] > 0: ans = min(ans, n - 1 - left[i] - right[i]) return ans
minimum-number-of-removals-to-make-mountain-array
python3: TIme Complexity O(n^2)
reynaldocv
1
64
minimum number of removals to make mountain array
1,671
0.425
Hard
24,142
https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/discuss/1093648/Python3-linearithmic-solution
class Solution: def minimumMountainRemovals(self, nums: List[int]) -> int: def fn(nums): """Return length of LIS (excluding x) ending at x.""" ans, vals = [], [] for i, x in enumerate(nums): k = bisect_left(vals, x) if k == len(vals): vals.append(x) else: vals[k] = x ans.append(k) return ans left, right = fn(nums), fn(nums[::-1])[::-1] ans = inf for i in range(1, len(nums)-1): if left[i] and right[i]: ans = min(ans, len(nums) - left[i] - right[i] - 1) return ans
minimum-number-of-removals-to-make-mountain-array
[Python3] linearithmic solution
ye15
0
93
minimum number of removals to make mountain array
1,671
0.425
Hard
24,143
https://leetcode.com/problems/richest-customer-wealth/discuss/2675823/Python-or-1-liner-simple-solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max([sum(acc) for acc in accounts])
richest-customer-wealth
Python | 1-liner simple solution
LordVader1
36
2,200
richest customer wealth
1,672
0.882
Easy
24,144
https://leetcode.com/problems/richest-customer-wealth/discuss/1077433/faster-than-98.4-submissions....python-basics
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: res=[] for i in accounts: res.append(sum(i)) return max(res) ```easy solution using python basics
richest-customer-wealth
faster than 98.4% submissions....python basics
yashwanthreddz
5
795
richest customer wealth
1,672
0.882
Easy
24,145
https://leetcode.com/problems/richest-customer-wealth/discuss/2231650/Beginner-Friendly-Solution-oror-Fast!!-oror-Python
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: # Use the variable below to remember the highest sum. wealth = 0 for customer in accounts: # The sum() function below can be replaced with another for-loop in order to traverse the nested lists. # In this case, however, the function approach makes it simpler. s = sum(customer) if wealth < s: wealth = s return wealth
richest-customer-wealth
Beginner Friendly Solution || Fast!! || Python
cool-huip
4
114
richest customer wealth
1,672
0.882
Easy
24,146
https://leetcode.com/problems/richest-customer-wealth/discuss/2071570/Python-Easy-Solution-oror-One-Liner
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max([sum(i) for i in accounts])
richest-customer-wealth
Python Easy Solution || One Liner
Shivam_Raj_Sharma
4
138
richest customer wealth
1,672
0.882
Easy
24,147
https://leetcode.com/problems/richest-customer-wealth/discuss/2071570/Python-Easy-Solution-oror-One-Liner
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: arr = [] for i in range(len(accounts)): wealth = 0 for j in accounts[i]: wealth += j arr.append(wealth) return max(arr)
richest-customer-wealth
Python Easy Solution || One Liner
Shivam_Raj_Sharma
4
138
richest customer wealth
1,672
0.882
Easy
24,148
https://leetcode.com/problems/richest-customer-wealth/discuss/1655228/Python-Easy-Solution-or-One-liner
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum, accounts))
richest-customer-wealth
Python Easy Solution | One-liner ✔
leet_satyam
4
179
richest customer wealth
1,672
0.882
Easy
24,149
https://leetcode.com/problems/richest-customer-wealth/discuss/1733401/Python-3-(40ms)-or-2-Pythonic-Solutions-or-One-Liner-Easy-to-Understand
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: m=0 for i in accounts: m = max(m,sum(i)) return m
richest-customer-wealth
Python 3 (40ms) | 2 Pythonic Solutions | One-Liner Easy to Understand
MrShobhit
3
161
richest customer wealth
1,672
0.882
Easy
24,150
https://leetcode.com/problems/richest-customer-wealth/discuss/1733401/Python-3-(40ms)-or-2-Pythonic-Solutions-or-One-Liner-Easy-to-Understand
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum,accounts))
richest-customer-wealth
Python 3 (40ms) | 2 Pythonic Solutions | One-Liner Easy to Understand
MrShobhit
3
161
richest customer wealth
1,672
0.882
Easy
24,151
https://leetcode.com/problems/richest-customer-wealth/discuss/1697292/Python-code%3A-Richest-Customer-Wealth
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: arr=[] for i in accounts: arr.append(sum(i)) return max(arr)
richest-customer-wealth
Python code: Richest Customer Wealth
Anilchouhan181
3
160
richest customer wealth
1,672
0.882
Easy
24,152
https://leetcode.com/problems/richest-customer-wealth/discuss/1154494/Python-using-sum-and-max
class Solution(object): def maximumWealth(self, accounts): """ :type accounts: List[List[int]] :rtype: int """ max_wealth = 0 for account in accounts: wealth = sum(account) max_wealth = max(wealth, max_wealth) return max_wealth
richest-customer-wealth
Python using sum and max
5tigerjelly
3
237
richest customer wealth
1,672
0.882
Easy
24,153
https://leetcode.com/problems/richest-customer-wealth/discuss/952803/Python3-1-line
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum, accounts))
richest-customer-wealth
[Python3] 1-line
ye15
3
121
richest customer wealth
1,672
0.882
Easy
24,154
https://leetcode.com/problems/richest-customer-wealth/discuss/2361059/one-line-or-Success-Details-faster-than-100.00-or-Python3
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max([sum(i) for i in accounts])
richest-customer-wealth
one line | Success Details faster than 100.00% | Python3
vimla_kushwaha
2
94
richest customer wealth
1,672
0.882
Easy
24,155
https://leetcode.com/problems/richest-customer-wealth/discuss/2234469/Python3-simple-solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: result = 0 for i in range(len(accounts)): result = max(result, sum(accounts[i])) return result
richest-customer-wealth
📌 Python3 simple solution
Dark_wolf_jss
2
69
richest customer wealth
1,672
0.882
Easy
24,156
https://leetcode.com/problems/richest-customer-wealth/discuss/2145674/Python-Easy-and-Simple-Solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: maxwealth=0 for i in range(len(accounts)): maxwealth=max(sum(accounts[i]), maxwealth) return maxwealth
richest-customer-wealth
Python Easy and Simple Solution
pruthashouche
2
67
richest customer wealth
1,672
0.882
Easy
24,157
https://leetcode.com/problems/richest-customer-wealth/discuss/1312458/WEEB-DOES-PYTHON
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: cur_max = 0 for money in accounts: if sum(money) > cur_max: cur_max = sum(money) return cur_max
richest-customer-wealth
WEEB DOES PYTHON
Skywalker5423
2
118
richest customer wealth
1,672
0.882
Easy
24,158
https://leetcode.com/problems/richest-customer-wealth/discuss/1151108/Python3-Simple-Solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: ans = 0 for i in accounts: ans = max(ans , sum(i)) return ans
richest-customer-wealth
[Python3] Simple Solution
Lolopola
2
78
richest customer wealth
1,672
0.882
Easy
24,159
https://leetcode.com/problems/richest-customer-wealth/discuss/2348319/Riches-man's-wealth-Python-simple-one
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: # Initialize the maximum wealth seen so far to 0 (the minimum wealth possible) max_wealth_so_far = 0 # Iterate over accounts for account in accounts: # Add the money in each bank curr_customer_wealth = sum(account) # Update the maximum wealth seen so far if the current wealth is greater # If it is less than the current sum max_wealth_so_far = max(max_wealth_so_far, curr_customer_wealth) # Return the maximum wealth return max_wealth_so_far
richest-customer-wealth
Riches man's wealth Python simple one
RohanRob
1
96
richest customer wealth
1,672
0.882
Easy
24,160
https://leetcode.com/problems/richest-customer-wealth/discuss/2328819/Python3-or-Easy-Solution-or-3-line-soution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: res = 0 temp = list(map(lambda x: sum(x), accounts)) return max(temp)
richest-customer-wealth
Python3 | Easy Solution | 3 line soution
irapandey
1
86
richest customer wealth
1,672
0.882
Easy
24,161
https://leetcode.com/problems/richest-customer-wealth/discuss/2250216/Python3-Runtime%3A-60ms-oror-Memory%3A-13.9mb-32.16
class Solution: # O(rc) || O(n) # Runtime: 60ms || Memory: 13.9mb 32.16% def maximumWealth(self, accounts: List[List[int]]) -> int: maxWealth = float('-inf') for row in range(len(accounts)): runningSum = 0 for col in range(len(accounts[row])): runningSum += accounts[row][col] maxWealth = max(maxWealth, runningSum) return maxWealth
richest-customer-wealth
Python3 Runtime: 60ms || Memory: 13.9mb 32.16%
arshergon
1
30
richest customer wealth
1,672
0.882
Easy
24,162
https://leetcode.com/problems/richest-customer-wealth/discuss/1972374/maximum-sum-easy-python3-solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: c=0 #Intialising a counter variable for comparison for i in range(len(accounts)): #looping through the entire list of lists temp_list = accounts[i] #storing the list sum=0 for j in range(len(temp_list)): #looping through the particular list sum=sum+temp_list[j] #adding all the elements in the list if sum>c: #for getting the maximum value c=sum sum=0 return c
richest-customer-wealth
maximum sum easy python3 solution
vishwahiren16
1
72
richest customer wealth
1,672
0.882
Easy
24,163
https://leetcode.com/problems/richest-customer-wealth/discuss/1954990/Richest-customer-wealth
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: max_num = max(sum(i) for i in accounts) return max_num
richest-customer-wealth
Richest customer wealth
vidamaleki
1
29
richest customer wealth
1,672
0.882
Easy
24,164
https://leetcode.com/problems/richest-customer-wealth/discuss/1936445/Python-3-One-Liner-FASTER-THAN-988
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum, accounts))
richest-customer-wealth
[Python 3] One-Liner, FASTER THAN 98,8%
tender777
1
50
richest customer wealth
1,672
0.882
Easy
24,165
https://leetcode.com/problems/richest-customer-wealth/discuss/1733409/Python-Easy-To-Understand-Approach-With-Explanation
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: maxWealth = 0 for money in accounts: # Finding the max value between our current max and previous max maxWealth = max(sum(money), maxWealth) return maxWealth
richest-customer-wealth
Python Easy To Understand Approach With Explanation
pniraj657
1
41
richest customer wealth
1,672
0.882
Easy
24,166
https://leetcode.com/problems/richest-customer-wealth/discuss/1717329/1672-richest-customer-wealth-or-greater-97
class Solution(object): def maximumWealth(self, accounts): """ :type accounts: List[List[int]] :rtype: int """ max_money = 0 for sbi in accounts: money = sum(sbi) if money > max_money: max_money = money return max_money
richest-customer-wealth
1672 - richest customer wealth | > 97%
ankit61d
1
51
richest customer wealth
1,672
0.882
Easy
24,167
https://leetcode.com/problems/richest-customer-wealth/discuss/1715043/1672.-Richest-Customer-Wealth-easy-python-solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: lis=[] for x in accounts: lis.append(sum(x)) return max(lis)
richest-customer-wealth
1672. Richest Customer Wealth easy python solution
apoorv11jain
1
76
richest customer wealth
1,672
0.882
Easy
24,168
https://leetcode.com/problems/richest-customer-wealth/discuss/1450079/One-line-simple-solution-faster-than-98.42
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max([sum(acc) for acc in accounts ])
richest-customer-wealth
One line simple solution faster than 98.42%
1_d99
1
232
richest customer wealth
1,672
0.882
Easy
24,169
https://leetcode.com/problems/richest-customer-wealth/discuss/1374464/Python3-One-Liner-or-Using-map-max-sum
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum, accounts))
richest-customer-wealth
[Python3] One Liner | Using map, max, sum
say4n
1
55
richest customer wealth
1,672
0.882
Easy
24,170
https://leetcode.com/problems/richest-customer-wealth/discuss/1172860/Simple-Python-Solutions%3A-Multiple-Approaches_O(n*m)
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: max_wealth = 0 for c in accounts: c_wealth = sum(c) if c_wealth > max_wealth: max_wealth = c_wealth return max_wealth
richest-customer-wealth
Simple Python Solutions: Multiple Approaches_O(n*m)
smaranjitghose
1
96
richest customer wealth
1,672
0.882
Easy
24,171
https://leetcode.com/problems/richest-customer-wealth/discuss/1172860/Simple-Python-Solutions%3A-Multiple-Approaches_O(n*m)
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(map(sum,accounts))
richest-customer-wealth
Simple Python Solutions: Multiple Approaches_O(n*m)
smaranjitghose
1
96
richest customer wealth
1,672
0.882
Easy
24,172
https://leetcode.com/problems/richest-customer-wealth/discuss/1157010/Python3-one-liner-easy-and-understandable
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max([sum(i) for i in accounts])
richest-customer-wealth
Python3 one-liner easy and understandable
adarsh__kn
1
89
richest customer wealth
1,672
0.882
Easy
24,173
https://leetcode.com/problems/richest-customer-wealth/discuss/1142266/Python-99.77-faster
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: newX = 0 for x in accounts: if newX < sum(x): newX = sum(x) return newX
richest-customer-wealth
Python 99.77% faster
Valarane
1
101
richest customer wealth
1,672
0.882
Easy
24,174
https://leetcode.com/problems/richest-customer-wealth/discuss/1137766/Python3-32ms-(with-comments)
class Solution(object): def maximumWealth(self, accounts): """ :type accounts: List[List[int]] :rtype: int """ #declaring the sum of 1st list in the accounts as the biggest value result = sum(accounts[0]) #looping through each list in the accounts list for account in accounts: #finding the sum of each list maximum = sum(account) #checking if this list is the largest ever encountered if maximum > result: #If yes, then declaring it as the largest in the result variable result = maximum return result
richest-customer-wealth
Python3 32ms (with comments)
Akshar-code
1
112
richest customer wealth
1,672
0.882
Easy
24,175
https://leetcode.com/problems/richest-customer-wealth/discuss/2838948/Python-Fast-and-Simple-Solution
class Solution: def maximumWealth(self, accounts): richest = 0 for i in range(len(accounts)): localTotal = 0 for j in range((len(accounts[i]))): localTotal += accounts[i][j] if localTotal > richest: richest = localTotal return richest
richest-customer-wealth
Python - Fast & Simple Solution
BladeStew
0
1
richest customer wealth
1,672
0.882
Easy
24,176
https://leetcode.com/problems/richest-customer-wealth/discuss/2838422/Solution-(Beginner)
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: y =[] for x in accounts: t = sum(x) y.append(t) return max(y)
richest-customer-wealth
Solution (Beginner)
arob3303
0
1
richest customer wealth
1,672
0.882
Easy
24,177
https://leetcode.com/problems/richest-customer-wealth/discuss/2828803/Python-3-lines-oror-Faster-than-97.95-and-Memory-Beats-98.38!!
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: m = 0 for a in accounts: m = max(sum(a), m) return m
richest-customer-wealth
Python 3-lines ✅✅✅ || Faster than 97.95% and Memory Beats 98.38%!!
qiy2019
0
3
richest customer wealth
1,672
0.882
Easy
24,178
https://leetcode.com/problems/richest-customer-wealth/discuss/2826236/Fast-and-Simple-Python-Solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: reference = 0 for i in accounts: wealth = 0 for j in i: wealth += j if wealth > reference: reference = wealth return reference
richest-customer-wealth
Fast and Simple Python Solution
PranavBhatt
0
2
richest customer wealth
1,672
0.882
Easy
24,179
https://leetcode.com/problems/richest-customer-wealth/discuss/2821549/One-Liner-approach
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(sum(i) for i in accounts)
richest-customer-wealth
One Liner approach
prathambhatiapersonal
0
3
richest customer wealth
1,672
0.882
Easy
24,180
https://leetcode.com/problems/richest-customer-wealth/discuss/2818359/The-simplest
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: result = [] for i in range(len(accounts)): result.append(sum(accounts[i])) return max(result)
richest-customer-wealth
The simplest
pkozhem
0
2
richest customer wealth
1,672
0.882
Easy
24,181
https://leetcode.com/problems/richest-customer-wealth/discuss/2810584/Easily-steps-Python3
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: wealth = 0 for i in range(len(accounts)): wealth = max(sum(accounts[i]), wealth) return wealth
richest-customer-wealth
Easily steps Python3
Ar_elazazi007
0
3
richest customer wealth
1,672
0.882
Easy
24,182
https://leetcode.com/problems/richest-customer-wealth/discuss/2805396/Pure-Algorithmic-Solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: max = 0 # initialize the max value for i in range(len(accounts)): # loop through all of the rows sum = 0 # define and set a local running sum for j in range(len(accounts[i])): # loop through all of the columns sum += accounts[i][j] # add up the values in the columns if sum > max: # check to see if the total of this column is the largest max = sum # if it is, set it to the max. return max
richest-customer-wealth
Pure Algorithmic Solution
cyber-patriot517
0
3
richest customer wealth
1,672
0.882
Easy
24,183
https://leetcode.com/problems/richest-customer-wealth/discuss/2803202/Simple-and-easy-way
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: a=[] for i in accounts: a.append(sum(i)) return max(a)
richest-customer-wealth
Simple and easy way
chetan21
0
1
richest customer wealth
1,672
0.882
Easy
24,184
https://leetcode.com/problems/richest-customer-wealth/discuss/2799357/simple-solution-with-python-list-functions
class Solution: def maximumWealth(self, accounts: List[List[int]]): listout = [] for li in accounts: listout.append(sum(li)) return max(listout)
richest-customer-wealth
simple solution with python list functions
peralaarun91
0
2
richest customer wealth
1,672
0.882
Easy
24,185
https://leetcode.com/problems/richest-customer-wealth/discuss/2799356/simple-solution-with-python-list-functions
class Solution: def maximumWealth(self, accounts: List[List[int]]): listout = [] for li in accounts: listout.append(sum(li)) return max(listout)
richest-customer-wealth
simple solution with python list functions
peralaarun91
0
1
richest customer wealth
1,672
0.882
Easy
24,186
https://leetcode.com/problems/richest-customer-wealth/discuss/2788547/Python-easy-solution
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: richest = 0 for li in accounts: totalAmount = 0 for num in li: totalAmount += num if totalAmount > richest: richest = totalAmount return richest
richest-customer-wealth
Python easy solution
kamman626
0
1
richest customer wealth
1,672
0.882
Easy
24,187
https://leetcode.com/problems/richest-customer-wealth/discuss/2787219/python3-%3A-T-O(n)-S-O(1)
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: richest=0 print(len(accounts)) for i in accounts: if sum(i)>richest: richest=sum(i) return richest
richest-customer-wealth
python3 : T-O(n) , S-O(1)
fancyuserid
0
2
richest customer wealth
1,672
0.882
Easy
24,188
https://leetcode.com/problems/richest-customer-wealth/discuss/2786424/Easy-with-Python-for-the-Richest-Customer-Wealth-Task
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: return max(sum(customer_account) for customer_account in accounts)
richest-customer-wealth
Easy with Python for the Richest Customer Wealth Task
Bassel_Alf
0
2
richest customer wealth
1,672
0.882
Easy
24,189
https://leetcode.com/problems/richest-customer-wealth/discuss/2783447/Simple-Python-Solution-oror-Easy-and-Explained
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: max1 = 0 sum1 = 0 for i in accounts: sum1 = sum(i) if sum1>max1: max1 = sum1 return max1
richest-customer-wealth
Simple Python Solution || Easy & Explained
dnvavinash
0
1
richest customer wealth
1,672
0.882
Easy
24,190
https://leetcode.com/problems/richest-customer-wealth/discuss/2781059/Python3-or-Faster-than-97-or-Simple-w-less15-lines
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: most = 0 for e in accounts: current = 0 current += sum(e) if current > most: most = current else: continue return most
richest-customer-wealth
[Python3] | Faster than 97% | Simple w/ <15 lines
xzvg
0
4
richest customer wealth
1,672
0.882
Easy
24,191
https://leetcode.com/problems/richest-customer-wealth/discuss/2772551/Python-Brute-Force-simple-solution-for-beginners
class Solution: def maximumWealth(self, accounts: List[List[int]]) -> int: maxwealth=0 for i in range(len(accounts)): maxwealth=max(maxwealth,sum(accounts[i])) return maxwealth
richest-customer-wealth
Python Brute Force simple solution for beginners
mritunjayyy
0
2
richest customer wealth
1,672
0.882
Easy
24,192
https://leetcode.com/problems/find-the-most-competitive-subsequence/discuss/953711/Python3-greedy-O(N)
class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: stack = [] # (increasing) mono-stack for i, x in enumerate(nums): while stack and stack[-1] > x and len(stack) + len(nums) - i > k: stack.pop() if len(stack) < k: stack.append(x) return stack
find-the-most-competitive-subsequence
[Python3] greedy O(N)
ye15
6
342
find the most competitive subsequence
1,673
0.493
Medium
24,193
https://leetcode.com/problems/find-the-most-competitive-subsequence/discuss/953711/Python3-greedy-O(N)
class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: ans, pq = [], [] prev = -inf for i, x in enumerate(nums): heappush(pq, (x, i)) if i+k >= len(nums): while pq and pq[0][1] < prev: heappop(pq) x, prev = heappop(pq) ans.append(x) return ans
find-the-most-competitive-subsequence
[Python3] greedy O(N)
ye15
6
342
find the most competitive subsequence
1,673
0.493
Medium
24,194
https://leetcode.com/problems/find-the-most-competitive-subsequence/discuss/1027570/O(n)-time-and-O(n)-space-python3-solution-accepted-(STACK)
class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: i=0 n=len(nums) res_len=0 stack=[] while(i<n): while(stack and (n-i)>k-res_len and stack[-1]>nums[i]): stack.pop() res_len-=1 else: if(res_len<k): stack.append(nums[i]) res_len+=1 i+=1 return stack
find-the-most-competitive-subsequence
O(n) time and O(n) space python3 solution accepted (STACK)
_Rehan12
2
54
find the most competitive subsequence
1,673
0.493
Medium
24,195
https://leetcode.com/problems/find-the-most-competitive-subsequence/discuss/2790817/Monotonic-Stack-Solution
class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: stack,N=[],len(nums) for i,x in enumerate(nums): while(stack and stack[-1] >x and len(stack) + N-i >k ): ##put some condition on i also so that relevant length subs is formed stack.pop() stack.append(x) return stack[:k]
find-the-most-competitive-subsequence
Monotonic Stack Solution
shadowfax_1024
0
3
find the most competitive subsequence
1,673
0.493
Medium
24,196
https://leetcode.com/problems/find-the-most-competitive-subsequence/discuss/2333991/Python-monotonic-stack.-O(N)O(k)
class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: stack = [] for i, n in enumerate(nums): while stack and stack[-1] > n and len(stack) + len(nums) - i > k: stack.pop() if len(stack) < k: stack.append(n) return stack
find-the-most-competitive-subsequence
Python, monotonic stack. O(N)/O(k)
blue_sky5
0
33
find the most competitive subsequence
1,673
0.493
Medium
24,197
https://leetcode.com/problems/find-the-most-competitive-subsequence/discuss/1736203/Python3-or-Monotonic-Stack
class Solution: def mostCompetitive(self, nums: List[int], k: int) -> List[int]: n=len(nums) stack=[] top=0 for i in range(n): diff=n-i while stack and top+diff>k and stack[top-1]>nums[i]: stack.pop() top-=1 if top<k: stack.append(nums[i]) top+=1 return stack
find-the-most-competitive-subsequence
[Python3] | Monotonic Stack
swapnilsingh421
0
34
find the most competitive subsequence
1,673
0.493
Medium
24,198
https://leetcode.com/problems/find-the-most-competitive-subsequence/discuss/953091/Python3-Solution-using-stack
class Solution: def __init__(self): self.stack = [] self.toRemove = 0 def mostCompetitive(self, nums: List[int], k: int) -> List[int]: self.stack.append(nums[0]) self.toRemove = len(nums) - k for i in range(1,len(nums)): while(self.stack and self.toRemove>0 and self.stack[-1]>nums[i]): self.toRemove -= 1 self.stack.pop() self.stack.append(nums[i]) while(self.toRemove>0 or len(self.stack)>k): self.toRemove -= 1 self.stack.pop() return self.stack
find-the-most-competitive-subsequence
Python3 Solution using stack
swap2001
0
53
find the most competitive subsequence
1,673
0.493
Medium
24,199