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-operations-to-make-a-uni-value-grid/discuss/2665809/O(mn-*-log(mn)) | class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
m=len(grid)
n=len(grid[0])
mn=float('inf')
numlist=[]
for i in range(m):
for j in range(n):
numlist.append(grid[i][j])
numlist.sort()
target=numlist[m*n/... | minimum-operations-to-make-a-uni-value-grid | O(mn * log(mn)) | ConfusedMoe | 0 | 2 | minimum operations to make a uni value grid | 2,033 | 0.524 | Medium | 28,300 |
https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/discuss/2049908/python-3-oror-sorting-and-median-solution | class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
m, n = len(grid), len(grid[0])
nums = sorted(grid[i][j] for i in range(m) for j in range(n))
firstModX = nums[0] % x
median = nums[(m*n - 1) // 2]
operations = 0
for num i... | minimum-operations-to-make-a-uni-value-grid | python 3 || sorting and median solution | dereky4 | 0 | 43 | minimum operations to make a uni value grid | 2,033 | 0.524 | Medium | 28,301 |
https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/discuss/1886433/Similar-questions-like-this-%3A | class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
nums=[]
for i in grid:
nums+=i
nums.sort()
ans=0
median=nums[len(nums)//2]
for i in nums:
dist=abs(i-median)
if dist%x!=0:
retur... | minimum-operations-to-make-a-uni-value-grid | Similar questions like this : | goxy_coder | 0 | 65 | minimum operations to make a uni value grid | 2,033 | 0.524 | Medium | 28,302 |
https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/discuss/1538881/Easy-Methord-oror-Begineer | class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
nums = []
for row in grid:
for num in row:
nums.append(num)
nums.sort()
m1=nums[0]%x
for i in nums:
if i%x!=m1:return -1
median =... | minimum-operations-to-make-a-uni-value-grid | Easy Methord || Begineer | vkn84527 | 0 | 87 | minimum operations to make a uni value grid | 2,033 | 0.524 | Medium | 28,303 |
https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/discuss/1519881/Python3-easy-solution-using-sorting | class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
temp = []
for i in grid:
temp += i
temp.sort()
start = temp[0]%x
if any(y % x != start for y in temp):
return -1
mid = len(temp)//2 if len... | minimum-operations-to-make-a-uni-value-grid | Python3 easy solution using sorting | ermolushka2 | 0 | 58 | minimum operations to make a uni value grid | 2,033 | 0.524 | Medium | 28,304 |
https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/discuss/1513614/For-Beginners-oror-Median-oror-Easy-and-Greedy-Approach | class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
nums = []
for r in grid:
for v in r:
nums.append(v)
mi = min(nums)
for n in nums:
if (n-mi)%x:
return -1
nums.sort()
median = nums[len(nums)//2]
res = 0
f... | minimum-operations-to-make-a-uni-value-grid | 📌📌 For Beginners || Median || Easy & Greedy Approach 🐍 | abhi9Rai | 0 | 75 | minimum operations to make a uni value grid | 2,033 | 0.524 | Medium | 28,305 |
https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/discuss/1513337/Python-Solution-Minimum-operations-to-Make-uni-valued-Grid | class Solution:
def minOperations(self, grid: List[List[int]], x: int) -> int:
m,n = len(grid),len(grid[0])
count = 0
li = []
for i in range(m):
for j in range(n):
li.append(grid[i][j])
li.sort()
med = li[len(li)//... | minimum-operations-to-make-a-uni-value-grid | [Python] Solution - Minimum operations to Make uni-valued Grid | SaSha59 | 0 | 69 | minimum operations to make a uni value grid | 2,033 | 0.524 | Medium | 28,306 |
https://leetcode.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference/discuss/1513435/Python-or-Easy-Explanation-or-Meet-in-the-Middle | class Solution:
def minimumDifference(self, nums: List[int]) -> int:
N = len(nums) // 2 # Note this is N/2, ie no. of elements required in each.
def get_sums(nums): # generate all combinations sum of k elements
ans = {}
N = len(nums)
for k in range(1, N+1... | partition-array-into-two-arrays-to-minimize-sum-difference | Python | Easy Explanation | Meet in the Middle | malraharsh | 117 | 8,800 | partition array into two arrays to minimize sum difference | 2,035 | 0.183 | Hard | 28,307 |
https://leetcode.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference/discuss/1514580/Python-3-Hint-solution-binary-search | class Solution:
def minimumDifference(self, nums: List[int]) -> int:
n = len(nums)
tot = sum(nums)
l, r = nums[:n//2], nums[n//2:]
lsum, rsum = defaultdict(set), defaultdict(set)
for k in range(n // 2 + 1):
lsum[k] |= set(map(sum, combinations(l, k)))
... | partition-array-into-two-arrays-to-minimize-sum-difference | [Python 3] Hint solution binary search | chestnut890123 | 3 | 825 | partition array into two arrays to minimize sum difference | 2,035 | 0.183 | Hard | 28,308 |
https://leetcode.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference/discuss/2346227/Runtime%3A-1740-ms-or-Memory-Usage%3A-17.2-MB | class Solution:
def minimumDifference(self, nums: List[int]) -> int:
n = len(nums) // 2;
sum1, sum2 = sum(nums[:n]), sum(nums[n:]);
psum1, psum2 = [{0}], [{0}];
for ns, ps in zip([nums[:n], nums[n:]], [psum1, psum2]):
for i, x in enumerate(ns):
if... | partition-array-into-two-arrays-to-minimize-sum-difference | Runtime: 1740 ms | Memory Usage: 17.2 MB | vimla_kushwaha | 1 | 145 | partition array into two arrays to minimize sum difference | 2,035 | 0.183 | Hard | 28,309 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1539518/O(n)-counting-sort-in-Python | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum(abs(seat - student) for seat, student in zip(seats, students)) | minimum-number-of-moves-to-seat-everyone | O(n) counting sort in Python | mousun224 | 7 | 841 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,310 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1539518/O(n)-counting-sort-in-Python | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats_cnt, students_cnt = [0] * (max(seats) + 1), [0] * (max(students) + 1)
for seat in seats:
seats_cnt[seat] += 1
for student in students:
students_cnt[student] += 1
ans ... | minimum-number-of-moves-to-seat-everyone | O(n) counting sort in Python | mousun224 | 7 | 841 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,311 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1987191/Python-Easiest-Solution-With-Explanation-or-Sorting-or-Beg-to-adv | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
total_moves = 0 # taking a int variable to store the value
sorted_seats = sorted(seats) # sorting the seat list
sorted_students = sorted(students) #sorting the student list
diff_1 = [] # ... | minimum-number-of-moves-to-seat-everyone | Python Easiest Solution With Explanation | Sorting | Beg to adv | rlakshay14 | 3 | 235 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,312 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1524161/Python3-1-line | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
return sum(abs(x-y) for x, y in zip(sorted(seats), sorted(students))) | minimum-number-of-moves-to-seat-everyone | [Python3] 1-line | ye15 | 3 | 190 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,313 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2822070/Python-oror-99.81-Faster-oror-5-Lines-oror-Sorting | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
c,n=0,len(seats)
for i in range(n): c+=abs(seats[i]-students[i])
return c | minimum-number-of-moves-to-seat-everyone | Python || 99.81% Faster || 5 Lines || Sorting | DareDevil_007 | 2 | 50 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,314 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1827464/Simple-Python-solution-or-Easy-to-understand-or-90-Faster | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
c = 0
for i, j in zip(seats, students):
c += abs(j-i)
return c | minimum-number-of-moves-to-seat-everyone | ✔Simple Python solution | Easy to understand | 90% Faster | Coding_Tan3 | 1 | 106 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,315 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1589575/Python-3-Brute-Force-Solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats = sorted(seats)
students = sorted(students)
ans = 0
for i in range(len(seats)):
ans += abs(seats[i] - students[i])
return ans | minimum-number-of-moves-to-seat-everyone | [Python 3] Brute Force Solution | terrencetang | 1 | 117 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,316 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1525887/Python3-Easy-solution-sorting | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
moves = 0
for seat, student in zip(sorted(seats), sorted(students)):
moves += abs(seat - student)
return moves | minimum-number-of-moves-to-seat-everyone | Python3 Easy solution, sorting | frolovdmn | 1 | 87 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,317 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2846625/Python-or-Simple-or-Easy | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
total_moves = 0
for i in range(len(seats)):
total_moves += abs(students[i] - seats[i])
return total_moves | minimum-number-of-moves-to-seat-everyone | Python | Simple | Easy | pawangupta | 0 | 1 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,318 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2843436/PYTHON-Clean-or-With-Comments | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats = sorted(seats)
students = sorted(students)
# redefine the varaibles to be sorted [min->max]
counter = 0
# set up the counter for amount of moves
for x in range(len(seats))... | minimum-number-of-moves-to-seat-everyone | [PYTHON] Clean | With Comments | omkarxpatel | 0 | 1 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,319 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2840269/Python-1-line%3A-Optimal-and-Clean-with-explanation-2-ways%3A-O(nlogn)-time-and-O(1)-space | class Solution:
# hint: if you sort both arrays, does greedy work? try to reason about a counterexample.
# O(nlogn) time : O(1) space
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum(abs(seat - student) for seat, studen... | minimum-number-of-moves-to-seat-everyone | Python 1 line: Optimal and Clean with explanation - 2 ways: O(nlogn) time and O(1) space | topswe | 0 | 3 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,320 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2836103/Python-or-Simple-Understandable-Solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
p=sorted(seats)
s=sorted(students)
ps=[]
for i in range(len(students)):
if p[i]-s[i]<0:
ps.append(s[i]-p[i])
else:
ps.append(p[i]-s[i])
... | minimum-number-of-moves-to-seat-everyone | Python | Simple Understandable Solution | priyanshupriyam123vv | 0 | 1 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,321 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2833776/3Line-code | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats = sorted(seats)
students = sorted(students)
return sum([abs(seats[i] - students[i]) for i in range(len(students))]) | minimum-number-of-moves-to-seat-everyone | 3Line code | zsigmondy | 0 | 2 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,322 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2833441/PYTHON3-BEST | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum(abs(i - j) for i, j in zip(seats, students)) | minimum-number-of-moves-to-seat-everyone | PYTHON3 BEST | Gurugubelli_Anil | 0 | 1 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,323 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2818126/Python-simple-sorting-solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
res = 0
for i in range(len(seats)):
res += abs(students[i]-seats[i])
return res | minimum-number-of-moves-to-seat-everyone | Python simple sorting solution | ankurkumarpankaj | 0 | 1 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,324 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2811510/Simple-program-which-beats-100-in-terms-of-speed | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
s=0
for i in range(len(seats)):
n=seats[i]-students[i]
if n<0:
n=-1*n
s+=n
return s | minimum-number-of-moves-to-seat-everyone | Simple program which beats 100% in terms of speed | gowdavidwan2003 | 0 | 1 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,325 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2760983/python-solution-94.75-faster. | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
min_number_of_moves = 0
for student, seat in zip(students, seats):
diff = abs(student - seat)
min_number_of_moves += diff
retu... | minimum-number-of-moves-to-seat-everyone | python solution 94.75% faster. | samanehghafouri | 0 | 4 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,326 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2727054/Python3-Simple-Solution%3A-abs-differences-of-items | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum([abs(seats[i] - students[i]) for i in range(0,len(seats))]) | minimum-number-of-moves-to-seat-everyone | Python3 Simple Solution: abs differences of items | sipi09 | 0 | 3 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,327 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2677689/Python-Sort-One-line-solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
return sum([abs(i - j) for i,j in zip(sorted(seats), sorted(students))]) | minimum-number-of-moves-to-seat-everyone | Python Sort One line solution | zzjoshua | 0 | 15 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,328 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2622337/Simple-and-fast-python3-solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
res = 0
seats.sort()
students.sort()
for i in range(len(students)):
res += abs(students[i] - seats[i])
return res | minimum-number-of-moves-to-seat-everyone | Simple and fast python3 solution | Gilbert770 | 0 | 16 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,329 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2601747/Easiest-way-to-find-minimum-numbers-of-moves-or-Python-or-Faster | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
count=0
seats.sort()
students.sort()
for i in range(len(seats)):
count+=abs(seats[i]-students[i])
return count | minimum-number-of-moves-to-seat-everyone | Easiest way to find minimum numbers of moves | Python | Faster | msherazedu | 0 | 45 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,330 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2387705/Python3-Solution-with-using-sorting | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
res = 0
for i in range(len(seats)):
res += abs(seats[i] - students[i])
return res | minimum-number-of-moves-to-seat-everyone | [Python3] Solution with using sorting | maosipov11 | 0 | 21 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,331 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2296635/Python-oror-Easy-oror-6-Liner-oror-70-Faster | '''class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
moves=0
for i in range(len(seats)):
n=abs(seats[i]-students[i])
moves=moves+n
return moves''' | minimum-number-of-moves-to-seat-everyone | Python || Easy || 6 Liner || 70% Faster | keertika27 | 0 | 36 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,332 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2160510/Simple-Logic | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum(abs(e-t) for e, t in zip(seats, students)) | minimum-number-of-moves-to-seat-everyone | Simple Logic | writemeom | 0 | 61 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,333 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2040399/Python-(Simple-Approach-and-Beginner-Friendly) | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
op = 0;
seats.sort()
students.sort()
for i in range(0,len(seats)):
op += abs(students[i] - seats[i])
return op | minimum-number-of-moves-to-seat-everyone | Python (Simple Approach and Beginner-Friendly) | vishvavariya | 0 | 106 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,334 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/2019069/Python-or-simple-or-easy-solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
count = 0
for i, j in zip(sorted(seats), sorted(students)):
count+=abs(i-j)
return count | minimum-number-of-moves-to-seat-everyone | Python | simple | easy solution | manikanthgoud123 | 0 | 26 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,335 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1991622/Python-Solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
return sum(map(lambda x: abs(x[0] - x[1]), zip(sorted(seats), sorted(students)))) | minimum-number-of-moves-to-seat-everyone | Python Solution | hgalytoby | 0 | 59 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,336 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1991622/Python-Solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
return reduce(lambda x, y: x + abs(y[0] - y[1]), zip(sorted(seats), sorted(students)), 0) | minimum-number-of-moves-to-seat-everyone | Python Solution | hgalytoby | 0 | 59 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,337 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1865789/Python-solution-faster-than-99-memory-less-than-77 | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
count_moves = 0
for i in range(len(seats)):
count_moves += abs(students[i] - seats[i])
return count_moves | minimum-number-of-moves-to-seat-everyone | Python solution faster than 99%, memory less than 77% | alishak1999 | 0 | 100 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,338 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1857672/3-Lines-Python-Solution-oror-80-Faster-oror-Memory-less-than-85 | class Solution:
def minMovesToSeat(self, SE: List[int], ST: List[int]) -> int:
ST.sort() ; SE.sort() ; ans=0
for i in range(len(SE)): ans+=abs(ST[i]-SE[i])
return ans | minimum-number-of-moves-to-seat-everyone | 3-Lines Python Solution || 80% Faster || Memory less than 85% | Taha-C | 0 | 44 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,339 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1834119/Simple-Python-Solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
moves = 0
for i, j in zip(seats, students):
moves += abs(i-j)
return moves
``` | minimum-number-of-moves-to-seat-everyone | Simple Python Solution | himanshu11sgh | 0 | 30 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,340 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1762586/WEEB-DOES-PYTHONC%2B%2B | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
result = 0
for student, seat in zip(students, seats):
result += abs(student - seat)
return result | minimum-number-of-moves-to-seat-everyone | WEEB DOES PYTHON/C++ | Skywalker5423 | 0 | 50 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,341 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1723912/Easiest-Python3-solution-with-99-better-memory-usage | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
out=0
for i in range(0,len(seats)):
if seats[i]>=students[i]:
out=out+seats[i]-students[i]
elif students[i]>seats[i]:
... | minimum-number-of-moves-to-seat-everyone | Easiest Python3 solution with 99% better memory usage | rajatkumarrrr | 0 | 35 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,342 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1620416/Python-3-sorting-solution-faster-than-96 | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum(abs(seat - student) for seat, student in zip(seats, students)) | minimum-number-of-moves-to-seat-everyone | Python 3 sorting solution, faster than 96% | dereky4 | 0 | 205 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,343 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1611651/Python-Easy-to-understand | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
final=0
seats.sort()
students.sort()
for i in range(len(seats)):
final+=abs(seats[i] - students[i])
return final | minimum-number-of-moves-to-seat-everyone | Python, Easy to understand | japnitS | 0 | 128 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,344 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1573718/python-solution-or-faster-than-96 | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
ans = [abs(seats[i]-students[i]) for i in range(len(seats))]
return sum(ans) | minimum-number-of-moves-to-seat-everyone | python solution | faster than 96% | anandanshul001 | 0 | 103 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,345 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1544679/Straightforward-Python-solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort(reverse=True), students.sort()
moves = 0
for student in students:
moves += abs(student - seats[-1])
seats.pop()
return moves | minimum-number-of-moves-to-seat-everyone | Straightforward Python solution | akshaykumar19002 | 0 | 87 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,346 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1524399/Python-Sorting-O(nlogn) | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum(abs(seats[i]-students[i]) for i in range(len(seats))) | minimum-number-of-moves-to-seat-everyone | Python-Sorting-O(nlogn) | zoro_55 | 0 | 59 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,347 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1524374/Python-one-liner | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
return sum(abs(i-j) for i, j in zip(sorted(seats), sorted(students))) | minimum-number-of-moves-to-seat-everyone | Python, one-liner | blue_sky5 | 0 | 63 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,348 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1524267/Python-sorting-solution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats.sort()
students.sort()
return sum(abs(seats[i]-students[i]) for i in range(len(seats))) | minimum-number-of-moves-to-seat-everyone | Python sorting solution | abkc1221 | 0 | 72 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,349 |
https://leetcode.com/problems/minimum-number-of-moves-to-seat-everyone/discuss/1883258/Python-dollarolution | class Solution:
def minMovesToSeat(self, seats: List[int], students: List[int]) -> int:
seats = sorted(seats)
students = sorted(students)
count = 0
for i in range(len(seats)):
count += abs(seats[i] - students[i])
return count | minimum-number-of-moves-to-seat-everyone | Python $olution | AakRay | -1 | 44 | minimum number of moves to seat everyone | 2,037 | 0.821 | Easy | 28,350 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/1524153/C%2B%2BPythonJava-Count-%22AAA%22-and-%22BBB%22 | class Solution:
def winnerOfGame(self, s: str) -> bool:
a = b = 0
for i in range(1,len(s)-1):
if s[i-1] == s[i] == s[i+1]:
if s[i] == 'A':
a += 1
else:
b += 1
return a>b | remove-colored-pieces-if-both-neighbors-are-the-same-color | [C++/Python/Java] Count "AAA" and "BBB" | lokeshsenthilkumar | 75 | 5,000 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,351 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/2112058/PYTHON-oror-EXPLANATION-FOR-ALL-oror | class Solution:
def winnerOfGame(self, s: str) -> bool:
a=[]
p="C"
for i in s:
if i==p:
a[-1]+=1
else:
p=i
a.append(1)
odd,even=0,0
for i in range(len(a)):
if i%2:
odd += max(0... | remove-colored-pieces-if-both-neighbors-are-the-same-color | PYTHON || ✔️ EXPLANATION FOR ALL ✔️|| | karan_8082 | 9 | 589 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,352 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/1524171/Python3-greedy-5-line | class Solution:
def winnerOfGame(self, colors: str) -> bool:
diff = 0
for k, grp in groupby(colors):
if k == "A": diff += max(0, len(list(grp)) - 2)
else: diff -= max(0, len(list(grp)) - 2)
return diff > 0 | remove-colored-pieces-if-both-neighbors-are-the-same-color | [Python3] greedy 5-line | ye15 | 1 | 108 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,353 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/2577253/Python3-or-greedy-with-split-or-O(n) | class Solution:
def winnerOfGame(self, colors: str) -> bool:
a_segs = colors.split("B")
b_segs = colors.split("A")
a_removal = 0
for seg in a_segs:
if len(seg) > 2:
a_removal += len(seg) - 2
b_removal = 0
for seg in b_segs:
... | remove-colored-pieces-if-both-neighbors-are-the-same-color | Python3 | greedy with split | O(n) | colors92window | 0 | 65 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,354 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/2397422/Python-oror-O(n)-oror-Easy | class Solution:
def winnerOfGame(self, colors: str) -> bool:
acount=0
bcount=0
for i in range(len(colors)):
c=colors[i]
if(c=='A' and i-1>=0 and i+1<len(colors) and colors[i-1]=='A' and colors[i+1]=='A'):
acount+=1
if(c=='... | remove-colored-pieces-if-both-neighbors-are-the-same-color | Python || O(n) || Easy | ausdauerer | 0 | 71 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,355 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/2362262/Python-straightforward-solution | class Solution:
def winnerOfGame(self, colors: str) -> bool:
a_moves = b_moves = 0
for i in range(2, len(colors)):
if colors[i-2] == colors[i-1] == colors[i]:
if colors[i] == 'A':
a_moves += 1
else:
b_moves += 1
... | remove-colored-pieces-if-both-neighbors-are-the-same-color | Python, straightforward solution | blue_sky5 | 0 | 51 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,356 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/2111439/counting-consectives | class Solution:
def winnerOfGame(self, colors: str) -> bool:
if len(colors) < 3:
return False
bobsTurn = []
alicesTrun = []
currLetter = colors[0]
count = 0
for i in range(len(colors)):
if colors[i] == currLetter:
count +=1
... | remove-colored-pieces-if-both-neighbors-are-the-same-color | counting consectives | zoudarren7 | 0 | 19 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,357 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/1659491/Intuition-Explained | class Solution:
def winnerOfGame(self, colors: str) -> bool:
aliceMoves = 0
bobMoves = 0
consecutiveA = 0
consecutiveB = 0
for color in colors:
if color == "A":
consecutiveA += 1
consecutiveB = 0
else:
... | remove-colored-pieces-if-both-neighbors-are-the-same-color | Intuition Explained | jdot593 | 0 | 69 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,358 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/1527980/Using-groupby-71-speed | class Solution:
def winnerOfGame(self, colors: str) -> bool:
count_a = count_b = 0
for key, g in groupby(colors):
len_g = len(list(g))
if key == "A":
if len_g > 2:
count_a += len_g - 2
else:
if len_g > 2:
... | remove-colored-pieces-if-both-neighbors-are-the-same-color | Using groupby, 71% speed | EvgenySH | 0 | 89 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,359 |
https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/discuss/1524245/Python-2-pointers | class Solution:
def winnerOfGame(self, arr: str) -> bool:
n = len(arr)
def count(char):
i, j = 0, 0
res = 0
while j < n:
temp = 0
while j < n and arr[j] == char:
temp += 1
j += 1
... | remove-colored-pieces-if-both-neighbors-are-the-same-color | Python 2 pointers | abkc1221 | 0 | 73 | remove colored pieces if both neighbors are the same color | 2,038 | 0.582 | Medium | 28,360 |
https://leetcode.com/problems/the-time-when-the-network-becomes-idle/discuss/1524183/Python3-graph | class Solution:
def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int:
graph = {}
for u, v in edges:
graph.setdefault(u, []).append(v)
graph.setdefault(v, []).append(u)
dist = [-1]*len(graph)
dist[0] = 0
val = 0
... | the-time-when-the-network-becomes-idle | [Python3] graph | ye15 | 5 | 176 | the time when the network becomes idle | 2,039 | 0.508 | Medium | 28,361 |
https://leetcode.com/problems/the-time-when-the-network-becomes-idle/discuss/2526479/Python-bfs-oror-fast-and-very-easy-to-understand | class Solution:
def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int:
graph = defaultdict(set)
for a, b in edges:
graph[a].add(b)
graph[b].add(a)
dis = {}
queue = deque([(0, 0)])
visited = set([0])
while... | the-time-when-the-network-becomes-idle | Python bfs || fast and very easy to understand | Yared_betsega | 1 | 34 | the time when the network becomes idle | 2,039 | 0.508 | Medium | 28,362 |
https://leetcode.com/problems/the-time-when-the-network-becomes-idle/discuss/1524256/For-Beginners-oror-Greedy-Approach-oror-Well-Explained | class Solution:
def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int:
graph = defaultdict(list)
for e1,e2 in edges:
graph[e1].append(e2)
graph[e2].append(e1)
dist = [-1]*len(graph)
dist[0] = 0
queue = [0]
d = 0
while queue:
d+=2
... | the-time-when-the-network-becomes-idle | 📌📌 For-Beginners || Greedy-Approach || Well-Explained 🐍 | abhi9Rai | 1 | 70 | the time when the network becomes idle | 2,039 | 0.508 | Medium | 28,363 |
https://leetcode.com/problems/the-time-when-the-network-becomes-idle/discuss/2847951/Easiest-code-with-best-explanation-for-the-formula | class Solution:
def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int:
#part-1 of code
#Djikstra for getting the shortest time
graph = defaultdict(list)
for u,v in edges:
graph[u].append(v)
graph[v].append(u)
time_tracker = ... | the-time-when-the-network-becomes-idle | Easiest code with best explanation for the formula | shriyansnaik | 0 | 1 | the time when the network becomes idle | 2,039 | 0.508 | Medium | 28,364 |
https://leetcode.com/problems/the-time-when-the-network-becomes-idle/discuss/2272867/Python-3-BFS | class Solution:
def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int:
n=len(patience)
G=[[] for _ in range(n)]
for x,y in edges:
G[x].append(y)
G[y].append(x)
vis,q=[False]*n,[0]
vis[0]=True
res,d=0,1
while q:
new_q=[]
for node in q:
for child in G[node]:... | the-time-when-the-network-becomes-idle | [Python 3] BFS | gabhay | 0 | 17 | the time when the network becomes idle | 2,039 | 0.508 | Medium | 28,365 |
https://leetcode.com/problems/the-time-when-the-network-becomes-idle/discuss/1670121/Python-Simple-BFS-Implementation. | class Solution:
def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int:
# create adjacency list
adj_list = defaultdict(list)
for i,j in edges:
adj_list[i].append(j)
adj_list[j].append(i)
# min_time is the time taken for a mes... | the-time-when-the-network-becomes-idle | Python - Simple BFS Implementation. | kaustav43 | 0 | 64 | the time when the network becomes idle | 2,039 | 0.508 | Medium | 28,366 |
https://leetcode.com/problems/the-time-when-the-network-becomes-idle/discuss/1531159/Python-3-or-Clean-BFS-Deque-or-Explanation | class Solution:
def networkBecomesIdle(self, edges: List[List[int]], patience: List[int]) -> int:
graph = collections.defaultdict(list)
for a, b in edges: # build graph
graph[a].append(b)
graph[b].append(a)
dq = collections.deque(... | the-time-when-the-network-becomes-idle | Python 3 | Clean BFS, Deque | Explanation | idontknoooo | 0 | 87 | the time when the network becomes idle | 2,039 | 0.508 | Medium | 28,367 |
https://leetcode.com/problems/kth-smallest-product-of-two-sorted-arrays/discuss/1524190/Python3-binary-search | class Solution:
def kthSmallestProduct(self, nums1: List[int], nums2: List[int], k: int) -> int:
def fn(val):
"""Return count of products <= val."""
ans = 0
for x in nums1:
if x < 0: ans += len(nums2) - bisect_left(nums2, ceil(val/x))
... | kth-smallest-product-of-two-sorted-arrays | [Python3] binary search | ye15 | 8 | 1,300 | kth smallest product of two sorted arrays | 2,040 | 0.291 | Hard | 28,368 |
https://leetcode.com/problems/kth-smallest-product-of-two-sorted-arrays/discuss/1524190/Python3-binary-search | class Solution:
def kthSmallestProduct(self, nums1: List[int], nums2: List[int], k: int) -> int:
neg = [x for x in nums1 if x < 0]
pos = [x for x in nums1 if x >= 0]
def fn(val):
"""Return count of products <= val."""
ans = 0
lo, hi = 0, len(nums2... | kth-smallest-product-of-two-sorted-arrays | [Python3] binary search | ye15 | 8 | 1,300 | kth smallest product of two sorted arrays | 2,040 | 0.291 | Hard | 28,369 |
https://leetcode.com/problems/kth-smallest-product-of-two-sorted-arrays/discuss/2163920/Python-3-AC-Solution-with-detailed-math-derivation | class Solution:
def kthSmallestProduct(self, nums1: List[int], nums2: List[int], k: int) -> int:
"""
Binary Search
find first number that makes countSmallerOrEqual(number) >= k
return number
"""
boundary = [nums1[0]*nums2[0], nums1[0] * nums2[-1], nums1[-1] * nums2[0]... | kth-smallest-product-of-two-sorted-arrays | Python 3 AC Solution with detailed math derivation | Cara22 | 2 | 189 | kth smallest product of two sorted arrays | 2,040 | 0.291 | Hard | 28,370 |
https://leetcode.com/problems/kth-smallest-product-of-two-sorted-arrays/discuss/1596349/Python3-Brute-Force-in-TLE-passing-82112-test-cases | class Solution:
def kthSmallestProduct(self, nums1: List[int], nums2: List[int], k: int) -> int:
result = []
for i in range(len(nums1)):
for j in range(len(nums2)):
temp = nums1[i]*nums2[j]
result.append(temp)
result.sort()
return result[k-... | kth-smallest-product-of-two-sorted-arrays | [Python3] Brute Force in TLE passing 82/112 test cases | yugo9081 | 0 | 361 | kth smallest product of two sorted arrays | 2,040 | 0.291 | Hard | 28,371 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1525219/Python3-2-line | class Solution:
def areNumbersAscending(self, s: str) -> bool:
nums = [int(w) for w in s.split() if w.isdigit()]
return all(nums[i-1] < nums[i] for i in range(1, len(nums))) | check-if-numbers-are-ascending-in-a-sentence | [Python3] 2-line | ye15 | 24 | 1,400 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,372 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1525691/Python-3-Simple-regex-solution-or-2-lines! | class Solution:
def areNumbersAscending(self, s):
nums = re.findall(r'\d+', s)
return nums == sorted(set(nums), key=int) | check-if-numbers-are-ascending-in-a-sentence | [Python 3] Simple regex solution | 2 lines! | JK0604 | 3 | 147 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,373 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1526154/Python-optimal-one-pass-solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
prev = 0
for token in s.split():
if token.isnumeric():
if (curr := int(token)) <= prev:
return False
prev = curr
return True | check-if-numbers-are-ascending-in-a-sentence | Python, optimal one pass solution | blue_sky5 | 2 | 97 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,374 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1525901/Python3-Easy-solution-re | class Solution:
def areNumbersAscending(self, s: str) -> bool:
nums = re.findall('\d+', s)
nums = [int(num) for num in nums]
if nums == sorted(nums) and len(nums) == len(set(nums)):
return True
else:
return False | check-if-numbers-are-ascending-in-a-sentence | Python3 Easy solution, re | frolovdmn | 2 | 52 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,375 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2670447/Python-or-O(n) | class Solution:
def areNumbersAscending(self, s: str) -> bool:
st = ''
res= []
for i in range(len(s)):
if s[i].isnumeric():
st += s[i]
else:
if len(st)>0:
res.append(int(st))
st =''
if len(st)... | check-if-numbers-are-ascending-in-a-sentence | Python | O(n) | naveenraiit | 1 | 123 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,376 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1697770/Python3-accepted-solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
num = [int(i) for i in s.split() if(i.isnumeric())]
return True if(num == sorted(num) and len(num)==len(set(num))) else False | check-if-numbers-are-ascending-in-a-sentence | Python3 accepted solution | sreeleetcode19 | 1 | 55 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,377 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1662416/Python3-3-line | class Solution:
def areNumbersAscending(self, s: str) -> bool:
lst = [int(x) for x in s.split() if x.isdigit()]
a = sorted(set(lst))
return lst == a | check-if-numbers-are-ascending-in-a-sentence | [Python3] 3-line | Cheems_Coder | 1 | 68 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,378 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1589768/Using-regex-97-speed | class Solution:
def areNumbersAscending(self, s: str) -> bool:
nums = list(map(int, re.findall(r"\b\d+\b", s)))
return len(nums) < 2 or all(n2 > n1 for n1, n2 in zip(nums, nums[1:])) | check-if-numbers-are-ascending-in-a-sentence | Using regex, 97% speed | EvgenySH | 1 | 60 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,379 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2837421/Python3-Sample | class Solution:
def areNumbersAscending(self, s: str) -> bool:
number, curr = "", -1
for i in range(len(s)):
if s[i] in ("0","1","2","3","4","5","6","7","8","9"):
number += s[i]
elif len(number) > 0:
if curr >= int(number):
... | check-if-numbers-are-ascending-in-a-sentence | Python3 Sample | DNST | 0 | 2 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,380 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2834109/Simple-intuitive-python-solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
arr = []
i = 0
while i < len(s):
if s[i].isdigit():
j = i + 1
while j < len(s) and s[j].isdigit():
j += 1
arr.append(int(s[i:j]))
i =... | check-if-numbers-are-ascending-in-a-sentence | Simple intuitive python solution | aruj900 | 0 | 3 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,381 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2813520/Solution-with-O(1)-space | class Solution:
def areNumbersAscending(self, s: str) -> bool:
def getTokens(s):
i = 0
currentToken = []
while i < len(s):
if s[i] != ' ':
currentToken.append(s[i])
else:
yield ''.join(currentToken)
... | check-if-numbers-are-ascending-in-a-sentence | Solution with O(1) space | Mik-100 | 0 | 2 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,382 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2781864/Python-Solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
previous_number = -1
for char in s.split(" "):
if char.isdigit():
current_number = int(char)
if current_number <= previous_number:
return False
previous_n... | check-if-numbers-are-ascending-in-a-sentence | Python Solution | namashin | 0 | 3 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,383 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2752405/Python-Solution-oror-Beats-92 | class Solution:
def areNumbersAscending(self, s: str) -> bool:
res=[int(i) for i in s.split() if i.isdigit()]
if(len(set(res))!=len(res)):
return False
else:
return sorted(res)==res | check-if-numbers-are-ascending-in-a-sentence | Python Solution || Beats 92% | shivammenda2002 | 0 | 3 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,384 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2726575/Python3-simple-approach | class Solution:
def areNumbersAscending(self, s: str) -> bool:
l = []
for i in s.split():
if i.isdigit():
l.append(int(i))
for i in range(1,len(l)):
if l[i-1] > l[i] or l[i-1] == l[i]:
return False
return True | check-if-numbers-are-ascending-in-a-sentence | Python3 simple approach | chakalivinith | 0 | 3 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,385 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2662218/Python-Solution-without-Regex-or-Split-or-O(n)-time-O(1)-space | class Solution:
def areNumbersAscending(self, s: str) -> bool:
prevNum = currNum = -1
for char in s:
if char.isdigit():
if currNum == -1:
currNum = int(char)
else:
currNum = (currNum * 10) + int(char)
... | check-if-numbers-are-ascending-in-a-sentence | Python Solution without Regex or Split | O(n) time, O(1) space | kcstar | 0 | 2 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,386 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2657272/Python-3-liner-easy-peasy-solution-with-explanation | class Solution:
def areNumbersAscending(self, s: str) -> bool:
#Get rid of any spaces and put them in a list
str_list = s.split()
# Filter out the numeric and non numeric characters in a list
new_list = [int(i) for i in str_list if i.isnumeric()]
# By default return false. Return true only if... | check-if-numbers-are-ascending-in-a-sentence | Python 3 liner easy peasy solution with explanation | code_snow | 0 | 9 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,387 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2569535/Solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
arr = []
c1 = 0
c2 = 0
s = s.split()
for i in range(len(s)):
if s[i].isalpha():
continue
else:
c2 = int(s[i])
if c1 >= c2: return False
... | check-if-numbers-are-ascending-in-a-sentence | Solution | fiqbal997 | 0 | 7 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,388 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2384976/Easy-python3-fast-solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
prev=-1
i=0
l=len(s)
num=""
while i < l:
if s[i].isdigit():
num+=s[i]
if (i!=l-1) and (s[i+1].isdigit()):
pass
else:
... | check-if-numbers-are-ascending-in-a-sentence | Easy [python3] fast solution | sunakshi132 | 0 | 20 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,389 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2302978/Simple-Python3-Solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
nums = []
s_list = s.split()
for word in s_list:
if word.isdigit():
nums.append(word)
for i in range(1, len(nums)):
if int(nums[i-1]) >= int(nums[i]):
... | check-if-numbers-are-ascending-in-a-sentence | Simple Python3 Solution | vem5688 | 0 | 31 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,390 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2260014/faster-than-40-or-python3 | '''class Solution:
def areNumbersAscending(self, s: str) -> bool:
lst=[]
c=[]
ans=False
l=list(s.split(' '))
for i in l:
if i.isdigit():
lst.append(int(i))
c.append(int(i))
if len(set(lst))==len(lst): #check for strictly increasing order
lst.sort()
if lst==c:
ans=True
return ans
p... | check-if-numbers-are-ascending-in-a-sentence | faster than 40% | python3 | keertika27 | 0 | 18 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,391 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/2090512/Simple-Python-Solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
words = s.split()
numbers = []
for i in words:
if i.isdigit():
numbers.append(int(i))
for i in range(len(numbers)-1):
if numbers[i] < numbers[i+1]:
... | check-if-numbers-are-ascending-in-a-sentence | Simple Python Solution | kn_vardhan | 0 | 38 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,392 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1956004/Python3-simple-solution | class Solution:
def areNumbersAscending(self, s: str) -> bool:
s = s.split()
c = -1
for i in s:
if c == -1 and i.isdigit():
c = int(i)
elif c != -1 and i.isdigit() and c >= int(i):
return False
elif c != -1 and i.isdigit() a... | check-if-numbers-are-ascending-in-a-sentence | Python3 simple solution | EklavyaJoshi | 0 | 26 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,393 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1913003/Python-easy-to-read-and-understand | class Solution:
def areNumbersAscending(self, s: str) -> bool:
words = s.split(" ")
prev = 0
for word in words:
if word.isnumeric():
if int(word) <= prev:
return False
prev = int(word)
return True | check-if-numbers-are-ascending-in-a-sentence | Python easy to read and understand | sanial2001 | 0 | 40 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,394 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1902096/Python-Clean-and-Concise! | class Solution:
def areNumbersAscending(self, s):
nums = list(map(int, filter(str.isdigit, s.split())))
return all(i < j for i,j in zip(nums, nums[1:])) | check-if-numbers-are-ascending-in-a-sentence | Python - Clean and Concise! | domthedeveloper | 0 | 28 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,395 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1902096/Python-Clean-and-Concise! | class Solution:
def areNumbersAscending(self, s):
nums = [int(i) for i in s.split() if i.isdigit()]
return all(i < j for i,j in zip(nums, nums[1:])) | check-if-numbers-are-ascending-in-a-sentence | Python - Clean and Concise! | domthedeveloper | 0 | 28 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,396 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1902096/Python-Clean-and-Concise! | class Solution:
def areNumbersAscending(self, s):
return (lambda nums : all(i < j for i,j in zip(nums, nums[1:])))([int(i) for i in s.split() if i.isdigit()]) | check-if-numbers-are-ascending-in-a-sentence | Python - Clean and Concise! | domthedeveloper | 0 | 28 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,397 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1883280/Python-dollarolution-(95-Faster) | class Solution:
def areNumbersAscending(self, s: str) -> bool:
s = s.split(' ')
x = -1
for i in s:
if i.isnumeric():
if int(i) > x:
x = int(i)
continue
else:
return False
return Tr... | check-if-numbers-are-ascending-in-a-sentence | Python $olution (95% Faster) | AakRay | 0 | 32 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,398 |
https://leetcode.com/problems/check-if-numbers-are-ascending-in-a-sentence/discuss/1815282/Python-Solution-with-2-ways | class Solution:
def areNumbersAscending(self, s: str) -> bool:
a = s.split()
res = []
for item in a:
if item.isdigit():
if int(item) in res:
return False
res.append(int(item))
temp = [str(x) for x in res]
res.sor... | check-if-numbers-are-ascending-in-a-sentence | Python Solution with 2 ways | iamamirhossein | 0 | 43 | check if numbers are ascending in a sentence | 2,042 | 0.661 | Easy | 28,399 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.