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 j==1: count += matrix1[i][j] if i==2: count += matrix1[i][j] return count def maxSum(self, grid: List[List[int]]) -> int: ans = [] for l in range(len(grid)-2): for k in range(len(grid[l])-2): matrix = [] #creating every possible 3*3 matrix for i in range(l,l+3): row = [] for j in range(k,k+3): row.append(grid[i][j]) matrix.append(row) ans.append(self.gridsSum(matrix)) #calculating the pattern sum for each generated possible matrix and storing it in ans list return max(ans)
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] ans = max(ans, val) return ans
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 currSum = 0 # POINTER top = row bottom = row + 2 for col in range(cols - 2): # LEFT RIGHT POINTER l = col - 1 r = col + 2 m = col + 1 # TOP WINDOW if currTop3Sum == -1: # initially calculate the sum currTop3Sum = sum(grid[top][col:r + 1]) else: # if previous sum is available slide the top window currTop3Sum -= grid[top][l] currTop3Sum += grid[top][r] # BOTTOM WINDOW if currBottom3Sum == -1: # initialy calculate the sum currBottom3Sum = sum(grid[bottom][col:r + 1]) else: # if previous sum is available slide the bottom window currBottom3Sum -= grid[bottom][l] currBottom3Sum += grid[bottom][r] # MID SECTION currMid = grid[top + 1][m] # SUM OUR PART OF HOURGLASS currSum = currTop3Sum + currMid + currBottom3Sum # COMPARE HOURGRLASS WITH SUM maxSum = max(maxSum, currSum) return maxSum
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[i][j+2] + grid[i+1][j+1] + grid[i+2][j] + grid[i+2][j+1] + grid[i+2] [j+2] s = max(s,c) else: continue return s
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(range(1, m - 1), range(1, n - 1)): maxSum = max(maxSum, hourglassSum(i, j)) return maxSum
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&amp;1) num2 = num2 >> 1 # print(nbit1) chk = [] ans = 0 # print(bin(num1), bin(ans)) for i in range(31, -1, -1): biti = (num1>>i)&amp;1 if biti==1 and nbit1>0: num1 = num1 &amp; ~(1<<i) ans = ans | (1<<i) chk.append(i) nbit1 -= 1 # print(bin(num1), bin(ans)) if nbit1>0: for i in range(0, 32, 1): biti = (num1>>i)&amp;1 if i not in chk and nbit1>0: num1 = num1 | (1<<i) ans = ans | (1<<i) nbit1 -= 1 # print(bin(num1), bin(ans)) # print("=" * 20) return ans
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 &amp; 1 num2 = num2 >> 1 num1Str = bin(num1)[2:] num1Len = len(num1Str) outLen = max(num1Len, numBitsToSet) out = ['0' for i in range(outLen)] num1Str = '0'*(outLen-num1Len) + num1Str #print('numBitsToSet', numBitsToSet, 'num1Len', num1Len, 'num1Str', num1Str, 'outLen', outLen) # Match the 1s of num1 for i in range(outLen): if numBitsToSet == 0: break if num1Str[i] == '1': out[i] = '1' numBitsToSet -= 1 # Set minimal bits that are 0 for i in range(outLen-1, -1, -1): if numBitsToSet == 0: break if out[i] == '0': out[i] = '1' numBitsToSet -= 1 #print('Modified out', out) return int(''.join(out), 2)
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_bit = (1 << (len(ones_bin)-1)) if len(ones_bin) > 1 or ones_bin[0] == '1' else 0 # set all ones that are included in num1 so we minimize the xor # as 1^1 = 0 result = 0 for ch in ones_bin: # guard clause if not two_ones: break if ch == '1': result |= highest_bit two_ones -= 1 highest_bit = highest_bit >> 1 # now go through binary one and set the leftover ones comp = 1 while two_ones: if not result&amp;comp: result |= comp two_ones -= 1 comp = comp << 1 return result
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_bin): b_bin = abs(len(b_bin) - len(a_bin)) * ('0') + b_bin zeroes_in_b = len(b_bin) - ones_in_b for i in range(len(a_bin)): if a_bin[i] == '0': if zeroes_in_b > 0: result += '0' zeroes_in_b -= 1 elif ones_in_b > 0: result += '1' ones_in_b -= 1 elif a_bin[i] == '1': if ones_in_b > 0: result += '1' ones_in_b -= 1 elif zeroes_in_b > 0: result += '0' zeroes_in_b -= 1 ans = int(result, 2) return ans
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 &amp; 1: # last bit is 1 n2 += 1 # increase count num2 >>= 1 # shift the binary number to the right # search for indices for 0's and 1's # n = 110 (binary form) => bits1{0: [0], 1: [1, 2]} bits1 = {0: [], 1: []} i = 0 # index from the right side while num1: if num1 &amp; 1: # decide which list to append bits1[1].append(i) else: bits1[0].append(i) i += 1 # increase index num1 >>= 1 # shift the number to the right # list of positions - reversed for 1 (left to right) # straight for 0 (right to left) target_pos = bits1[1][::-1] + bits1[0] # positions for 1 # if we need more 1's to be placed into the target number if len(target_pos) < n2: next_pos = target_pos[0] + 1 # most left position # fill it in with consecutive positions target_pos += list(range(next_pos, next_pos + n2 - len(target_pos))) # cut the list to the required length n2 target_pos = target_pos[:n2] # find the final number by shifting 1's to the target positions # e.g. target = 101 == 100 + 001 in binary return sum(1 << pos for pos in target_pos)
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&amp;1 == 1: c +=1 n = n>>1 return c bits = count_bits(num2) ans = 0 total = 0 if num1 == num2: return num1 for i in range(31,-1,-1): if (num1>>i)&amp;1 == 1: ans +=2**i total+=1 if total == bits: break i = 0 a = ans while total<bits: if a&amp;1 == 0: ans = ans+ (2**i) total +=1 i+=1 a = a>>1 return ans
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 &amp; 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 if num1_bin[i] == "1" and count != 0: ans += "1" count -= 1 else: ans += "0" return int(ans, 2)
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','') x = list('0'*len(s)) one_ix = [i for i in range(len(s)) if s[i]=='1'] if set_bits1<set_bits: left_bits = abs(set_bits-set_bits1) x=list('0'*(left_bits))+list(s) i=0 while left_bits>0: if x[len(x)-1-i]=='0': x[len(x)-1-i]='1' left_bits-=1 i+=1 else: i+=1 x = ''.join(x) elif set_bits1>set_bits: use = one_ix[:set_bits] for i in use: x[i]='1' x = ''.join(x) return(int(x,2))
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: break if bin1[i] == "1": ans[i] = "1" one -= 1 for i in range(len(bin1)-1,-1,-1): if one == 0: break if bin1[i] == "0": ans[i] = "1" one -= 1 for i in range(one): ans.appendleft("1") ans = "".join(ans) return int(ans,2)
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): break for i in range(31, -1, -1): if(setBits == 0): for j in range(i, -1, -1): bits[j] = 0 break elif(bits[i] == 1): setBits -= 1 for i in range(0, 32): if(setBits == 0): break elif(bits[i] == 0): bits[i] = 1 setBits -= 1 res = 0 for i in range(31, -1, -1): res *=2 res += bits[i] return(res)
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 # Adjust 1's Corresponding to 1's in num1 for i in range(32): if lis[i]=='1': ans[i]='1' ones-=1 if not(ones): return int(''.join(ans),2) temp = ans[::-1] # Took reverse so that we can set rightmost bits to one # Set rightmost bits to one for i in range(32): if temp[i]=='0': temp[i]='1' ones-=1 if not(ones): return int(''.join(temp[::-1]),2)
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') ones -= 1 else: ans.append('0') # if remaining ones, replace previous '0' from right to left idx = [i for i in range(len(ans)) if ans[i] == '0'] while ones and idx: ans[idx.pop()] = '1' ones -= 1 # put remaining ones at front ans = ['1'] * ones + ans return int("".join(ans), 2)
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'*(blen-alen)+num2 # keeping count of 1's in x and y for nums1 and nums2 respectively. x=num1.count('1') y=num2.count('1') # case 1 if x==y: return num1 #case 2 if x>y: for i in range(len(num1)): if num1[i]=='1': if y!=0: new_num+='1' y-=1 else: new_num+='0' else: new_num+='0' return int(new_num,2) #case 3 else: new_num=list(num1)[::-1] y-=x for i in range(len(num1)): if new_num[i]!='1' and y>0: new_num[i]='1' y-=1 nn=''.join(new_num[::-1]) return int(nn,2)
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&amp;(1<<i): b -= 1 a ^= 1<<i if b == 0: break #print(a, b) x = 0 while b: while a&amp;(1<<x): x += 1 a ^= 1<<x b -= 1 return a
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]='1' val-=1 if val==0: break if val>0: for i in range(len(arr)-1,-1,-1): if arr[i]=='0': arr[i]='1' val-=1 if val==0: break if val>0: arr+=['1']*val return int(''.join(map(str,arr)),2)
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(format(num1, f'0{M}b')) i = len(result) - 1 count = n2 - n1 while i >= 0 and count: if result[i] == '0': result[i] = '1' count -= 1 i -= 1 return int(''.join(result), 2) else: M = len(f'{num2:b}') result = list(format(num1, f'0{M}b')) i = len(result) - 1 count = n1 - n2 while i >= 0 and count: if result[i] == '1': result[i] = '0' count -= 1 i -= 1 return int(''.join(result), 2)
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 &amp; 1 << i: # use one 1-bit from the bal bal -= 1 res |= 1 << i i -= 1 if bal > 0: # set the rest of bits to `1` res |= (1 << (i + 1)) - 1 return res
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(p-1) m+=2**(p-1) cnt+=1 if cnt==setbit: return m p-=1 # print(m) # print(m) # print(cnt) k=0 while(cnt<setbit): if k not in chk: m+=2**(k) cnt+=1 k+=1 return m
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): if data[i] == 1: if bits: data[i] == 0 bits -= 1 res[i] = 1 else: break if not bits: return int(''.join([str(x) for x in res]), 2) else: for i in range(31, -1, -1): if res[i] != 1: res[i] = 1 bits -= 1 if not bits: return int(''.join([str(x) for x in res]), 2)
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': m.add(len(a) - 1 - i) c-=1 cur = 0 while True: if c == 0: break if not cur in m: m.add(cur) c -= 1 cur += 1 res = 0 for i in m: res += 1 << i return res
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 &amp; 1<<i: ans ^= 1<<i n -= 1 for i in range(30): if not n: break if ans &amp; 1<<i == 0: ans ^= 1<<i n -= 1 return ans
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 if a == b: return num1 print(x,y) x = list(x[::-1]) y = list(y[::-1]) if b > a: d = b-a for i in range(len(x)): if x[i] == "0" and d > 0: x[i] = "1" d -= 1 if d == 0: break x = "".join(x[::-1]) return int(x,2) else: d = a-b for i in range(len(x)): if x[i] == "1" and d > 0: x[i] = "0" d -= 1 if d == 0: break x = "".join(x[::-1]) return int(x,2)
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": ans |= 1 << (len(bin1) - i - 1) bits2 -= 1 if bits2 == 0: return ans for i in range(len(bin1)): if bin1[~i] == "0": ans |= 1 << i bits2 -= 1 if bits2 == 0: return ans
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] = max(dp[i], 1 + dp[i + l]) return dp[0]
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 if s[i : i + l] == s[i + l : i + 2 * l]: dp[i] = max(dp[i], 1 + dp[i + l]) M[i] = max(dp[i], M[i + 1]) return dp[0]
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: ordChar = ord(char.lower()) - ord('a') + 1 s_hash.append( (s_hash[-1] * BASE + ordChar) % MOD ) #caching pow function to reduce the runtime. @functools.lru_cache( maxsize = None) def my_pow( power): return pow( BASE, power, MOD) #get the hash value for substr s. Assuming average constant runtime for my_pow(). @functools.lru_cache( maxsize = None) def get_substr_hash( startIndex, endIndex): #return substr[startIndex: endIndex] hash value. nonlocal s_hash, s if endIndex > len(s): return -1 return (s_hash[endIndex] - s_hash[startIndex] * my_pow( endIndex - startIndex))%MOD #DP bottom-up using recursive function calls. #RUNTIME: O(S**2), SPACE: O(S). S = s.length(), assuming the get_substr_hash() has constant run-time averagely. @functools.lru_cache( maxsize = None) def traverse_str( startIndex = 0): nonlocal s if startIndex >= len(s): return 0 numOps = 1 for midIndex in range( startIndex+1, len(s)): substrLength = midIndex-startIndex #if s[startIndex:startIndex+substrLength] == s[midIndex:midIndex+substrLength]: if get_substr_hash( startIndex, startIndex+substrLength) == get_substr_hash( midIndex, midIndex+substrLength): numOps= max( numOps, 1 + traverse_str( midIndex) ) return numOps maxOps = traverse_str() #cleaning up memory before exit. traverse_str.cache_clear() my_pow.cache_clear() get_substr_hash.cache_clear() return maxOps
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: #print('MEMO found -> memo[s]:', memo[s]) return memo[s] N = len(s) #print('N:', N) if N == 0: #print('Empty string case, s:', s) return 0 if N == 1: # Remove entire string #print('Single char case, s:', s) memo[s] = 1 return 1 c = Counter(s) if c[s[0]] == N: # All chars are same memo[s] = N return N maxToRem = N // 2 #print('maxToRem:', maxToRem) maxSteps = 1 for numToRem in range(maxToRem, 0, -1): if s[:numToRem] == s[numToRem:2*numToRem]: #numCharsToRem,append(numToRem) #print('s:', s, 'numToRem:', numToRem, 'Removing', s[:numToRem]) maxSteps = max(maxSteps, rem(s[numToRem:])+1) memo[s] = maxSteps #print('s:', s, 'memo[s]:', memo[s]) return maxSteps
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, 1 + dfs(s, i + span)) span += 1 return ret ans = dfs(s, 0) dfs.cache_clear() return ans
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] = 1 + eq[i+1][j+1] dp = [0]*n for i in range(n-1, -1, -1): dp[i] = 1 j = 1 while i+2*j <= n: if eq[i][i+j] >= j: dp[i] = max(dp[i], dp[i+j]+1) j += 1 return dp[0]
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]: print((s[i-l+1:i+1], s[i+1:i+1+l]), end = "->") if i-l+1==0: dp[i] = max(dp[i], 1) elif dp[i-l]>0: dp[i] = max(dp[i], dp[i-l] + 1) print(f"(dp[{i-l}]={dp[i-l]})+1={dp[i]}", end=" ") if dp[i]==vmax+1: break vmax = max(vmax, dp[i]) print(f"==> dp[{i}]={dp[i]}, vmax={vmax}") ans = vmax + 1 print("dp:", dp) print("ans:", ans) print("=" * 20, "\n") return ans print = lambda *a, **aa: ()
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): # Base condition: no characters left if i >= n: return 0 ret = 1 # Try every possible candidate and only keep maximum # j = number of characters we'll try to delete # k = new index of s that we want to check the deleting condition with for j in range(1, (n-i)//2+1): k = i+j if s[i:k] == s[k:k+j]: # Check deleting condition ret = max(ret, 1 + helper(k)) # Add 1 to helper(k) because s[i:k] == s[k:k+j] means one delete operation can be performed return ret # Start from index 0 return helper(0)
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:] def helper(i): # Base condition: no characters left if i >= n: return 0 # If memoized already, use that value. if i in memo: return memo[i] ret = 1 # Try every possible candidate and only keep maximum # j = number of characters we'll try to delete # k = new index of s that we want to check the deleting condition with for j in range(1, (n-i)//2+1): k = i+j if s[i:k] == s[k:k+j]: # Check deleting condition ret = max(ret, 1 + helper(k)) # Add 1 to helper(k) because s[i:k] == s[k:k+j] means one delete operation can be performed # Memoize the calculated value memo[i] = ret return ret # Start from index 0 return helper(0)
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] if s[i+k] == s[j]: k += 1 lsp.append(k) if 2*k == j-i+1: dp[i] = max(dp[i], 1+dp[i+k]) return dp[0]
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): if s[i] == s[j]: lp[i][j] = lp[i + 1][j + 1] + 1 res = [1] * n for i in range(n - 2, -1, -1): for j in range(i + 1, n): if j + j - i > n: break if lp[i][j] >= j - i: res[i] = max(res[i], res[j] + 1) return res[0]
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] == string[i:2*i] and self.cache.get(string[i:], 0) < curmax+1: self.cache[string[i:]] = curmax + 1 self.dfs(string[i:], curmax + 1) def deleteString(self, s: str) -> int: if len(set(s)) == 1: return len(s) self.dfs(s, 0) return self.maxop+1
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]: maxOperations = max(maxOperations, dp(i + l)) return maxOperations + 1 return dp()
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): if s[i : i + l] == s[i + l:i + 2 * l]: maxOperations = max(maxOperations, dp(i + l)) return maxOperations + 1 return dp()
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): best_id = emp_id best_time = time start = end return best_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 for i in range(len(times)): if times[i] == max_time: id = min(id, logs[i][0]) return id
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 return ans
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 # ids # store all times appending ids # return max of time units and min of ids in list # time O(n) space O(n) d = defaultdict(list) start = 0 max_val = 0 for log in logs: id, end = log units = end - start max_val = max(max_val, units) start = end d[units].append(id) return min(d[max_val])
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 pre_leave_time = leave_time if worked_time > longest_time: longest_time = worked_time longest_time_id = _id elif worked_time == longest_time and longest_time_id > _id: longest_time_id = _id return longest_time_id
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 employee_id = employee elif interval == largest_interval and employee < employee_id: employee_id = employee last_time = t return employee_id
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 - start_time == res[1]: res = [min(res[0], i), end_time - start_time] start_time = end_time return res[0]
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 longestTime = timeTaken if timeTaken == longestTime: ans = min(emp_id, ans) currTime = leaveTime return ans
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 x=i[1] return s
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 for i in range(len(ans)): if ans[i][1]==maxx: minn=min(minn,ans[i][0]) print(ans) return minn
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 > count : count = time - prev print(ids , time, count) mx = ids if time - prev == count : if ids < mx : mx = ids prev = time return mx
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): best=current bestid=i last=j return bestid
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 result = employee_id elif time_worked == longest: result = min(result, empoyee_id) return result
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 elif leaveTime - prevTime == timeTaken: if id < resId: resId = id prevTime = leaveTime return resId
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 sorted(hm.keys()): if hm[h] == m: return h
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 that worked on longest duration job! In case of a tie, we can #update the person to be one with lowest person_id! #use pre variable to keep track of start time for every current job we process on for loop(make sure it's in #correct state)! pre = 0 ans = None #set longest job duration to default value -1! longest_job_duration = -1 #iterate through each log of task and destructure it! for ID, end_time in logs: job_time = end_time - pre #check if current job's time exceeds longest_job seen so far! if(job_time > longest_job_duration): longest_job_duration = job_time ans = ID #tie-breaker! if(job_time == longest_job_duration): ans = min(ans, ID) #always update end_time of current job to now be start time for next upcoming job! pre = end_time return ans
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, work_done) elif work_done==max_work_obj[1]: max_work_obj = (min(emp_id, max_work_obj[0]), work_done) return max_work_obj[0]
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 maxT==t-T and e<answ: maxT=t-T answ=e return answ
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: current_diff = user_time - last_time if current_diff == max_time: result = min(result, user_id) max_time = current_diff elif current_diff > max_time: if result != user_id: result = user_id else: result = min(result, user_id) max_time = current_diff last_time = user_time return result
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 iterating from 1st index of pref for i in range(1,len(pref)): #store the (last element of storage ^ last element of ans) in variable m m = storage[-1] ^ ans[-1] #now m contains the xor of all elements in ans #now do the xor of (curr element in pref and m) k = m ^ pref[i] #store the k value in ans ans.append(k) #store the m value in storage storage.append(m) #return the list(ans) after finishing for loop return ans
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 ^ ans[-1] k = storage ^ pref[i] ans.append(k) return ans
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 in both pref[i] and pref[i-1]! Thus, we can pair them up by taking #exclusive or between pref[i] and pref[i-1]! We can pair up same terms and exclusive or them, leading to series #of exclusive OR of zeroes -> which results in 0! Then, the only unpaired element is ans[i], which exclusive OR with 0, #retains its original value! Thus, we have formula: ans[i] = pref[i-1] ^ pref[i]! #But, this formula only applies to indices of at least 1 since, pref[0] describes first element of original array! #intialize ans to first element of input pref array since it's a given! ans = [pref[0]] n = len(pref) for i in range(1, n): #use the formula! res = pref[i] ^ pref[i-1] ans.append(res) return ans
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.pop() return "".join(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]: ans += t.pop() ans += t[::-1] return ''.join(ans)
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 and min_suffix[i + 1] >= t[-1]: ans += t.pop() ans += t[::-1] return ''.join(ans)
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