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/maximum-sum-of-an-hourglass/discuss/2649069/Python-oror-Easily-Understood-oror-Faster-than-96-oror-EXPLAINED-EASILY | class Solution:
def gridsSum(self, matrix1: List[List[int]]) -> int: # this method gives pattern sum of each 3*3 matrix
count = 0
for i in range(len(matrix1)):
for j in range(len(matrix1[i])):
if i==0:
count += matrix1[i][j]
if i==1 and... | maximum-sum-of-an-hourglass | π₯ Python || Easily Understood β
|| Faster than 96% || EXPLAINED EASILY | rajukommula | 0 | 29 | maximum sum of an hourglass | 2,428 | 0.739 | Medium | 33,200 |
https://leetcode.com/problems/maximum-sum-of-an-hourglass/discuss/2648891/Python3-brute-force | class Solution:
def maxSum(self, grid: List[List[int]]) -> int:
ans = 0
m, n = len(grid), len(grid[0])
for i in range(m-2):
for j in range(n-2):
val = grid[i][j] + grid[i][j+1] + grid[i][j+2] + grid[i+1][j+1] + grid[i+2][j] + grid[i+2][j+1] + grid[i+2][j+2]
... | maximum-sum-of-an-hourglass | [Python3] brute-force | ye15 | 0 | 10 | maximum sum of an hourglass | 2,428 | 0.739 | Medium | 33,201 |
https://leetcode.com/problems/maximum-sum-of-an-hourglass/discuss/2648776/Python-solution-using-sliding-window-TC-greaterO(n2)-(sliding-hourglass) | class Solution:
def maxSum(self, grid: List[List[int]]) -> int:
rows = len(grid)
cols = len(grid[0])
maxSum = 0
for row in range(rows - 2):
# TEMP VARIABLE TO STORE PART OF HOURGLASS
currTop3Sum = -1
currBottom3Sum = -1
currS... | maximum-sum-of-an-hourglass | Python solution using sliding window TC->O(n^2) (sliding hourglass) | theRealSandro | 0 | 33 | maximum sum of an hourglass | 2,428 | 0.739 | Medium | 33,202 |
https://leetcode.com/problems/maximum-sum-of-an-hourglass/discuss/2648772/Python-Solution | class Solution:
def maxSum(self, grid: List[List[int]]) -> int:
m = len(grid)
n = len(grid[0])
s = float("-inf")
for i in range(m):
c = 0
for j in range(n):
if i+2 <= m-1 and j+2 <= n-1:
c = grid[i][j] + grid[i][j+1] + grid[... | maximum-sum-of-an-hourglass | Python Solution | a_dityamishra | 0 | 19 | maximum sum of an hourglass | 2,428 | 0.739 | Medium | 33,203 |
https://leetcode.com/problems/maximum-sum-of-an-hourglass/discuss/2648739/Brute-force%3A-Accepted | class Solution:
def maxSum(self, grid: List[List[int]]) -> int:
m = len(grid); n = len(grid[0])
def hourglassSum(i: int, j: int) -> int:
return sum(grid[i - 1][j - 1:j + 2]) + grid[i][j] + sum(grid[i + 1][j - 1:j + 2])
maxSum = 0
for i, j in product(rang... | maximum-sum-of-an-hourglass | Brute force: Accepted | sr_vrd | 0 | 16 | maximum sum of an hourglass | 2,428 | 0.739 | Medium | 33,204 |
https://leetcode.com/problems/minimize-xor/discuss/2649210/O(log(n))-using-set-and-clear-bit-(examples) | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
nbit1 = 0
while num2>0:
nbit1 = nbit1 + (num2&1)
num2 = num2 >> 1
# print(nbit1)
chk = []
ans = 0
# print(bin(num1), bin(ans))
for i in range(31, -1... | minimize-xor | O(log(n)) using set and clear bit (examples) | dntai | 1 | 39 | minimize xor | 2,429 | 0.418 | Medium | 33,205 |
https://leetcode.com/problems/minimize-xor/discuss/2648726/Python-AC-Greedy-Bits-Easy-to-understand | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
numBitsToSet = 0
while num2:
numBitsToSet += num2 & 1
num2 = num2 >> 1
num1Str = bin(num1)[2:]
num1Len = len(num1Str)
outLen = max(num1Len, numBitsToSet)
... | minimize-xor | [Python] [AC] [Greedy] [Bits] Easy to understand | debayan8c | 1 | 60 | minimize xor | 2,429 | 0.418 | Medium | 33,206 |
https://leetcode.com/problems/minimize-xor/discuss/2845436/Python3-A-lot-of-binary-operators-Fast | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
# find the numbers of ones in nums
two_ones = bin(num2).count("1")
# now count the number of ones in num1 we want to
# delete
ones_bin = bin(num1)[2:]
# find the highest bit in ones
highest... | minimize-xor | [Python3] - A lot of binary operators - Fast | Lucew | 0 | 2 | minimize xor | 2,429 | 0.418 | Medium | 33,207 |
https://leetcode.com/problems/minimize-xor/discuss/2815643/Simple-Solution-using-greedy-approach-with-explanation | class Solution:
def minimizeXor(self, a: int, b: int) -> int:
result = ""
a_bin, b_bin = bin(a).lstrip('0b'), bin(b).lstrip('0b')
ones_in_b = b_bin.count('1')
if len(a_bin) < len(b_bin):
a_bin = abs(len(b_bin) - len(a_bin)) * ('0') + a_bin
elif len(b_bin) < len(a... | minimize-xor | Simple Solution using greedy approach with explanation | cppygod | 0 | 4 | minimize xor | 2,429 | 0.418 | Medium | 33,208 |
https://leetcode.com/problems/minimize-xor/discuss/2793673/Bit-manipulations-90-speed | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
# determine number of 1's in binary representation
# which is also equal to bin(num2[1:]).count("1")
n2 = 0
while num2:
if num2 & 1: # last bit is 1
n2 += 1 # increase count
... | minimize-xor | Bit manipulations, 90% speed | EvgenySH | 0 | 15 | minimize xor | 2,429 | 0.418 | Medium | 33,209 |
https://leetcode.com/problems/minimize-xor/discuss/2776885/easy-solution-using-python-(bit-manipulation) | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
def count_bits(n):
c = 0
while n>0:
if n&1 == 1:
c +=1
n = n>>1
return c
bits = count_bits(num2)
ans = 0
... | minimize-xor | easy solution using python (bit manipulation) | Ramganga143 | 0 | 6 | minimize xor | 2,429 | 0.418 | Medium | 33,210 |
https://leetcode.com/problems/minimize-xor/discuss/2737313/Python3-Greedy | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
r, choices = 0, sorted([(num1^(1<<i)) - num1 for i in range(32)])
while num2:
while not num2 & 1:
num2>>=1
num2>>=1
r += abs(choices.pop(0))
return r | minimize-xor | Python3 Greedy | godshiva | 0 | 4 | minimize xor | 2,429 | 0.418 | Medium | 33,211 |
https://leetcode.com/problems/minimize-xor/discuss/2705632/Python-or-Simple-bit-solution | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
count = str(bin(num2))[2:].count("1")
num1_bin = str(bin(num1))[2:]
ans = ""
for i in range(len(num1_bin)):
if len(num1_bin) - i <= count:
ans += "1"*count
break
... | minimize-xor | Python | Simple bit solution | LordVader1 | 0 | 14 | minimize xor | 2,429 | 0.418 | Medium | 33,212 |
https://leetcode.com/problems/minimize-xor/discuss/2661819/My-Ugly-God-awful-code-that-somehow-beats-98-in-terms-of-runtime | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
n1 = bin(num1)
n2 = bin(num2)
if n1.count('1')==n2.count('1'):
return(num1)
set_bits=n2.count('1')
set_bits1 = n1.count('1')
s = n1.replace('b'... | minimize-xor | My Ugly God awful code that somehow beats 98% in terms of runtime | tnutala | 0 | 13 | minimize xor | 2,429 | 0.418 | Medium | 33,213 |
https://leetcode.com/problems/minimize-xor/discuss/2658898/Python-Solution | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
bin1 = list('{0:b}'.format(num1))
bin2 = list('{0:b}'.format(num2))
ans = deque(["0"] * len(bin1))
one = bin2.count("1")
for i in range(len(bin1)):
if one == 0:
b... | minimize-xor | Python Solution | maomao1010 | 0 | 11 | minimize xor | 2,429 | 0.418 | Medium | 33,214 |
https://leetcode.com/problems/minimize-xor/discuss/2652305/Simple-Python-Solution | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
setBits = 0
while(num2 > 0):
setBits += num2%2
num2 //= 2
bits = [0]*32
for i in range(0, 32):
bits[i] = num1%2
num1 //= 2
if(num1 == 0):
br... | minimize-xor | Simple Python Solution | kardeepakkumar | 0 | 9 | minimize xor | 2,429 | 0.418 | Medium | 33,215 |
https://leetcode.com/problems/minimize-xor/discuss/2651867/Python-O(logn)-solution-.-Beats-99-of-python-Submissions | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
ones = bin(num2)[2:].count('1')
# Took 32bit because num1 and num2 are less than 2^32 (as per the constraints)
bin_num1 = "{:032b}".format(num1)
lis = list(bin_num1)
ans = ['0']*32 # Empty Binary array
... | minimize-xor | Python O(logn) solution . Beats 99% of python Submissions | anup_omkar | 0 | 22 | minimize xor | 2,429 | 0.418 | Medium | 33,216 |
https://leetcode.com/problems/minimize-xor/discuss/2651207/Python-3Rule-based-approach | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
ones = bin(num2).count('1')
num1 = bin(num1)[2:]
ans = []
# set all '1' to '0' in num1
for x in num1:
if x == '1' and ones:
ans.append('1')
... | minimize-xor | [Python 3]Rule based approach | chestnut890123 | 0 | 59 | minimize xor | 2,429 | 0.418 | Medium | 33,217 |
https://leetcode.com/problems/minimize-xor/discuss/2650737/Python-or-Easy-to-Understand-or-O(n)-approach | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
num1=bin(num1)[2:]
num2=bin(num2)[2:]
#add padding to make length equal
alen=len(num1)
blen=len(num2)
if alen>blen:
num1='0'*(alen-blen)+num1
else:
num2='0'*... | minimize-xor | Python | Easy to Understand | O(n) approach | mamtadnr | 0 | 18 | minimize xor | 2,429 | 0.418 | Medium | 33,218 |
https://leetcode.com/problems/minimize-xor/discuss/2650394/Don't-see-my-solution | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
a = 0
b = num2.bit_count()
for i in range(32, -1, -1):
if num1&(1<<i):
b -= 1
a ^= 1<<i
if b == 0:
break
#print(a, b)
... | minimize-xor | Don't see my solution π | ManojKumarPatnaik | 0 | 4 | minimize xor | 2,429 | 0.418 | Medium | 33,219 |
https://leetcode.com/problems/minimize-xor/discuss/2649764/Python-3-or-Easy-with-quick-explanation-or-Bit-manipulation | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
bin_num1="{0:b}".format(int(num1))
bin_num2="{0:b}".format(int(num2))
val=bin_num2.count('1')
arr=['0' for i in bin_num1]
for i in range(len(bin_num1)):
if bin_num1[i]=='1':
arr[i]... | minimize-xor | Python 3 | Easy with quick explanation | Bit manipulation | RickSanchez101 | 0 | 37 | minimize xor | 2,429 | 0.418 | Medium | 33,220 |
https://leetcode.com/problems/minimize-xor/discuss/2649362/Python-or-Bit-flip-from-the-end | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
n1, n2 = bin(num1).count('1'), bin(num2).count('1')
print(n1, n2)
print(bin(num1), bin(num2))
if n1 == n2:
return num1
elif n1 < n2:
M = len(f'{num2:b}')
result = list(form... | minimize-xor | Python | Bit flip from the end | tillchen417 | 0 | 1 | minimize xor | 2,429 | 0.418 | Medium | 33,221 |
https://leetcode.com/problems/minimize-xor/discuss/2649350/Short-Python3-Greedy-one-loop | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
bal = bin(num2).count('1')
i, bits = 30, 31
res = 0
# if we have balance and there are more choice to make: more bits to decide than bal
while i >= 0 and 0 < bal < i + 1:
if num1 & 1... | minimize-xor | Short Python3 Greedy one loop | pya | 0 | 52 | minimize xor | 2,429 | 0.418 | Medium | 33,222 |
https://leetcode.com/problems/minimize-xor/discuss/2649252/Python-or-Greedy-Bit-manipulation | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
x=bin(num1)[2:]
h=bin(num2)[2:]
setbit=h.count("1")
# print(setbit)
# print(x,h)
p=len(x)
m=0
cnt=0
chk=set()
for i in x:
if i=="1":
chk.add... | minimize-xor | Python | Greedy Bit manipulation | Prithiviraj1927 | 0 | 45 | minimize xor | 2,429 | 0.418 | Medium | 33,223 |
https://leetcode.com/problems/minimize-xor/discuss/2649183/Python3-Greedy-Solution | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
bits = bin(num2)[2:].count('1')
data = bin(num1)[2:]
data = (32 - len(data))*'0' + data
data = [int(x) for x in data]
res = [0]*32
for i in range(32):
i... | minimize-xor | Python3 Greedy Solution | xxHRxx | 0 | 11 | minimize xor | 2,429 | 0.418 | Medium | 33,224 |
https://leetcode.com/problems/minimize-xor/discuss/2649088/Python-Answer-Using-Set | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
b = str(bin(num2))[2:]
c = b.count('1')
m = set()
a = str(bin(num1))[2:]
for i,v in enumerate(a):
if c == 0:
break
if v == '1':
... | minimize-xor | [Python Answerπ€«πππ] Using Set | xmky | 0 | 28 | minimize xor | 2,429 | 0.418 | Medium | 33,225 |
https://leetcode.com/problems/minimize-xor/discuss/2648896/Python3-bit-operations | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
n = num2.bit_count()
ans = 0
for i in range(29, -1, -1):
if not n: break
if num1 & 1<<i:
ans ^= 1<<i
n -= 1
for i in range(30):
if not n: bre... | minimize-xor | [Python3] bit operations | ye15 | 0 | 12 | minimize xor | 2,429 | 0.418 | Medium | 33,226 |
https://leetcode.com/problems/minimize-xor/discuss/2648805/Python-Solution | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
x = bin(num1)[2:]
y = bin(num2)[2:]
a = x.count("1")
b = y.count("1")
if len(x) > len(y):
y = "0"*(len(x)-len(y)) + y
elif len(y) > len(x):
x = "0"*(len(y)-len(x)) + x
... | minimize-xor | Python Solution | a_dityamishra | 0 | 22 | minimize xor | 2,429 | 0.418 | Medium | 33,227 |
https://leetcode.com/problems/minimize-xor/discuss/2648660/Greedy-from-left-then-from-right | class Solution:
def minimizeXor(self, num1: int, num2: int) -> int:
bits2 = bin(num2)[2:].count("1")
bin1 = bin(num1)[2:]
if len(bin1) <= bits2:
return (1 << bits2) - 1
ans = 0
for i in range(len(bin1)):
if bin1[i] == "1":
... | minimize-xor | Greedy from left, then from right | sr_vrd | 0 | 36 | minimize xor | 2,429 | 0.418 | Medium | 33,228 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2648661/Python3-Dynamic-Programming-Clean-and-Concise | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
if len(set(s)) == 1:
return n
dp = [1] * n
for i in range(n - 2, -1, -1):
for l in range(1, (n - i) // 2 + 1):
if s[i : i + l] == s[i + l : i + 2 * l]:
dp[i] ... | maximum-deletions-on-a-string | [Python3] Dynamic Programming, Clean & Concise | xil899 | 10 | 1,000 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,229 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2648661/Python3-Dynamic-Programming-Clean-and-Concise | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
if len(set(s)) == 1:
return n
dp, M = [1] * n, [1] * n
for i in range(n - 2, -1, -1):
for l in range(1, (n - i) // 2 + 1):
if dp[i] >= M[i + l] + 1:
break
... | maximum-deletions-on-a-string | [Python3] Dynamic Programming, Clean & Concise | xil899 | 10 | 1,000 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,230 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2656689/Python-3-DP-bottom-up-%2B-Substr-Hash | class Solution:
def deleteString(self, s: str) -> int:
if len(set(s)) == 1: return len(s)
MOD = 10**10 + 7 #use MODulus to avoid large int in python.
BASE = 26 + 1 #base 26, lower case alphas only.
s_hash = [0] #prefix hash of s.
for char in s:
... | maximum-deletions-on-a-string | Python 3, DP bottom-up + Substr Hash | wangtan83 | 1 | 67 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,231 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2648825/Python-AC-Trick-Dynammic-Programming-based.-Trick-to-avoid-TLE | class Solution:
def deleteString(self, s: str) -> int:
from collections import Counter
N = len(s)
global memo
memo = {}
#print('\n\nTest case -> s:', s, 'N:', N)
return rem(s)
def rem(s):
#print('Rem Start -> s:', s)
global memo
if s in memo:
#pr... | maximum-deletions-on-a-string | [Python] [AC] [Trick] Dynammic Programming based. Trick to avoid TLE | debayan8c | 1 | 76 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,232 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2652768/Python-keeps-getting-TLE | class Solution:
def deleteString(self, s: str) -> int:
@cache
def dfs(s, i):
if i == len(s):
return 0
ret = 1
span = 1
while i + span * 2 <= len(s):
if s[i:i+span] == s[i+span:i+span*2]:
ret = max(ret... | maximum-deletions-on-a-string | Python keeps getting TLE | pya | 0 | 30 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,233 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2650387/100-or-0-ms-or-faster | class Solution:
def deleteString(self, s: str) -> int:
if min(s) == max(s):
return len(s)
n = len(s)
eq = [[0]*(n+1) for i in range(n+1)]
for i in range(n-1, -1, -1):
for j in range(n-1, -1, -1):
if s[i] == s[j]:
eq[i][j] = ... | maximum-deletions-on-a-string | β¬οΈβ
100 % | 0 ms | faster | ManojKumarPatnaik | 0 | 10 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,234 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2649163/O(n3)-using-dynamic-programming-with-branch-and-bound-(Examples) | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
print("s:", s)
dp = [0] * n
vmax = 0
for i in range(n-1):
print("+ ", i, end = ": ")
for l in range(1, min(i+1, n-(i+1))+1):
if s[i-l+1:i+1] == s[i+1:i+1+l]:
... | maximum-deletions-on-a-string | O(n^3) using dynamic programming with branch and bound (Examples) | dntai | 0 | 50 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,235 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2649074/Python3-Recursion-to-Top-Down-Memoization | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
# Edge case for s with all-same characters like "aaaaaaaaaa...aaaaa"
if len(set(s))==1:
return n
# Returns the maximum number of operations needed to delete all of s[i:]
def helper(i):
... | maximum-deletions-on-a-string | [Python3] Recursion to Top-Down Memoization | seung_hun | 0 | 69 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,236 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2649074/Python3-Recursion-to-Top-Down-Memoization | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
# Edge case for s with all-same characters like "aaaaaaaaaa...aaaaa"
if len(set(s))==1:
return n
memo = {}
# Returns the maximum number of operations needed to delete all of s[i:... | maximum-deletions-on-a-string | [Python3] Recursion to Top-Down Memoization | seung_hun | 0 | 69 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,237 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2648910/Python3-O(N2)-DP-via-KMP | class Solution:
def deleteString(self, s: str) -> int:
if len(set(s)) == 1: return len(s)
dp = [1]*len(s)
for i in range(len(s)-2, -1, -1):
lsp = [0]
k = 0
for j in range(i+1, len(s)):
while k and s[i+k] != s[j]: k = lsp[k-1]
... | maximum-deletions-on-a-string | [Python3] O(N^2) DP via KMP | ye15 | 0 | 67 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,238 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2648820/Short-and-clean-python-O(N2)-longest-common-prefix | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
# lp[i][j] is longest prefix for i and j
lp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n):
lp[i][i] = n - i
for i in range(n - 1, -1, -1):
for j in range(i, n):
... | maximum-deletions-on-a-string | Short and clean, python O(N^2) longest common prefix | plus2047 | 0 | 14 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,239 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2648810/Python-dfs-%2B-memoization-circumvent-all-'a'-cases | class Solution:
def __init__(self):
self.maxop = 0
self.cache = {}
def dfs(self, string, curmax):
self.maxop = max(self.maxop, curmax)
if len(string) == 1:
return
for i in range(1, len(string) // 2 + 1):
if string[:i] == str... | maximum-deletions-on-a-string | [Python] dfs + memoization, circumvent all 'a' cases | uesugi000kenshin | 0 | 12 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,240 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2654596/I'm-not-happy-that-this-was-accepted-and-%22beats-100%22 | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
@cache
def dp(i: int = 0) -> int:
if i == n - 1:
return 1
maxOperations = 0
for l in range(1, (n - i) // 2 + 1):
if s[i : i + l] == s[i + l:i + 2 * l... | maximum-deletions-on-a-string | I'm not happy that this was accepted and "beats 100%"π | sr_vrd | -1 | 33 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,241 |
https://leetcode.com/problems/maximum-deletions-on-a-string/discuss/2654596/I'm-not-happy-that-this-was-accepted-and-%22beats-100%22 | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
if len(set(s)) == 1:
return n
@cache
def dp(i: int = 0) -> int:
if i == n - 1:
return 1
maxOperations = 0
for l in range(1, (n - i) // 2 + 1):
... | maximum-deletions-on-a-string | I'm not happy that this was accepted and "beats 100%"π | sr_vrd | -1 | 33 | maximum deletions on a string | 2,430 | 0.322 | Hard | 33,242 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2693491/Python-Elegant-and-Short-or-No-indexes-or-99.32-faster | class Solution:
"""
Time: O(n)
Memory: O(1)
"""
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
best_id = best_time = start = 0
for emp_id, end in logs:
time = end - start
if time > best_time or (time == best_time and best_id > emp_id):
... | the-employee-that-worked-on-the-longest-task | Python Elegant & Short | No indexes | 99.32% faster | Kyrylo-Ktl | 4 | 47 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,243 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2679148/Python-Explained-or-O(n) | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
times = [logs[0][1]]
max_time = times[0]
for i in range(1, len(logs)):
times.append(logs[i][1]-logs[i-1][1])
max_time = max(max_time, times[i])
id = 500
fo... | the-employee-that-worked-on-the-longest-task | Python [Explained] | O(n) | diwakar_4 | 2 | 36 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,244 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2800946/Python3-short-and-simple | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
startTime, maxTime, ans = 0, 0, 0
for i, e in logs:
t = e - startTime
if t >= maxTime:
ans = min(ans,i) if t == maxTime else i
maxTime = t
startTime = e
... | the-employee-that-worked-on-the-longest-task | Python3 short and simple | titov | 0 | 5 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,245 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2722259/Basic-Solution | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
# each task represents an index in array (increasingly)
# the span of task is the difference between end time of
# preivous task and next task
# use a hashmap with times as keys and a list to hold
... | the-employee-that-worked-on-the-longest-task | Basic Solution | andrewnerdimo | 0 | 4 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,246 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2718537/Use-some-variables-to-record-longest_time-and-id | class Solution:
def hardestWorker(self, n: int, logs: list[list[int]]) -> int:
"""
TC: O(n)
SC: O(1)
"""
longest_time = 0
longest_time_id = 0
pre_leave_time = 0
for _id, leave_time in logs:
worked_time = leave_time - pre_leave_time
... | the-employee-that-worked-on-the-longest-task | Use some variables to record longest_time and id | woora3 | 0 | 3 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,247 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2702899/Python-or-Simple-sorting | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
arr = [[logs[0][0], logs[0][1]]]
for i in range(1, len(logs)):
arr.append([logs[i][0], logs[i][1] - logs[i - 1][1]])
arr.sort(key = lambda x: (x[1], -x[0]))
return arr[-1][0] | the-employee-that-worked-on-the-longest-task | Python | Simple sorting | LordVader1 | 0 | 2 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,248 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2694286/One-pass-75-speed | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
employee_id = logs[0][0]
last_time = largest_interval = 0
for employee, t in logs:
if (interval := t - last_time) > largest_interval:
largest_interval = interval
employe... | the-employee-that-worked-on-the-longest-task | One pass, 75% speed | EvgenySH | 0 | 2 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,249 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2693990/Python3-O(n)-simple-and-intuitive-solution. | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
start_time = 0
res = [float("INF"), 0]
for i, end_time in logs:
if end_time - start_time > res[1]:
res = [i, end_time - start_time]
elif end_time - sta... | the-employee-that-worked-on-the-longest-task | [Python3] O(n) simple and intuitive solution. | MaverickEyedea | 0 | 5 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,250 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2691829/Python3-Running-Best-As-Tuple | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
la = 0
m = 0, 0
for i in range(len(logs)):
d = logs[i][1] - la, -logs[i][0]
la = logs[i][1]
if d > m:
m = d
return -m[1] | the-employee-that-worked-on-the-longest-task | Python3 Running Best As Tuple | godshiva | 0 | 2 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,251 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2689796/Python-(Faster-than-92)-easy-to-understand-O(N)-solution | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
longestTime = 0
ans = n
currTime = 0
for emp_id, leaveTime in logs:
timeTaken = leaveTime - currTime
if timeTaken > longestTime:
ans = emp_id
longest... | the-employee-that-worked-on-the-longest-task | Python (Faster than 92%) easy to understand O(N) solution | KevinJM17 | 0 | 5 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,252 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2685273/SIMPLE-PYTHON-SOLLUTION-oror-EASILY-UNDARSTANDABLE | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
ans=0
s=0
x=0
for i in logs:
y=i[1]-x
if ans<=y:
if ans==y:
s=min(s,i[0])
else:
s=i[0]
ans=y
... | the-employee-that-worked-on-the-longest-task | SIMPLE PYTHON SOLLUTION || EASILY UNDARSTANDABLE | narendra_036 | 0 | 10 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,253 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2685255/The-Employee-That-Worked-on-the-Longest-Task-oror-Python3 | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
diff=0
ans=[]
maxx=0
for i in range(len(logs)):
a=logs[i][1]-diff
ans.append([logs[i][0],a])
maxx=max(a,maxx)
diff=logs[i][1]
minn=n
... | the-employee-that-worked-on-the-longest-task | The Employee That Worked on the Longest Task || Python3 | shagun_pandey | 0 | 2 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,254 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2683230/python-O(1)-space-and-O(n)-time-no-hashmap! | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
count = 0 #where the diffrence of two numbers is stored
prev = 0 #stores the previous time
mx = 0
for idx, val in enumerate(logs):
ids, time = val
if time - prev... | the-employee-that-worked-on-the-longest-task | python O(1) space and O(n) time no hashmap! | pandish | 0 | 9 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,255 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2681293/Easy-and-faster-linear-solution | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
best=0
bestid=None
last=0
for i,j in logs:
current=j-last
if(current==best and bestid>i):
best=current
bestid=i
if(current>best):
... | the-employee-that-worked-on-the-longest-task | Easy and faster linear solution | Raghunath_Reddy | 0 | 7 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,256 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2681122/Python.-one-for-loop | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
prev = longest = 0
for employee_id, time_finished in logs:
time_worked, prev = time_finished - prev, time_finished
if time_worked > longest:
longest = time_worked
... | the-employee-that-worked-on-the-longest-task | Python. one for-loop | blue_sky5 | 0 | 24 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,257 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2679779/Python%2BNumPy | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
import numpy as np
diff=np.diff([0]+[y for x,y in logs])
mx=np.max(diff)
where=np.where(diff==mx)[0]
return np.min([logs[i][0] for i in where]) | the-employee-that-worked-on-the-longest-task | Python+NumPy | Leox2022 | 0 | 2 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,258 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2679761/Python3-Simple-Solution | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
prevTime = 0
resId = -1
timeTaken = 0
for id, leaveTime in logs:
if leaveTime - prevTime > timeTaken:
resId = id
timeTaken = leaveTime - prevTime
... | the-employee-that-worked-on-the-longest-task | Python3 Simple Solution | mediocre-coder | 0 | 15 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,259 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2679388/Python-Answer-Dictionary-and-hashmap | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
hm = defaultdict(int)
cur = 0
for log in logs:
hm[log[0]] = max(log[1]-cur, hm[log[0]])
cur = log[1]
m = max(hm.values())
for h in ... | the-employee-that-worked-on-the-longest-task | [Python Answerπ€«πππ] Dictionary and hashmap | xmky | 0 | 21 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,260 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2679298/Python3-Solution-or-Simple-Linear-Traversal-O(N)-TIME-and-O(1)-SPACE! | class Solution:
#Let m = len(logs)!
#Time-Complexity: O(m)
#Space-Complexity: O(1)
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
#Approach: Logs input is already sorted by increasing order of Leavetime! This means that we can linearly
#traverse and keep track of best hardestworker t... | the-employee-that-worked-on-the-longest-task | Python3 Solution | Simple Linear Traversal O(N) TIME and O(1) SPACE! | JOON1234 | 0 | 15 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,261 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2679270/Easy-to-read | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
max_work_obj = (logs[0][0], logs[0][1])
for i in range(1, len(logs)):
emp_id, work_done = logs[i][0], logs[i][1]-logs[i-1][1]
if work_done > max_work_obj[1]:
max_work_obj = (emp_id,... | the-employee-that-worked-on-the-longest-task | Easy to read | np137 | 0 | 13 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,262 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2679134/Python3-Simple | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
logs=[[0,0]] + logs
answ=0
maxT=0
for i in range(1,len(logs)):
e,t=logs[i]
E,T=logs[i-1]
if maxT<t-T:
maxT=t-T
answ=e
elif ma... | the-employee-that-worked-on-the-longest-task | Python3, Simple | Silvia42 | 0 | 11 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,263 |
https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/discuss/2678928/Python-Simple-Python-Solution-Using-BruteForce | class Solution:
def hardestWorker(self, n: int, logs: List[List[int]]) -> int:
result = 0
max_time = -10000000000000000
last_time = 0
for index in range(len(logs)):
user_id, user_time = logs[index]
if index == 0:
last_time = user_time
max_time = user_time
result = user_id
else:
cur... | the-employee-that-worked-on-the-longest-task | [ Python ] β
β
Simple Python Solution Using BruteForce π₯³βπ | ASHOK_KUMAR_MEGHVANSHI | 0 | 42 | the employee that worked on the longest task | 2,432 | 0.489 | Easy | 33,264 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2684467/Python-3-Easy-O(N)-Time-Greedy-Solution-Explained | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ans = [0 for i in range(len(pref))]
ans[0] = pref[0]
for i in range(1, len(pref)):
ans[i] = pref[i-1]^pref[i]
return ans | find-the-original-array-of-prefix-xor | [Python 3] Easy O(N) Time Greedy Solution Explained | user2667O | 1 | 29 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,265 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2679089/Python-EXPLAINED-or-O(n) | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
xor = 0
ans = []
for i in range(len(pref)):
ans.append(pref[i]^xor)
xor ^= ans[i]
return ans | find-the-original-array-of-prefix-xor | Python [EXPLAINED] | O(n) | diwakar_4 | 1 | 11 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,266 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2817631/Python-Solution-or-Simple-Logic-or-99-Faster | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ans = [pref[0]] * len(pref)
for i in range(1,len(ans)):
ans[i] = pref[i] ^ pref[i-1]
return (ans) | find-the-original-array-of-prefix-xor | Python Solution | Simple Logic | 99% Faster | Gautam_ProMax | 0 | 1 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,267 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2816559/Python-3-Simple-Approach-with-linear-complexity | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
result=[pref[0]]
for i in range(1,len(pref)):
result.append(pref[i]^pref[i-1])
return result | find-the-original-array-of-prefix-xor | Python-3 Simple Approach with linear complexity | spark1443 | 0 | 3 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,268 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2806940/Python-Solution | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
l=[]
l.append(pref[0])
for i in range(1,len(pref)):
l.append(pref[i-1]^pref[i])
return l | find-the-original-array-of-prefix-xor | Python Solution | CEOSRICHARAN | 0 | 1 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,269 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2792147/O(n)-solution | class Solution:
def findArray(self, a: List[int]) -> List[int]:
pref=a[0]
ans=[a[0]]
for i in range(1,len(a)):
ans=pref^a[i]
ans.append(ans)
pref=pref^ans[i]
return(rans) | find-the-original-array-of-prefix-xor | O(n) solution Κ α΅α΄₯α΅ Κ | katerrinss | 0 | 2 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,270 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2788648/2433.-Find-The-Original-Array-of-Prefix-Xor | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
result = []
if len(pref) == 1:
return pref
result.append(pref[0])
for i in range(0, len(pref)-1):
result.append(pref[i] ^ pref[i+1])
return result | find-the-original-array-of-prefix-xor | 2433. Find The Original Array of Prefix Xor | sungmin69355 | 0 | 1 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,271 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2780802/XOR-oror-Python3-oror-CPP | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ans = [pref[0]]
for i in range(1, len(pref)):
ans.append(pref[i - 1] ^ pref[i])
return ans | find-the-original-array-of-prefix-xor | XOR || Python3 || CPP | joshua_mur | 0 | 2 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,272 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2780244/Python3-simple-solution | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
result = [pref[0]]
previousXor = pref[0]
for i in range(1,len(pref)):
a = previousXor ^ pref[i]
result.append(a)
previousXor ^= a
return result | find-the-original-array-of-prefix-xor | Python3 simple solution | EklavyaJoshi | 0 | 2 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,273 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2745232/Python3-One-Liner | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
return [pref[0]] + [pref[i] ^ pref[i - 1] for i in range(1, len(pref))] | find-the-original-array-of-prefix-xor | [Python3] One-Liner | ivnvalex | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,274 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2702902/Python-or-Xor-restoration | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ans = [pref[0]]
carry = pref[0]
for i in range(1, len(pref)):
carry ^= pref[i]
ans.append(carry)
carry = pref[i]
return ans | find-the-original-array-of-prefix-xor | Python | Xor restoration | LordVader1 | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,275 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2698986/Simple-python-code-with-explanation | class Solution:
def findArray(self, pref):
#create a list(ans) to store the result
ans = [pref[0]]
#create a list(storage) to store the xor values of all previous elements in ans
storage = [0]
#first element in ans will be same as the first element in pref
#so start i... | find-the-original-array-of-prefix-xor | Simple python code with explanation | thomanani | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,276 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2698986/Simple-python-code-with-explanation | class Solution:
#instead of using storage list i have used variable storage
#because we need only last element of storage
#this will decrease the space complexity
def findArray(self, pref):
ans = [pref[0]]
storage =0
for i in range(1,len(pref)):
storage = storage ^ ... | find-the-original-array-of-prefix-xor | Simple python code with explanation | thomanani | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,277 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2698728/Python-Code | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
res = []
prev = 0
cumulative = 0
for n in pref:
prev = cumulative
cumulative = cumulative ^ n
res.append(cumulative)
cumulative = cumulative ^ prev
return res | find-the-original-array-of-prefix-xor | Python Code | akshit2649 | 0 | 2 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,278 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2698054/Python3-Simple-Solution | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
L = len(pref)
res = [None]*L
tmp = 0
for i in range(L):
res[i] = pref[i] ^ tmp
tmp = tmp ^ res[i]
return res | find-the-original-array-of-prefix-xor | Python3 Simple Solution | mediocre-coder | 0 | 2 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,279 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2697766/Python3-Simple-InPlace-Approach | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
for i in range(len(pref)-1, 0, -1):
pref[i] = pref[i-1] ^ pref[i]
return pref | find-the-original-array-of-prefix-xor | [Python3] Simple InPlace Approach | axce1 | 0 | 3 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,280 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2689745/Python-(Faster-than-90)-easy-to-understand-O(N)-solution | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
n = len(pref)
curr = pref[0]
ans = [pref[0]]
for i in range(1, n):
ans.append(curr ^ pref[i])
curr ^= ans[-1]
return ans | find-the-original-array-of-prefix-xor | Python (Faster than 90%) easy to understand O(N) solution | KevinJM17 | 0 | 4 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,281 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2682410/python3-Iteration-sol-for-reference | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ans = [0]*len(pref)
ans[0] = pref[0]
for n in range(1, len(pref)):
ans[n] = pref[n-1] ^ pref[n]
return ans | find-the-original-array-of-prefix-xor | [python3] Iteration sol for reference | vadhri_venkat | 0 | 4 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,282 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2682131/Python-or-Very-Simple | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
n = len(pref)
arr = [0] * n
arr[0] = pref[0]
for i in range(1, n):
arr[i] = pref[i] ^ pref[i - 1]
return arr | find-the-original-array-of-prefix-xor | Python | Very Simple | on_danse_encore_on_rit_encore | 0 | 2 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,283 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2681141/Easy-and-Optimal-faster | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
res = [pref[0]]
for i in range(1,len(pref)):
res.append(pref[i]^pref[i-1])
return res | find-the-original-array-of-prefix-xor | Easy and Optimal faster | Raghunath_Reddy | 0 | 3 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,284 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2680064/Python-(system-of-logical-equations)-2-solutions-with-with-an-explanation | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
xor=[pref[0]]
for i in range(0,len(pref)-1):
xor.append(pref[i]^pref[i+1])
return xor | find-the-original-array-of-prefix-xor | Python (system of logical equations), 2 solutions with with an explanation | Leox2022 | 0 | 4 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,285 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2680064/Python-(system-of-logical-equations)-2-solutions-with-with-an-explanation | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
return list(map(lambda x:x[0]^x[1],zip(pref[0:-1],pref[1:]))).insert(0,pref[0]) | find-the-original-array-of-prefix-xor | Python (system of logical equations), 2 solutions with with an explanation | Leox2022 | 0 | 4 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,286 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2679732/Python3-or-Simple-Bitwise-Manipulation-Formula-O(N)-TIME-AND-O(1)-SPACE! | class Solution:
#Time-Complexity: O(n)
#Space-Complexity: O(1)
def findArray(self, pref: List[int]) -> List[int]:
#Approach: Notice how pref[i] = ans[0] ^ ans[1] ^ ... ^ ans[i]!
#But, pref[i-1] = ans[0] ^ ... ^ ans[i-1]!
#If you notice, ans[0] to ans[i-1] appears two times i... | find-the-original-array-of-prefix-xor | Python3 | Simple Bitwise Manipulation Formula O(N) TIME AND O(1) SPACE! | JOON1234 | 0 | 8 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,287 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2679622/Easy-solution-O(n) | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
n = len(pref)
arr = [0] * n
arr[0] = pref[0]
for i in range(1,n):
arr[i] = pref[i] ^ pref[i-1]
return arr | find-the-original-array-of-prefix-xor | Easy solution O(n) | amishah137 | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,288 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2679415/Python3-Solution-operation-with-adjacent-item.. | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ans = [pref[0]]
i = 1
while i < len(pref):
ans.append(pref[i-1]^pref[i])
i += 1
return ans | find-the-original-array-of-prefix-xor | Python3 Solution - operation with adjacent item.. | sipi09 | 0 | 2 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,289 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2679382/Python-Answer-Simple-XOR | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
sol = [0] * len(pref)
#print(sol)
sol[0] = pref[0]
for i in range(1,len(pref)):
n = pref[i-1]^pref[i]
sol[i] = n
return sol | find-the-original-array-of-prefix-xor | [Python Answerπ€«πππ] Simple XOR | xmky | 0 | 4 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,290 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2679102/Python3-Straightforward-and-Simple | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
answ=[pref[0]]
for i in range(1,len(pref)):
answ.append(pref[i-1]^pref[i])
return answ | find-the-original-array-of-prefix-xor | Python3, Straightforward and Simple | Silvia42 | 0 | 4 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,291 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2678993/Python | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
res = [pref[0]]
hold = res[-1]
for i in range(1, len(pref)):
temp = hold ^ pref[i]
res.append(temp)
hold ^= temp
return res | find-the-original-array-of-prefix-xor | Python | JSTM2022 | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,292 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2678991/Python-Simple-Python-Solution-Using-XOR | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
result = [pref[0]]
for index in range(1,len(pref)):
xor = pref[index - 1]^pref[index]
result.append(xor)
return result | find-the-original-array-of-prefix-xor | [ Python ] β
β
Simple Python Solution Using XOR π₯³βπ | ASHOK_KUMAR_MEGHVANSHI | 0 | 25 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,293 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2678932/Python-easy-solution | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
last = 0
arr = []
for p in pref:
arr.append(last^p)
last ^= (last^p)
return arr | find-the-original-array-of-prefix-xor | Python easy solution | Yihang-- | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,294 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2678899/One-Liner-Simple-XOR-Python-Solution | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
return [pref[0]] + [pref[i]^pref[i-1] for i in range(1,len(pref))] | find-the-original-array-of-prefix-xor | [One Liner] Simple XOR Python Solution | parthberk | 0 | 6 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,295 |
https://leetcode.com/problems/find-the-original-array-of-prefix-xor/discuss/2678882/Python-simple-XOR | class Solution:
def findArray(self, pref: List[int]) -> List[int]:
ans = [pref[0]]
mx = pref[0]
for i in range(1,len(pref)):
a = pref[i]^mx
ans.append(a)
mx = mx^a
return ans | find-the-original-array-of-prefix-xor | Python simple XOR | chandu71202 | 0 | 11 | find the original array of prefix xor | 2,433 | 0.857 | Medium | 33,296 |
https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/discuss/2678810/Counter | class Solution:
def robotWithString(self, s: str) -> str:
cnt, lo, p, t = Counter(s), 'a', [], []
for ch in s:
t += ch
cnt[ch] -= 1
while lo < 'z' and cnt[lo] == 0:
lo = chr(ord(lo) + 1)
while t and t[-1] <= lo:
p += t.p... | using-a-robot-to-print-the-lexicographically-smallest-string | Counter | votrubac | 78 | 3,600 | using a robot to print the lexicographically smallest string | 2,434 | 0.381 | Medium | 33,297 |
https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/discuss/2678792/Python3-Stack-%2B-Counter-O(N)-Clean-and-Concise | class Solution:
def robotWithString(self, s: str) -> str:
dic, t, ans = Counter(s), [], []
for char in s:
t.append(char)
if dic[char] == 1:
del dic[char]
else:
dic[char] -= 1
while dic and t and min(dic) >= t[-1]:
... | using-a-robot-to-print-the-lexicographically-smallest-string | [Python3] Stack + Counter O(N), Clean & Concise | xil899 | 45 | 1,900 | using a robot to print the lexicographically smallest string | 2,434 | 0.381 | Medium | 33,298 |
https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/discuss/2678792/Python3-Stack-%2B-Counter-O(N)-Clean-and-Concise | class Solution:
def deleteString(self, s: str) -> int:
n = len(s)
min_suffix, t, ans = [s[-1]] * n, [], []
for i in range(n - 2, -1, -1):
min_suffix[i] = min(s[i], min_suffix[i + 1])
for i, char in enumerate(s):
t.append(char)
while i + 1 < n and t... | using-a-robot-to-print-the-lexicographically-smallest-string | [Python3] Stack + Counter O(N), Clean & Concise | xil899 | 45 | 1,900 | using a robot to print the lexicographically smallest string | 2,434 | 0.381 | Medium | 33,299 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.