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/sign-of-the-product-of-an-array/discuss/2657341/Easy-Python-Solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
return 1 if math.prod(nums) > 0 else (-1 if math.prod(nums) < 0 else 0) | sign-of-the-product-of-an-array | 🐍Easy Python Solution ✔⭐ | kanvi26 | 0 | 1 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,000 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2604867/Python-One-liner-without-if-else-Statement | class Solution:
def arraySign(self, nums: List[int]) -> int:
return (sum(i < 0 for i in nums) % 2 * (-2) + 1) * (0 not in nums) | sign-of-the-product-of-an-array | [Python] One-liner without if-else Statement | andy2167565 | 0 | 24 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,001 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2449062/Python3-Brute-Force-Easy-Self-Explanatory-Solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
product = 1 # Initializing product variable (any number multiplied with 1 will be same number)
for i in nums:
product = product * i # Storing total product in the product variable
if product > 0... | sign-of-the-product-of-an-array | Python3 Brute-Force Easy Self Explanatory Solution | MusfiqDehan | 0 | 18 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,002 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2426897/Sign-of-the-Product-of-an-Array-or-Python-Step-by-Step-Solution-or | class Solution:
def arraySign(self, nums: List[int]) -> int:
for i in range(len(nums)): # iterating through loop and setting each element 0,1 or -1
if nums[i] >= 1:
nums[i] = 1
elif nums[i] < 0:
nums[i] = -1
else:
nums[i] =... | sign-of-the-product-of-an-array | Sign of the Product of an Array | Python Step by Step Solution | | mayankus | 0 | 10 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,003 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2416386/98-faster-than-other | class Solution:
def arraySign(self, nums: List[int]) -> int:
product = 1
for i in range(len(nums)):
product = product * nums[i]
if product > 0 :
return 1
elif product < 0 :
return -1
return 0 | sign-of-the-product-of-an-array | 98% faster than other | Akash2907 | 0 | 28 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,004 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2384838/EASY-oror-95-Faster-oror-python3 | class Solution:
def arraySign(self, nums: List[int]) -> int:
if 0 in nums: return 0
else:
c=0
for i in nums:
if i<0: c+=1
if c%2==0: return 1
else: return -1 | sign-of-the-product-of-an-array | EASY || 95% Faster || python3 | keertika27 | 0 | 27 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,005 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2238128/Python3.-negative-numbers-counter.-faster-than-99.77-and-memory-better-than-76 | class Solution:
def arraySign(self, nums: List[int]) -> int:
res = 0
for num in nums:
if num==0:
return 0
elif num<0:
res += 1
if res%2>0:
return -1
else:
return 1 | sign-of-the-product-of-an-array | Python3. negative numbers counter. faster than 99.77% and memory better than 76% | devmich | 0 | 37 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,006 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2177002/Python-Simple-Python-Solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
result = 1
for num in nums:
result = result * num
if result == 0:
return 0
elif result < 0:
return -1
else:
return 1 | sign-of-the-product-of-an-array | [ Python ] ✅✅ Simple Python Solution 🥳✌👍 | ASHOK_KUMAR_MEGHVANSHI | 0 | 76 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,007 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2159994/Python3-34ms-solution-99 | class Solution(object):
def arraySign(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
negs = 0
#for each value in nums, asses its sign
for value in nums:
#track number of negatives we hit
if value <0:
neg... | sign-of-the-product-of-an-array | Python3 34ms solution 99% | mm91 | 0 | 40 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,008 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2105198/Best-and-very-easy-python-solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
prod = 1
for i in nums:
prod = prod*i
if(prod<0):
return -1
elif(prod>0):
return 1
else:
return 0 | sign-of-the-product-of-an-array | Best and very easy python solution | yashkumarjha | 0 | 55 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,009 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2099246/PYTHON-or-Simple-python-solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
res = 1
for i in nums:
res *= i
if res < 0: return -1
elif res == 0: return 0
else: return 1 | sign-of-the-product-of-an-array | PYTHON | Simple python solution | shreeruparel | 0 | 53 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,010 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2073477/Easy-to-understand-python-solution-with-complexities | class Solution:
def arraySign(self, nums: List[int]) -> int:
ans = 1
for i in nums:
if i == 0:
ans = 0
break
elif i > 0:
ans = ans * 1
elif i < 0 :
ans = ans * (-1)
return ans
#... | sign-of-the-product-of-an-array | Easy to understand python solution with complexities | mananiac | 0 | 36 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,011 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2049345/Beats-80-Python-Simple-Solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
if 0 in nums:
return 0
return 1 if len([x for x in nums if x < 0]) % 2 == 0 else -1 | sign-of-the-product-of-an-array | Beats 80% - Python Simple Solution | 7yler | 0 | 47 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,012 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/2045117/Python-solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
from functools import reduce
from operator import mul
if reduce(mul, nums) > 0:
return 1
elif reduce(mul, nums) < 0:
return -1
else:
return 0 | sign-of-the-product-of-an-array | Python solution | StikS32 | 0 | 41 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,013 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/1889907/simple-Python-Solution-or-Clean-and-Easy-to-Understand | class Solution:
def arraySign(self, nums: List[int]) -> int:
total = nums[0]
for i in nums[1:]:
total *= i
return self.signFunc(total)
def signFunc(self, n: int) ->int:
if n > 0:
return 1
elif n < 0:
return -1
... | sign-of-the-product-of-an-array | simple Python Solution | Clean and Easy to Understand | parthpatel9414 | 0 | 66 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,014 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/1888159/Python-clean-and-simple!-Literal-approach | class Solution:
def arraySign(self, nums):
# There is a function signFunc(x) that returns 1 if x is positive, -1 if x is negative, 0 if x is equal to 0.
def signFunc(x): return 1 if x > 0 else -1 if x < 0 else 0
# Let product be the product of all values in the array nums.
p... | sign-of-the-product-of-an-array | Python - clean and simple! Literal approach | domthedeveloper | 0 | 53 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,015 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/1863692/Python-Solution | class Solution:
def arraySign(self, nums: List[int]) -> int:
ans = 1
for i in range(len(nums)):
if nums[i] == 0:
return 0
else:
if nums[i] < 0:
ans *= -1
else:
ans *= 1
return ans | sign-of-the-product-of-an-array | Python Solution | DietCoke777 | 0 | 44 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,016 |
https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/1859178/Python-dollarolution | class Solution:
def arraySign(self, nums: List[int]) -> int:
if 0 in nums:
return 0
count = 1
for i in nums:
if i < 0:
count *= -1
return count | sign-of-the-product-of-an-array | Python $olution | AakRay | 0 | 37 | sign of the product of an array | 1,822 | 0.66 | Easy | 26,017 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1152420/Python3-simulation | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
nums = list(range(n))
i = 0
while len(nums) > 1:
i = (i + k-1) % len(nums)
nums.pop(i)
return nums[0] + 1 | find-the-winner-of-the-circular-game | [Python3] simulation | ye15 | 16 | 1,900 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,018 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1152420/Python3-simulation | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
ans = 0
for x in range(2, n+1): ans = (ans + k) % x
return ans + 1 | find-the-winner-of-the-circular-game | [Python3] simulation | ye15 | 16 | 1,900 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,019 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1181024/Python3-simple-solution-beats-90-users | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
l = list(range(1,n+1))
i = 0
while len(l) > 1:
i = (i + k - 1)%len(l)
l.pop(i)
return l[0] | find-the-winner-of-the-circular-game | Python3 simple solution beats 90% users | EklavyaJoshi | 3 | 206 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,020 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2770302/Simple-Approach%3A-BF | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
l = list(range(n))
s = 0
while len(l) > 1:
i = (k%len(l) + s)%len(l)
l = l[: i] + l[i+1: ]
s = i-1
return l[0] or n | find-the-winner-of-the-circular-game | Simple Approach: BF | Mencibi | 1 | 106 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,021 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1993022/Python-oror-6-line-using-SET | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
friends = sorted(set(range(1, n + 1)))
idx = 0
while len(friends) > 1:
idx = (idx + k - 1) % len(friends)
friends.remove(friends[idx])
return friends[0] | find-the-winner-of-the-circular-game | Python || 6-line using SET | gulugulugulugulu | 1 | 106 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,022 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1726293/Python-Solution-Using-Recursion | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
def solve(n, k, s):
if len(n)==1:
return n[-1]
n.pop(s)
l = len(n)
s = (s+k-1)%l
return solve(n,k,s)
l = list(range(1, n+1))
x = (0+k-1)%n
ans = solve(l, k, x)
return ans | find-the-winner-of-the-circular-game | Python Solution Using Recursion | ayush_kushwaha | 1 | 107 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,023 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1280511/python3-simple-iterative-solution-88-faster | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
temp,curr=[x for x in range(1, n+1)], 0
while len(temp)>1:
curr=(curr+k-1)%len(temp)
temp.pop(curr)
if len(temp)==curr:
curr=0
return temp[0] | find-the-winner-of-the-circular-game | [python3] simple, iterative solution, 88% faster | alter_mage | 1 | 116 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,024 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1153739/Python3-Stimulation-Easy | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
arr = [i+1 for i in range(n)]
prev = k-1 # k-1 steps from 1
for i in range(n-1):
del arr[prev] # delete
#print(arr)
prev = (prev+k-1)%len(arr) # move k-1 more steps, mod because circular
... | find-the-winner-of-the-circular-game | Python3 Stimulation Easy | gautamsw51 | 1 | 97 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,025 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1152779/Josephus-problem-oror-No-RECURSION-oror-Python | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
a=[]
for i in range(1,n+1):
a.append(i)
i = 0
while len(a) != 1:
i = (i + k-1) % len(a)
a.remove(a[i])
return a[0] | find-the-winner-of-the-circular-game | Josephus problem || No RECURSION || Python | suvoo | 1 | 194 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,026 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2847011/Python-code-with-Intuition-or-O(n)-or-O(1) | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
return self.helper(n,k)+1
def helper(self, n:int, k:int)-> int:
if(n==1):
return 0
prevWinner = self.helper(n-1, k)
return (prevWinner + k) % n | find-the-winner-of-the-circular-game | Python code with Intuition | O(n) | O(1) | samart3010 | 0 | 5 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,027 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2781788/Faster-than-100 | class Solution:
def solve(self,n,k):
if n == 1:
return 0
return (self.solve(n-1,k)+k )%n
def findTheWinner(self, n: int, k: int) -> int:
return self.solve(n,k)+1 | find-the-winner-of-the-circular-game | Faster than 100% | sanskar_ | 0 | 17 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,028 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2757338/Python3-Solution-with-using-queue | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
q = collections.deque([i for i in range(1, n + 1)])
while len(q) > 1:
for i in range(k - 1):
val = q.popleft()
q.append(val)
q.popleft()
retu... | find-the-winner-of-the-circular-game | [Python3] Solution with using queue | maosipov11 | 0 | 7 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,029 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2714886/Python-O(n)-and-O(n*k)-Solutions | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
# O(n), O(1)
frd = 1
for i in range(2,n+1):
frd = (frd+k-1) % i+1
return frd
# Using queue O(n*k), O(n)
q = deque(range(1,n+1))
while len(q) > 1:
# append friends in cloc... | find-the-winner-of-the-circular-game | Python O(n) and O(n*k) Solutions | oluomo_lade | 0 | 14 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,030 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2705458/python-solution | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
ls = [i for i in range(1,n+1)]
s=0
while len(ls) != 1:
rem = (s + k-1) % len(ls)
ls.pop(rem)
s = rem
return ls[0] | find-the-winner-of-the-circular-game | python solution | anshsharma17 | 0 | 10 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,031 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2683297/Python-Solution-Find-the-Winner-of-the-Circular-Game-using-queue | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
q = [i+1 for i in range(n)]
while len(q)>1:
for i in range(k-1):
t = q.pop(0)
q.append(t)
q.pop(0)
return q.pop(0) | find-the-winner-of-the-circular-game | Python Solution Find the Winner of the Circular Game using queue | sarthakchawande14 | 0 | 4 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,032 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2667978/Python-oror-Easy-Solution-oror-Recursion | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
def get_indx(cur_indx, steps, lnth):
new_indx = cur_indx + steps - 1
if new_indx >= lnth:
new_indx = new_indx%lnth
return new_indx
def get_ans(arr, indx):
lnth = len(... | find-the-winner-of-the-circular-game | Python || Easy Solution || Recursion | Rahul_Kantwa | 0 | 7 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,033 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2631466/Pyhton-basic-approach | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
arr=list(range(1,n+1))
while len(arr) != 1:
d=(k-1)%len(arr)
arr.pop(d)
'''
[1, 2, 3, 4, 5]Pop - 2 at d= 1
[3, 4, 5, 1] Pop -4 at d=1
[5, 1, 3] Pop - 1 at d=1
... | find-the-winner-of-the-circular-game | Pyhton basic approach | beingab329 | 0 | 20 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,034 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2425593/Python3-or-Simple-Queue-Solution | class Solution:
#Time-Complexity: O(n + (n-1) * (k-1)) -> O(n + nk) -> O(n)
#Space-Complexity: O(n)
def findTheWinner(self, n: int, k: int) -> int:
#approach: Initialize a queue DS that stores the players labels from i = 1 to n!
#Reading elements from left to right would co... | find-the-winner-of-the-circular-game | Python3 | Simple Queue Solution | JOON1234 | 0 | 22 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,035 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2412167/Python-O(N) | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
if n == 1:
return 1
# start from the last round -> choose the winner in [1, 2] (2 player)
if k % 2 == 0:
start = 1
else:
start = 2
# current_index = (prev_round_index - k... | find-the-winner-of-the-circular-game | Python O(N) | TerryHung | 0 | 43 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,036 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/2229400/Python-4-lines-simulation.-Time%3A-O(N2).-Space%3A-O(N) | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
idx, nums = 0, list(range(1, n+1))
while len(nums) > 1:
del nums[idx := (idx + k - 1) % len(nums)]
return nums[0] | find-the-winner-of-the-circular-game | Python, 4 lines, simulation. Time: O(N^2). Space: O(N) | blue_sky5 | 0 | 21 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,037 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1988841/Python3-Solution-by-Simulation | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
friends = [i for i in range(1, n + 1)]
p = 0
while len(friends) > 1:
p = (p + k - 1) % len(friends)
friends.pop(p)
return friends[0] | find-the-winner-of-the-circular-game | [Python3] Solution by Simulation | terrencetang | 0 | 50 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,038 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1933431/Easy-understanding-Queue-in-Python | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
queue = deque(list(range(1, n+1)))
while len(queue) > 1:
for i in range(k):
tmp = queue.popleft()
if i != k-1:
queue.append(tmp)
return queue.popleft() | find-the-winner-of-the-circular-game | Easy understanding Queue in Python | echonesis | 0 | 51 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,039 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1645559/PYTHON-Simulation-Solution-Easy-to-understand | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
arr = [i for i in range(1, n+1)]
i = 0
count = 1
while len(arr) > 1:
if count == k:
arr.pop(i)
count = 1
else:
count += 1
i += 1
... | find-the-winner-of-the-circular-game | [PYTHON] Simulation Solution - Easy to understand | satyu | 0 | 138 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,040 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1397757/Python3-Solution | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
circular_list = [n for n in range(1, n + 1)]
i = 0
iteration = n - 1
while iteration > 0:
for x in range(1, k + 1):
if i > len(circular_list) - 1:
i = i - len(circular_list... | find-the-winner-of-the-circular-game | Python3 Solution | RobertObrochta | 0 | 93 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,041 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1166045/Python3-Simple-Solution-with-Explanation-and-Comments-Beats-96-in-Running-Time | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
'''
1. Make a list of players from 1 to n inclusive
2. Until n-1 players have been eliminated, starting from a specific index, find the index of the player to be eliminated in each round.
The index of the player to ... | find-the-winner-of-the-circular-game | Python3 Simple Solution with Explanation and Comments, Beats 96% in Running Time | bPapan | 0 | 107 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,042 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1152565/Python-Simple-Solution-or-O(n)-or-100-Faster | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
if k==1:
return n
lst = list(range(1, n+1))
p = n
ptr = -1
while p!=1:
x = ptr+k
ptr = x if x < p else x%p
lst.pop(ptr)
ptr -= 1
p -= 1
... | find-the-winner-of-the-circular-game | Python Simple Solution | O(n) | 100% Faster | VijayantShri | 0 | 94 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,043 |
https://leetcode.com/problems/find-the-winner-of-the-circular-game/discuss/1152479/Python-DLL-Solution | class Solution:
def findTheWinner(self, n: int, k: int) -> int:
class Node:
def __init__(self,val):
self.prev = None
self.next = None
self.val = val
head = Node(1)
temp = head
i = 2
while i<n:
nn... | find-the-winner-of-the-circular-game | Python DLL Solution | SaSha59 | 0 | 95 | find the winner of the circular game | 1,823 | 0.779 | Medium | 26,044 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1480131/Python-3-or-DP-or-Explanation | class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
n = len(obstacles)
dp = [[sys.maxsize] * n for _ in range(3)]
dp[0][0]= 1
dp[1][0]= 0
dp[2][0]= 1
for i in range(1, n):
dp[0][i] = dp[0][i-1] if obstacles[i] != 1 else sys.maxsize
... | minimum-sideway-jumps | Python 3 | DP | Explanation | idontknoooo | 4 | 539 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,045 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1480131/Python-3-or-DP-or-Explanation | class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
n = len(obstacles)
a, b, c = 1, 0, 1
for i in range(1, n):
a = a if obstacles[i] != 1 else sys.maxsize
b = b if obstacles[i] != 2 else sys.maxsize
c = c if obstacles[i] != 3 else sys.maxs... | minimum-sideway-jumps | Python 3 | DP | Explanation | idontknoooo | 4 | 539 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,046 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1152546/Python3-dp | class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
ans = [0]*3
for i in reversed(range(len(obstacles) - 1)):
tmp = [inf]*3
for k in range(3):
if obstacles[i]-1 != k:
tmp[k] = ans[k]
if obstacles[i]-1... | minimum-sideway-jumps | [Python3] dp | ye15 | 2 | 137 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,047 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1238483/Python-Recursive-greater-Bottom-Up | class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
@functools.lru_cache(None)
def recurse(idx, lane):
if idx >= len(obstacles): return 0
if obstacles[idx] == lane: return float('inf') ... | minimum-sideway-jumps | Python Recursive -> Bottom Up | dev-josh | 1 | 194 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,048 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1238483/Python-Recursive-greater-Bottom-Up | class Solution:
def minSideJumps(self, A: List[int]) -> int:
# Because we also "look ahead", we want to shorten the DP array
N = len(A) - 1
dp = [
[float('inf')] * 3
for _ in range(N)
]
# Initial state
dp[0] =... | minimum-sideway-jumps | Python Recursive -> Bottom Up | dev-josh | 1 | 194 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,049 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1238483/Python-Recursive-greater-Bottom-Up | class Solution:
def minSideJumps(self, A: List[int]) -> int:
# 1
N = len(A) - 1
dp = [1, 0, 1]
# 2
for i in range(1, N):
for j in range(3):
# 3
if j+1 == A[i]:
dp[j] = f... | minimum-sideway-jumps | Python Recursive -> Bottom Up | dev-josh | 1 | 194 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,050 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1161090/Python-Solution-Minimum-Sideway-Jumps | class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
n = len(obstacles)
inf = sys.maxsize
lane1,lane2,lane3 = 1,0,1
for indx in range(1,n):
lane1_yes,lane2_yes,lane3_yes = True,True,True
if obstacles[indx] == ... | minimum-sideway-jumps | Python Solution-Minimum Sideway Jumps | SaSha59 | 1 | 188 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,051 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1153029/100-faster-0(n)-bottom-up-dp-solution | class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
n = len(obstacles)-1
mem = [[-1]*(4) for i in range(n+1)]
def jumps(pos, lane):
# if we reached the last position return 0
if pos == n:
return 0
# first we check in memoization t... | minimum-sideway-jumps | 100% faster, 0(n) bottom up dp solution | deleted_user | 1 | 222 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,052 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1152560/4-lines-Python-O(n)-Dynamic-Programming-with-detailed-explanation-and-readable-code | class Solution:
def minSideJumps(self, obstacles: list[int]) -> int:
n = len(obstacles)
dp = [[float("inf")] * 4 for _ in range(n - 1)] + [[0] * 4]
for i in range(n - 2, -1, -1):
for l in {1, 2, 3} - {obstacles[i]}:
if obstacles[i + 1] != l:
... | minimum-sideway-jumps | 4 lines Python O(n) Dynamic Programming with detailed explanation and readable code | guangxu-li | 1 | 178 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,053 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1152560/4-lines-Python-O(n)-Dynamic-Programming-with-detailed-explanation-and-readable-code | class Solution:
def minSideJumps(self, obs: list[int]) -> int:
dp = [0] * 4
for i in range(len(obs) - 2, -1, -1):
# for l in {1, 2, 3} - {obs[i], obs[i + 1]}:
# if obs[i + 1] == l:
# dp[l] = 1 + min(dp[nl] for nl in {1, 2, 3} - {obs[i], l})
... | minimum-sideway-jumps | 4 lines Python O(n) Dynamic Programming with detailed explanation and readable code | guangxu-li | 1 | 178 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,054 |
https://leetcode.com/problems/minimum-sideway-jumps/discuss/1352763/One-pass-update-min-jumps-per-lane-89-speed | class Solution:
def minSideJumps(self, obstacles: List[int]) -> int:
lanes = [1, 0, 1]
for obstacle_id in obstacles:
if obstacle_id == 0:
lanes[0] = min(lanes[0], lanes[1] + 1, lanes[2] + 1)
lanes[1] = min(lanes[1], lanes[0] + 1, lanes[2] + 1)
... | minimum-sideway-jumps | One pass, update min jumps per lane, 89% speed | EvgenySH | 0 | 108 | minimum sideway jumps | 1,824 | 0.495 | Medium | 26,055 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1178397/Python3-simple-solution-beats-90-users | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
for i in range(1,len(nums)):
if nums[i] <= nums[i-1]:
x = nums[i]
nums[i] += (nums[i-1] - nums[i]) + 1
count += nums[i] - x
return count | minimum-operations-to-make-the-array-increasing | Python3 simple solution beats 90% users | EklavyaJoshi | 8 | 764 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,056 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1609290/WEEB-DOES-PYTHON | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
for i in range(1,len(nums)):
if nums[i] <= nums[i-1]:
initial = nums[i]
nums[i] = nums[i-1] + 1
count += nums[i] - initial
return count | minimum-operations-to-make-the-array-increasing | WEEB DOES PYTHON | Skywalker5423 | 2 | 95 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,057 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2152188/Python-or-Easy-and-Understanding-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
n=len(nums)
if(n==1):
return 0
ans=0
for i in range(1,n):
if(nums[i]<=nums[i-1]):
ans+=nums[i-1]-nums[i]+1
nums[i]=nums[i-1]+1
r... | minimum-operations-to-make-the-array-increasing | Python | Easy & Understanding Solution | backpropagator | 1 | 108 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,058 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1753941/Simple-Python-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
s = 0
for i in range(1,len(nums)):
s += max(0,nums[i-1]-nums[i]+1)
nums[i] = max(nums[i-1]+1, nums[i])
return s | minimum-operations-to-make-the-array-increasing | Simple Python Solution | MengyingLin | 1 | 65 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,059 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1326644/Simple-Python-Solution | class Solution:
def minOperations(self, nums) -> int:
count=0
value=0
for i in range(len(nums)-1):
if nums[i+1] <= nums[i]:
value = (nums[i]+1) -nums[i+1]
nums[i+1] +=value
count+=value
return count | minimum-operations-to-make-the-array-increasing | Simple Python Solution | sangam92 | 1 | 168 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,060 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1171530/Python-Easy-solution-faster-than-92 | class Solution:
def minOperations(self, nums: List[int]) -> int:
n=0
for i in range(0,len(nums)-1):
if (nums[i]>=nums[i+1]):
n+=1+(nums[i]-nums[i+1])
nums[i+1]=nums[i]+1
return n | minimum-operations-to-make-the-array-increasing | Python Easy solution faster than 92% | kashish_ag | 1 | 102 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,061 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1163946/Intuitive-approach-by-loop | class Solution:
def minOperations(self, nums: List[int]) -> int:
ans = 0
for i in range(1, len(nums)):
if nums[i] <= nums[i-1]:
ans += abs(nums[i-1]-nums[i]) + 1
nums[i] = nums[i-1] + 1
return ans | minimum-operations-to-make-the-array-increasing | Intuitive approach by loop | puremonkey2001 | 1 | 37 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,062 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1163137/Python3-sweep | class Solution:
def minOperations(self, nums: List[int]) -> int:
ans = 0
for i in range(1, len(nums)):
if nums[i-1] >= nums[i]:
ans += 1 + nums[i-1] - nums[i]
nums[i] = 1 + nums[i-1]
return ans | minimum-operations-to-make-the-array-increasing | [Python3] sweep | ye15 | 1 | 70 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,063 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2846523/Easy-to-Understand. | class Solution:
def minOperations(self, nums: List[int]) -> int:
res=0
first,second = 0,1
total = len(nums)
while total>1:
if nums[second] >= nums[first]+1:
total-=1
else:
total-=1
need = nums[first] - nums[seco... | minimum-operations-to-make-the-array-increasing | Easy to Understand. | Warrior-Quant | 0 | 1 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,064 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2814506/python-or-easy-or-solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
cn=0
l=[]
n=len(nums)
l.append(nums[0])
for i in range (1,(len(nums))):
if nums[i]<=l[i-1]:
l.insert(i,(l[i-1]+1))
cn+=(l[i-1]+1)-nums[i]
else:
... | minimum-operations-to-make-the-array-increasing | python | easy | solution | tush18 | 0 | 1 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,065 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2803779/Python-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
if(len(nums)==1):
return 0
o=0
for i in range(1,len(nums)):
if(nums[i]<=nums[i-1]):
o=nums[i-1]-nums[i]+1+o
nums[i]=nums[i]+nums[i-1]-nums[i]+1
return o | minimum-operations-to-make-the-array-increasing | Python Solution | CEOSRICHARAN | 0 | 3 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,066 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2797459/Python-Simple-greedy-solution | class Solution:
def minOperations(self, nums: list[int]) -> int:
ans, prev = 0, nums[0]
for i in nums[1:]:
if prev >= i:
ans += prev - i + 1
prev += 1
else:
prev = i
return ans | minimum-operations-to-make-the-array-increasing | [Python] Simple greedy solution | Mark_computer | 0 | 1 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,067 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2547646/EASY-PYTHON3-SOLUTION-98faster | class Solution:
def minOperations(self, nums: List[int]) -> int:
if len(nums) == 1:
return 0
count = 0
for i in range(1, len(nums)):
if nums[i] <= nums[i-1]:
temp = nums[i]
nums[i] = max(nums[i-1]+1, nums[i])
... | minimum-operations-to-make-the-array-increasing | ✅✔🔥 EASY PYTHON3 SOLUTION 🔥✅✔98%faster | rajukommula | 0 | 33 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,068 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2489257/Very-simple-python-solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
for i in range(1,len(nums)):
if nums[i-1] > nums[i]:
count += nums[i-1] - nums[i] + 1
nums[i] = nums[i-1] + 1
elif nums[i-1] == nums[i]:
count += 1
... | minimum-operations-to-make-the-array-increasing | Very simple python solution | aruj900 | 0 | 25 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,069 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2454847/Simple-Python-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
ans=0
for i in range(1,len(nums)):
if nums[i-1]>=nums[i]:
ans+=abs(nums[i-1]-nums[i])+1
nums[i]=nums[i-1]+1
return ans | minimum-operations-to-make-the-array-increasing | Simple Python Solution | _anuraag_ | 0 | 17 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,070 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2421719/Python-easy-solution-81.14-Faster | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
for num in range(len(nums) - 1):
if nums[num] >= nums[num + 1]:
diff = abs(nums[num] - nums[num + 1])
count += diff + 1
nums[num + 1] = nums[num + 1] + dif... | minimum-operations-to-make-the-array-increasing | Python easy solution 81.14% Faster | samanehghafouri | 0 | 20 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,071 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2367124/Minimum-Operations-to-Make-the-Array-Increasing | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
for i in range(1,len(nums)):
if nums[i]<=nums[i-1]:
x = nums[i-1]-nums[i]+1
count+=x
nums[i]+=x
return count | minimum-operations-to-make-the-array-increasing | Minimum Operations to Make the Array Increasing | dhananjayaduttmishra | 0 | 15 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,072 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2298987/Minimum-Operations-to-Make-the-Array-Increasing-With-Python3 | class Solution:
def minOperations(self, nums: List[int]) -> int:
total = 0
for i in range(len(nums)-1): # 0 1 2 3
if nums[i] >= nums[i+1]:
total += nums[i] - nums[i+1] + 1
nums[i+1] = nums[i] + 1
return total | minimum-operations-to-make-the-array-increasing | Minimum Operations to Make the Array Increasing With Python3 | ibrahimbayburtlu5 | 0 | 19 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,073 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/2055667/Python3-Easy-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
if len(nums) == 1:
return 0
output = 0
for i in range(1, len(nums)):
if nums[i] <= nums[i-1]:
output += nums[i-1] - nums[i] + 1
nums[i] = nums[i-1]+1
return output | minimum-operations-to-make-the-array-increasing | Python3 Easy Solution | PythonerAlex | 0 | 56 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,074 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1989991/Simple-Python-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
if len(nums)==0 or len(nums)==1:
return 0
ans=0
prev=nums[0]
for i in range(1, len(nums)):
if nums[i]>prev:
prev=nums[i]
else:
ans+=prev+1 - nums[i]
... | minimum-operations-to-make-the-array-increasing | Simple Python Solution | Siddharth_singh | 0 | 42 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,075 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1966066/Python-3-Solution-O(n)-Time-Complexity-Greedy-Alforithm-Explained-with-comments | class Solution:
def minOperations(self, nums: List[int]) -> int:
operations = 0
for i in range(len(nums) - 1):
if nums[i + 1] <= nums[i]: # Checking if the next element is smaller or equal
diff = nums[i] - nums[i + 1] # If the above codition is true, I take the difference... | minimum-operations-to-make-the-array-increasing | Python 3 Solution, O(n) Time Complexity, Greedy Alforithm, Explained with comments | AprDev2011 | 0 | 32 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,076 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1884208/Python-solution-faster-than-85 | class Solution:
def minOperations(self, nums: List[int]) -> int:
op_count = 0
for i in range(0, len(nums)-1):
if nums[i+1] <= nums[i]:
op_count += (nums[i] + 1) - nums[i+1]
nums[i+1] = nums[i] + 1
return op_count | minimum-operations-to-make-the-array-increasing | Python solution faster than 85% | alishak1999 | 0 | 67 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,077 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1859188/Python-dollarolution | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
for i in range(1,len(nums)):
if nums[i] < nums[i-1]+1:
x = nums[i-1] - nums[i] + 1
count += x
nums[i] += x
return count | minimum-operations-to-make-the-array-increasing | Python $olution | AakRay | 0 | 33 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,078 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1821440/5-Lines-Python-Solution-oror-70-Faster-oror-Memory-less-than-97 | class Solution:
def minOperations(self, nums: List[int]) -> int:
sm=sum(nums)
if len(nums)==1: return 0
for i in range(len(nums)-1):
if nums[i+1]<=nums[i]: nums[i+1]=nums[i]+1
return sum(nums)-sm | minimum-operations-to-make-the-array-increasing | 5-Lines Python Solution || 70% Faster || Memory less than 97% | Taha-C | 0 | 40 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,079 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1808555/Easy-and-Simple-Python-solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
if len(nums)==1:
return 0
c=0
for i in range(1,len(nums)):
if nums[i]<=nums[i-1]:
k=nums[i] #store the original value of nums[i]
nums[i]=nums[i-1]+1
... | minimum-operations-to-make-the-array-increasing | Easy and Simple Python solution | adityabaner | 0 | 32 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,080 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1799735/Python-O(n)-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
if len(nums) == 1:
return 0
result = 0
for i in range(len(nums) - 1):
if nums[i] < nums[i + 1]:
pass
else:
numOps = nums[i] - nums[i + 1] + 1... | minimum-operations-to-make-the-array-increasing | Python O(n) Solution | White_Frost1984 | 0 | 25 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,081 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1733814/Easy-Python-Solution-with-memory-usage-less-than-100-other-submissions. | class Solution:
def minOperations(self, nums: List[int]) -> int:
operations = 0
for i in range(len(nums)-1):
if nums[i] == nums[i+1]:
nums[i+1] += 1
operations += 1
elif nums[i] > nums[i+1]:
difference = n... | minimum-operations-to-make-the-array-increasing | Easy Python Solution with memory usage less than 100% other submissions. | babuchakjethiya | 0 | 71 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,082 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1682966/O(N)-python | class Solution:
def minOperations(self, nums: List[int]) -> int:
if len(nums) == 1:
return 0
prev = nums[0]
increment = 0
for i in range(1, len(nums)):
if nums[i] - prev <= 0:
increment = increment + prev - nums[i] + 1
prev = p... | minimum-operations-to-make-the-array-increasing | O(N) python | snagsbybalin | 0 | 42 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,083 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1642959/99.9-Simple-Python-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
result, level = 0, 0
for num in nums:
if num <= level:
level += 1
result += level - num
else:
level = num
return result | minimum-operations-to-make-the-array-increasing | 99.9% Simple Python Solution | migash | 0 | 115 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,084 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1580905/python-soln-based-on-hint-provided-by-leetcode | class Solution:
def minOperations(self, nums: List[int]) -> int:
count = 0
copy = nums[:]
for idx in range(1,len(nums)):
nums[idx] = max(nums[idx - 1] + 1, nums[idx])
count += abs(nums[idx] - copy[idx])
return count | minimum-operations-to-make-the-array-increasing | python soln based on hint provided by leetcode | anandanshul001 | 0 | 48 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,085 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1554346/Python3-Simple-Solution-but-not-fast | class Solution:
def minOperations(self, nums: List[int]) -> int:
sum_nums = sum(nums)
for idx in range(1, len(nums)):
nums[idx] = max(nums[idx], nums[idx-1] + 1)
return sum(nums) - sum_nums | minimum-operations-to-make-the-array-increasing | [Python3] Simple Solution but not fast | JingMing_Chen | 0 | 48 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,086 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1306299/Python3-Simple-code-faster-than-89-submissions | class Solution:
def minOperations(self, nums: list) -> int:
operations = 0
prev = None
for num in nums:
if not prev:
prev = num
continue
if prev >= num:
diff = prev - num
new_diff = diff+1
... | minimum-operations-to-make-the-array-increasing | [Python3] Simple code, faster than 89% submissions | GauravKK08 | 0 | 53 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,087 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1300790/Easy-Python-Solution(95.52) | class Solution:
def minOperations(self, nums: List[int]) -> int:
c=0
s=0
for i in range(1,len(nums)):
if(nums[i-1]>=nums[i]):
c=nums[i-1]-nums[i]+1
s+=c
nums[i]+=c
return s | minimum-operations-to-make-the-array-increasing | Easy Python Solution(95.52%) | Sneh17029 | 0 | 147 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,088 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1274508/Easy-Python-Solution | class Solution:
def minOperations(self, nums: List[int]) -> int:
n=len(nums)
if n==1:
return 0
c=0
for i in range(n-1):
if nums[i]>=nums[i+1]:
c=c+nums[i]-nums[i+1]+1
nums[i+1]=nums[i]+1
return c | minimum-operations-to-make-the-array-increasing | Easy Python Solution | sakshigoel123 | 0 | 63 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,089 |
https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/discuss/1170201/C%2B%2B-and-Python | class Solution:
def minOperations(self, nums: List[int]) -> int:
minimumOperations = 0
for i in range(1, len(nums)): # Note that for loop starts with index 1 (we skip the index 0)
if nums[i] <= nums[i-1]:
oldNumber = nums[i]
nums[i] = nums[i-1] + ... | minimum-operations-to-make-the-array-increasing | C++ and Python | vetikke | 0 | 52 | minimum operations to make the array increasing | 1,827 | 0.782 | Easy | 26,090 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1163133/Python-One-liner | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
return [sum(math.sqrt((x0-x1)**2 + (y0-y1)**2) <= r for x1, y1 in points) for x0, y0, r in queries] | queries-on-number-of-points-inside-a-circle | Python One-liner | Black_Pegasus | 21 | 4,000 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,091 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1167044/Python-3-512-ms-faster-than-100-using-complex-numbers | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
points = list(map(complex, *zip(*points)))
queries = ((complex(x, y), r) for x, y, r in queries)
return [sum(abs(p - q) <= r for p in points) for q, r in queries] | queries-on-number-of-points-inside-a-circle | [Python 3] 512 ms, faster than 100% using complex numbers | kingjonathan310 | 15 | 1,400 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,092 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/2484361/Simple-python-code-with-explanation | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
#create a empty list k
k = []
#create a variable and initialise it to 0
count = 0
#iterate over the elements in the queries
... | queries-on-number-of-points-inside-a-circle | Simple python code with explanation | thomanani | 3 | 138 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,093 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1493474/Python-Solution-Naive-and-Efficient-methods | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
count = [[] for each in range(len(queries))]
for i in range(len(queries)):
for j in range(len(points)):
x = queries[i][0]
y = queries[i][1]
... | queries-on-number-of-points-inside-a-circle | Python Solution - Naive and Efficient methods | deleted_user | 3 | 265 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,094 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1493474/Python-Solution-Naive-and-Efficient-methods | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
res = []
for x,y,r in queries:
count = 0
for a,b in points:
if (x-a)*(x-a) + (y-b)*(y-b) <= r*r:
count += 1
res.append(count)... | queries-on-number-of-points-inside-a-circle | Python Solution - Naive and Efficient methods | deleted_user | 3 | 265 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,095 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1163186/Easy-to-understand-Python-solution | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
answer = [0 for i in range(len(queries))]
for i, query in enumerate(queries):
for point in points:
if (((point[0] - query[0])*(point[0] - query[0])) + ((point[1] - quer... | queries-on-number-of-points-inside-a-circle | Easy to understand Python solution | donchenkonadia | 2 | 205 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,096 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1618006/python3-faster-than-97 | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
points = [complex(x,y) for x,y in points]
queries = [(complex(x, y), r) for x, y, r in queries]
return [sum(abs(p - q) <= r for p in points) for q, r in queries] | queries-on-number-of-points-inside-a-circle | python3 faster than 97% | fatmakahveci | 1 | 203 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,097 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1606303/Python-Easy-Solution-or-Math-Formula | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
circle = []
for x2, y2, radius in queries:
count = 0
for x1, y1 in points:
dis = ((x2-x1)**2+(y2-y1)**2)**0.5 # Use the Distance Formula...
if dis <= radius:
count += 1
circle.append(count)
... | queries-on-number-of-points-inside-a-circle | Python Easy Solution | Math Formula ✔ | leet_satyam | 1 | 127 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,098 |
https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/discuss/1383495/Python-with-comments | class Solution:
def countPoints(self, points: List[List[int]], queries: List[List[int]]) -> List[int]:
ans = []
for circle in queries:
radius = circle[-1]
count = 0
# Calculate distance of each point to circle's origin
# If distance <= rad... | queries-on-number-of-points-inside-a-circle | Python with comments | SmittyWerbenjagermanjensen | 1 | 151 | queries on number of points inside a circle | 1,828 | 0.864 | Medium | 26,099 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.