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/jump-game-iii/discuss/1062049/Weeb-does-Python(bfs) | class Solution:
def canReach(self, arr, start):
queue = deque([start])
visited = set([])
limit = len(arr)
while queue:
for _ in range(len(queue)):
i = queue.popleft()
if i in visited: continue
if arr[i] == 0: return True
visited.add(i)
... | jump-game-iii | Weeb does Python(bfs) | Skywalker5423 | 0 | 75 | jump game iii | 1,306 | 0.631 | Medium | 19,500 |
https://leetcode.com/problems/jump-game-iii/discuss/953186/Simple-DFS-Solution | class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
visited=[0]*len(arr)
def helper(arr, start,i):
if i>=len(arr) or i<0:
return False
if arr[i]==0:
return True
if ... | jump-game-iii | Simple DFS Solution | Ayu-99 | 0 | 51 | jump game iii | 1,306 | 0.631 | Medium | 19,501 |
https://leetcode.com/problems/jump-game-iii/discuss/953046/Intuitive-approach-by-DFS | class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
visisted_pos = set()
dest_pos = set()
# 0) Search destination(s)
for i in range(len(arr)):
if arr[i] == 0:
dest_pos.add(i)
# 1) Short cut for no answe... | jump-game-iii | Intuitive approach by DFS | puremonkey2001 | 0 | 30 | jump game iii | 1,306 | 0.631 | Medium | 19,502 |
https://leetcode.com/problems/jump-game-iii/discuss/948583/Python-Simple-Recursion | class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
visit = [0 for _ in range(len(arr))]
def recursion(arr,start,visit):
if start>=len(arr) or start<0 or visit[start]==True:
return False
if arr[start]==0:
return True
... | jump-game-iii | Python Simple Recursion | bharatgg | 0 | 72 | jump game iii | 1,306 | 0.631 | Medium | 19,503 |
https://leetcode.com/problems/jump-game-iii/discuss/873755/Python3-very-simple-recursion-solution | class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
graph=collections.defaultdict(list)
# create a graph
for i in range(len(arr)):
if i-arr[i]>=0:
graph[i].append(i-arr[i])
if i+arr[i]<len(arr):
graph[i].... | jump-game-iii | Python3 very simple recursion solution | harshitCode13 | 0 | 43 | jump game iii | 1,306 | 0.631 | Medium | 19,504 |
https://leetcode.com/problems/jump-game-iii/discuss/714389/Python3-BFS-Solution | class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
seen = set()
q = deque()
q.append(start)
while q:
curr = q.popleft()
if curr in seen:
continue
seen.add(curr)
if 0 <= curr - arr[curr] < le... | jump-game-iii | Python3 BFS Solution | fuzzywuzzy21 | 0 | 68 | jump game iii | 1,306 | 0.631 | Medium | 19,505 |
https://leetcode.com/problems/jump-game-iii/discuss/694943/Python3-Clean-Concise-and-Easy-Recursive-Solution | class Solution:
def canReach(self, arr: List[int], start: int) -> bool:
def recurse(i):
# check index bounds
if i < 0:
return False
if i > len(arr)-1:
return False
# result will be an infi... | jump-game-iii | [Python3] Clean Concise and Easy Recursive Solution | jonathan | 0 | 49 | jump game iii | 1,306 | 0.631 | Medium | 19,506 |
https://leetcode.com/problems/jump-game-iii/discuss/463952/Python-3-(seven-lines)-(beats-100)-(BFS-Queue-Memo) | class Solution:
def canReach(self, A: List[int], S: int) -> bool:
L, V, C = len(A), set(), collections.deque([S])
while C:
_, i = V.update(C), C.popleft()
if A[i] == 0: return True
if i-A[i] >=0 and i-A[i] not in V: C.append(i-A[i])
if i+A[i] < L and i... | jump-game-iii | Python 3 (seven lines) (beats 100%) (BFS, Queue, Memo) | junaidmansuri | -1 | 131 | jump game iii | 1,306 | 0.631 | Medium | 19,507 |
https://leetcode.com/problems/verbal-arithmetic-puzzle/discuss/1216642/Python3-backtracking | class Solution:
def isSolvable(self, words: List[str], result: str) -> bool:
if max(map(len, words)) > len(result): return False # edge case
words.append(result)
digits = [0]*10
mp = {} # mapping from letter to digit
def fn(i, j, val):
"""Fin... | verbal-arithmetic-puzzle | [Python3] backtracking | ye15 | 4 | 398 | verbal arithmetic puzzle | 1,307 | 0.348 | Hard | 19,508 |
https://leetcode.com/problems/verbal-arithmetic-puzzle/discuss/2547373/Python3-or-Related%3A-Counting-all-possibilities | class Solution:
def isSolvable(self, words: List[str], result: str) -> bool:
# reverse words
words = [i[::-1] for i in words]
result = result[::-1]
allWords = words + [result]
# chars that can not be 0
nonZero = set()
for word in allWords:
... | verbal-arithmetic-puzzle | Python3 | Related: Counting all possibilities | DheerajGadwala | 0 | 344 | verbal arithmetic puzzle | 1,307 | 0.348 | Hard | 19,509 |
https://leetcode.com/problems/verbal-arithmetic-puzzle/discuss/464236/Python-3-(DFS)-(beats-100)-(16-lines) | class Solution:
def isSolvable(self, W: List[str], R: str) -> bool:
LW, LR, F, ML, AW, V, LMap = len(W), len(R), set([w[0] for w in W+[R]]), max(map(len, W+[R])), W+[R], set(), {}
if LR < ML: return False
def dfs(d,i,c):
if d == ML: return c == 0
if i == len(W) + 1:
... | verbal-arithmetic-puzzle | Python 3 (DFS) (beats 100%) (16 lines) | junaidmansuri | -1 | 486 | verbal arithmetic puzzle | 1,307 | 0.348 | Hard | 19,510 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/470770/Python-3-(two-lines)-(beats-100)-(16-ms)-(With-Explanation) | class Solution:
def freqAlphabets(self, s: str) -> str:
for i in range(26,0,-1): s = s.replace(str(i)+'#'*(i>9),chr(96+i))
return s
- Junaid Mansuri
- Chicago, IL | decrypt-string-from-alphabet-to-integer-mapping | Python 3 (two lines) (beats 100%) (16 ms) (With Explanation) | junaidmansuri | 107 | 6,100 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,511 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/491897/Python3-scan-string-backward | class Solution:
def freqAlphabets(self, s: str) -> str:
fn = lambda i: chr(96+int(i)) #convert number to char
ans = []
i = len(s)-1
while i >= 0:
if s[i] == "#":
ans.append(fn(s[i-2:i]))
i -= 3
else:
... | decrypt-string-from-alphabet-to-integer-mapping | [Python3] scan string backward | ye15 | 3 | 197 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,512 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2169355/Python-Simple-Solution | class Solution:
def freqAlphabets(self, s: str) -> str:
d={'1':'a','2':'b','3':'c','4':'d','5':'e','6':'f','7':'g','8':'h','9':'i','10#':'j','11#':'k','12#':'l','13#':'m','14#':'n','15#':'o','16#':'p','17#':'q','18#':'r','19#':'s','20#':'t','21#':'u','22#':'v','23#':'w','24#':'x','25#':'y','26#':'z'}
... | decrypt-string-from-alphabet-to-integer-mapping | Python Simple Solution | pruthashouche | 2 | 88 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,513 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2554688/Decrypt-String-from-Alphabet-to-Integer-Mapping | class Solution:
def freqAlphabets(self, s: str) -> str:
out = []
res=[]
i= 0
while i <len(s)-2:
if s[i+2] == "#":
out.append(s[i:i+2]+"#")
i+=3
else:
out.append(s[i])
i+=1
out.append(s[i... | decrypt-string-from-alphabet-to-integer-mapping | Decrypt String from Alphabet to Integer Mapping | dhananjayaduttmishra | 1 | 17 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,514 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2554688/Decrypt-String-from-Alphabet-to-Integer-Mapping | class Solution:
def freqAlphabets(self, s: str) -> str:
res=[]
i= 0
while i <len(s):
if i + 2 < len(s) and s[i+2] == "#" :
res.append(chr(int(s[i:i + 2]) + 96))
i+=3
else:
res.append(chr(96+int(s[i])))... | decrypt-string-from-alphabet-to-integer-mapping | Decrypt String from Alphabet to Integer Mapping | dhananjayaduttmishra | 1 | 17 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,515 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2456943/Python-Simple-Solution | class Solution:
def freqAlphabets(self, s: str) -> str:
ans = []
for i in range(len(s)):
if s[i] == '#':
del ans[-2:]
ans.append(s[i-2:i])
else:
ans.append(s[i])
return ''.join([chr(int(i)+96) for i in ans]) | decrypt-string-from-alphabet-to-integer-mapping | Python Simple Solution | xinhuangtien | 1 | 90 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,516 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2246455/Python3-simple-solution | class Solution:
def freqAlphabets(self, s: str) -> str:
result = ""
length = len(s)
i = 0
while i < length:
if i < length - 2 and s[i+2] == "#":
result+= chr(96+int(s[i]+s[i+1]))
i+=3
else:
result+=chr(9... | decrypt-string-from-alphabet-to-integer-mapping | 📌 Python3 simple solution | Dark_wolf_jss | 1 | 36 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,517 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1996794/Python-SImple-Logic-or-Easy-Understand | class Solution:
def freqAlphabets(self, s: str) -> str:
i = len(s) -1
ans = ''
while i > -1:
if s[i] == '#':
temp = s[i-2] + s[i-1]
ans = chr(int(temp) + 96) + ans
i -= 3
else:
ans = chr(int(s[i]... | decrypt-string-from-alphabet-to-integer-mapping | [Python] SImple Logic | Easy Understand | jamil117 | 1 | 75 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,518 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1062188/Python3-solution-efficient-O(n)-times-and-easy-to-understand.-Faster-than-96.55-with-runtime-24-ms | class Solution:
def freqAlphabets(self, s: str) -> str:
x=[]
for i in s:
if i!='#':
x.append(chr(int(i)+96))
else:
x.append(chr(int(str(ord(x.pop(-2)) - 96) + str(ord(x.pop(-1)) - 96))+96))
return ''.join(x) | decrypt-string-from-alphabet-to-integer-mapping | Python3 solution efficient O(n) times and easy to understand. Faster than 96.55 % with runtime 24 ms | coderash1998 | 1 | 160 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,519 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/947764/Python-4-lines-solution | class Solution:
def freqAlphabets(self, s: str) -> str:
for i in range(10,27):
s=s.replace(str(i)+'#',chr(96+i))
for i in range(1,10):
s=s.replace(str(i),chr(96+i))
return s | decrypt-string-from-alphabet-to-integer-mapping | Python 4-lines solution | lokeshsenthilkumar | 1 | 291 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,520 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2844882/Python3-Solution-beats-92 | class Solution:
def freqAlphabets(self, s: str) -> str:
i , ans = 0, ""
while i < len(s):
if i + 2 < len(s) and s[i + 2] == "#":
ans += chr(96 + int(s[i:i+2]))
i += 3
else:
ans += chr(96 + int(s[i]))
i += 1
... | decrypt-string-from-alphabet-to-integer-mapping | Python3 Solution - beats 92% | sipi09 | 0 | 1 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,521 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2809599/Decrypt-String-from-alphabet-or-PYTHON | class Solution:
def freqAlphabets(self, s: str) -> str:
return ''.join(chr(int(i[:2]) + 96) for i in re.findall(r'\d\d#|\d', s)) | decrypt-string-from-alphabet-to-integer-mapping | Decrypt String from alphabet | PYTHON | jashii96 | 0 | 3 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,522 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2765167/python-solution-considering-string-as-a-stack | class Solution:
def freqAlphabets(self, s: str) -> str:
alphabet_map = {'1': 'a', '2': 'b', '3': 'c', '4': 'd', '5': 'e', '6': 'f', '7': 'g', '8': 'h', '9': 'i',
'10': 'j', '11': 'k', '12': 'l', '13': 'm', '14': 'n', '15': 'o', '16': 'p', '17': 'q',
'18': 'r', '19': 's', '20'... | decrypt-string-from-alphabet-to-integer-mapping | python solution considering string as a stack | samanehghafouri | 0 | 2 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,523 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2760759/Python3-or-chr-or-map | class Solution:
def freqAlphabets(self, s: str) -> str:
i, n = 0, len(s)
ans = ''
while i < n:
if i < n - 2 and s[i + 2] == '#':
ans += str(chr(int(s[i:i+2]) + 96))
i += 3
else:
ans += str(chr(int(s[i]) + 96))
... | decrypt-string-from-alphabet-to-integer-mapping | Python3 | chr | map | joshua_mur | 0 | 1 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,524 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2608712/An-O(n)-time-and-O(n)-space-approach-without-dictionaries | class Solution:
def freqAlphabets(self, s: str) -> str:
if len(s) == 1:
return chr(int(s) + 96)
result, i = [], len(s) - 1
while i >= 0:
if s[i] == '#':
result.append(chr(int(s[i-2:i]) + 96))
i -= 3
else:
res... | decrypt-string-from-alphabet-to-integer-mapping | An O(n) time and O(n) space approach without dictionaries | kcstar | 0 | 16 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,525 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2585727/Easy-Python-Solution | class Solution:
def freqAlphabets(self, s: str) -> str:
dic = { "1":"a","2":"b","3":"c","4":"d","5":"e","6":"f","7":"g","8":"h","9":"i","10#":"j","11#":"k","12#":"l","13#":"m","14#":"n","15#":"o","16#":"p","17#":"q","18#":"r","19#":"s","20#":"t","21#":"u","22#":"v","23#":"w","24#":"x","25#":"y","26#":"z"
... | decrypt-string-from-alphabet-to-integer-mapping | Easy Python Solution | aniketbhamani | 0 | 26 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,526 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2478901/python3-easy-solution-(loop-dictionary) | class Solution:
def freqAlphabets(self, s: str) -> str:
dct = {'1': 'a', '2': 'b', '3': 'c', '4': 'd', '5': 'e', '6': 'f', '7': 'g', '8': 'h', '9': 'i', '10': 'j', '11': 'k', '12': 'l', '13': 'm', '14': 'n', '15': 'o', '16': 'p', '17': 'q', '18': 'r', '19': 's', '20': 't', '21': 'u', '22': 'v', '23': 'w', '... | decrypt-string-from-alphabet-to-integer-mapping | python3 easy solution (loop, dictionary) | katyasobol | 0 | 37 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,527 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2412747/Simple-and-easy-to-implement-using-Hash | class Solution:
def freqAlphabets(self, s: str) -> str:
dat={}
for x in range(1,10,1):
dat[str(x)]=chr(ord('a')+x-1)
for x in range(10,27):
dat[str(x)+'#']=chr(ord('a')+x-1)
n=len(s)
re=''
x=0
while x<n:
if s[n-x-1]... | decrypt-string-from-alphabet-to-integer-mapping | Simple and easy to implement using Hash | godemode12 | 0 | 41 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,528 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2412458/Python3-Iterative-with-explanation | class Solution:
def freqAlphabets(self, s: str) -> str:
# This will use ASCII to convert numbers to characters
# Uncomment the line below for some useful numbers
# print(ord('a'), ord('z'), ord('z')-ord('a'))
out = []
# Loop through the string
# Rea... | decrypt-string-from-alphabet-to-integer-mapping | [Python3] Iterative with explanation | connorthecrowe | 0 | 49 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,529 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2373202/Python-Easy-solution-best-for-Interview! | class Solution:
def freqAlphabets(self, s: str) -> str:
ans=""
i=0
while i<len(s):
if i+2<len(s) and s[i+2]=="#":
no=(int(s[i])*10)+(int(s[i+1]))
ans+=chr(no+ord("a")-1)
i+=3
else:
ans+=chr(int(s[i])+ord("a")-1)
i+=1
return ans | decrypt-string-from-alphabet-to-integer-mapping | Python - Easy solution best for Interview! | aady_02 | 0 | 60 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,530 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2284083/using-chr-and-traversing-in-reverse-order | class Solution:
def freqAlphabets(self, s: str) -> str:
out = ''
count = len(s) -1
while count >=0:
if s[count] == '#':
out = chr(96 + int(s[count-2:count]) )+ out
count = count - 3
else:
out = chr(96 + int(s[count]) )... | decrypt-string-from-alphabet-to-integer-mapping | using chr and traversing in reverse order | krishnamsgn | 0 | 28 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,531 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2198731/Python-Simple-Python-Solution-Using-Dictionary | class Solution:
def freqAlphabets(self, s: str) -> str:
d = {'1':'a','2':'b','3':'c','4':'d','5':'e',
'6':'f','7':'g','8':'h','9':'i','10#':'j',
'11#':'k','12#':'l','13#':'m','14#':'n',
'15#':'o','16#':'p','17#':'q','18#':'r',
'19#':'s','20#':'t','21#':'u','22#':'v',
'23#':'w','24#':'x','25#':'y... | decrypt-string-from-alphabet-to-integer-mapping | [ Python ] ✅✅ Simple Python Solution Using Dictionary 🥳✌👍 | ASHOK_KUMAR_MEGHVANSHI | 0 | 97 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,532 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2178804/Python-top-90-solution | class Solution:
def freqAlphabets(self, s: str) -> str:
from string import ascii_lowercase as let
let = list(let)
codes = [str(x) for x in range(1,10)]+[str(x)+'#' for x in range(10,27)]
for i in range(9,26):
s = s.replace(codes[i], let[i])
for i in range(9):
... | decrypt-string-from-alphabet-to-integer-mapping | Python top 90 solution | StikS32 | 0 | 46 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,533 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2151668/Use-of-ascii_lowercase-method-Python | class Solution:
def freqAlphabets(self, s: str) -> str:
res = ''
i = 0
while i<len(s):
if '#' in s[i:i+3]:
res +=string.ascii_lowercase[int(s[i:i+2])-1]
i += 3
else:
res +=string.ascii_lowercase[int(s[i:i+1])-1]
... | decrypt-string-from-alphabet-to-integer-mapping | Use of ascii_lowercase method-Python | jayeshvarma | 0 | 23 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,534 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/2004932/Python-Clean-and-Simple! | class Solution:
def freqAlphabets(self, s):
ans, n = "", len(s)
i = 0
while i < n:
if i < n-2 and s[i+2] == "#":
ans += self.convert(s[i:i+2])
i += 3
else:
ans += self.convert(s[i])
i += 1
... | decrypt-string-from-alphabet-to-integer-mapping | Python - Clean and Simple! | domthedeveloper | 0 | 76 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,535 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1990603/Python-or-Easy-to-Understand | class Solution:
def freqAlphabets(self, s: str) -> str:
# traverse from the end to the front
arr = list(s)
n = len(arr)
i = n -1
result = []
while i >= 0:
if arr[i] != '#':
result.append(chr(ord('a') + int(arr[i]) - 1))
... | decrypt-string-from-alphabet-to-integer-mapping | Python | Easy to Understand | Mikey98 | 0 | 53 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,536 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1974407/Easiest-and-Simplest-Approach-or-Python3-Solution-or-100-Faster-or-Using-Dictionary-and-list | class Solution:
def freqAlphabets(self, s: str) -> str:
d={}
temp=[]
ss=""
alpha=ord('a')
for i in range(1,26+1):
if i>9:
d[str(i)+'#']=chr(alpha)
else:
d[str(i)]=chr(alpha)
alpha+=1
for i in s:
... | decrypt-string-from-alphabet-to-integer-mapping | Easiest & Simplest Approach | Python3 Solution | 100% Faster | Using Dictionary and list | RatnaPriya | 0 | 66 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,537 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1870085/Easy-Python-Solution | class Solution:
def freqAlphabets(self, s: str) -> str:
r = ""
i = 0
while i < len(s):
if i+2 < len(s) and s[i+2] == "#":
r = r + chr(int(s[i:i+2])+96)
i = i + 3
else:
r = r + chr(int(s[i])+96)
i = i + 1
... | decrypt-string-from-alphabet-to-integer-mapping | Easy Python Solution | shubhamranjan95 | 0 | 55 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,538 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1835114/ASCII-Python | class Solution:
def freqAlphabets(self, s: str) -> str:
last_digit = 0
n = len(s)
res = ''
while last_digit != n:
if (last_digit + 2 <= n-1) and s[last_digit+2] == "#":
res += chr(int(s[last_digit:last_digit+2])+96)
last_digit = last_digit... | decrypt-string-from-alphabet-to-integer-mapping | ASCII Python | Yihang-- | 0 | 23 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,539 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1766561/Python-3-or-Simple-solution-or-O(n) | class Solution:
def freqAlphabets(self, s: str) -> str:
atoz = "abcdefghijklmnopqrstuvwxyz"
i = 0
resStr = str()
while(i<len(s)):
if "#" in s[i:i+3]:
resStr += (atoz[int(s[i:i+2])-1])
i += 3
continue
resStr += (a... | decrypt-string-from-alphabet-to-integer-mapping | Python 3 | Simple solution | O(n) | Coding_Tan3 | 0 | 54 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,540 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1730016/Python-dollarolution | class Solution:
def freqAlphabets(self, s: str) -> str:
x, i = '', 1
while i < len(s)+1:
if s[-i] != '#':
x = chr(int(s[-i])+96) + x
i += 1
else:
i += 1
x = chr(int(s[-i-1:-i+1])+96) + x
i += 2
... | decrypt-string-from-alphabet-to-integer-mapping | Python $olution | AakRay | 0 | 128 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,541 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1718512/python3-or-regex | class Solution:
def decrypt(self, value: str) -> str:
if len(value) == 3:
value = value[:-1]
return chr(int(value) + 96)
def freqAlphabets(self, s: str) -> str:
words = re.findall("[0-9]{2}#|\d", s)
return "".join(self.decrypt(l) for l in words) | decrypt-string-from-alphabet-to-integer-mapping | python3 | regex | khalidhassan3011 | 0 | 26 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,542 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1601220/Python-3-easy-solution | class Solution:
def freqAlphabets(self, s: str) -> str:
prev2 = prev1 = None
res = ''
for c in s:
if c == '#':
res += chr(int(prev2 + prev1) + 96)
prev1 = prev2 = None
else:
if prev2 is not None:
res ... | decrypt-string-from-alphabet-to-integer-mapping | Python 3 easy solution | dereky4 | 0 | 209 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,543 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1195304/My-clean-python | class Solution:
def freqAlphabets(self, s: str) -> str:
z = ['j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
a = ['X', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
n = s[::-1]
q = ""
while n != "":
if n[0] != "#":
... | decrypt-string-from-alphabet-to-integer-mapping | My clean python | pwily | 0 | 83 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,544 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1137234/Python-Simple-Solution-99.78-faster. | class Solution:
def freqAlphabets(self, s: str) -> str:
import string
l = string.ascii_letters[:26]
ans = ""
i = 0
while i < len(s):
if i+2<len(s) and s[i+2]=='#':
j = s[i] + s[i+1]
ans += l[int(j)-1]
i += 3
... | decrypt-string-from-alphabet-to-integer-mapping | Python Simple Solution 99.78% faster. | g_anes_h | 0 | 151 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,545 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1105074/Python-Easy-understanding-solution-faster-than-96.71-and-lesser-memory-than-98.40 | class Solution:
def freqAlphabets(self, s: str) -> str:
res = ""
letters = "abcdefghijklmnopqrstuvwxyz"
i = 0
while i < len(s):
if i+2 < len(s) and s[i+2] == "#":
res += letters[int(s[i:i+2])-1]
i += 3
else:
res ... | decrypt-string-from-alphabet-to-integer-mapping | [Python] Easy-understanding solution, faster than 96.71% and lesser memory than 98.40% | Pandede | 0 | 187 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,546 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/971620/Python3-or-Faster-than-94-using-dictionary-mapping-of-digits | class Solution:
def freqAlphabets(self, s: str) -> str:
output = ""
if not s:
return output
mapping = {
'1': 'a',
'2': 'b',
'3': 'c',
'4': 'd',
'5': 'e',
'6': 'f',
'7': 'g',
'... | decrypt-string-from-alphabet-to-integer-mapping | Python3 | Faster than 94% using dictionary mapping of digits | sirajali05 | 0 | 157 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,547 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/863569/Python-clear-and-faster-greater95 | class Solution:
def freqAlphabets(self, s: str) -> str:
idx = 0
res = []
while idx < len(s):
if idx+2 < len(s) and s[idx+2] == "#":
res.append( self.num2char( int(s[idx:idx+2]) ) )
idx = idx + 3
else:
res.append( self.n... | decrypt-string-from-alphabet-to-integer-mapping | Python clear and faster >95% | dnstanciu | 0 | 135 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,548 |
https://leetcode.com/problems/decrypt-string-from-alphabet-to-integer-mapping/discuss/1027230/Python3-easy-to-understand-simple-solution | class Solution:
def freqAlphabets(self, s: str) -> str:
x = ''
i = len(s)-1
while i > -1:
if s[i] == '#':
if int(s[i-2:i])%26 == 0:
x = chr(96+26) + x
else:
x = chr(96 + int(s[i-2:i])%26) + x
... | decrypt-string-from-alphabet-to-integer-mapping | Python3 easy to understand simple solution | EklavyaJoshi | -1 | 58 | decrypt string from alphabet to integer mapping | 1,309 | 0.795 | Easy | 19,549 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/470834/Python-3-(two-lines)-(beats-100)-(412-ms) | class Solution:
def xorQueries(self, A: List[int], Q: List[List[int]]) -> List[int]:
B = [A[0]]
for a in A[1:]: B.append(B[-1]^a)
B.append(0)
return [B[L-1]^B[R] for L,R in Q] | xor-queries-of-a-subarray | Python 3 (two lines) (beats 100%) (412 ms) | junaidmansuri | 5 | 639 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,550 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/470834/Python-3-(two-lines)-(beats-100)-(412-ms) | class Solution:
def xorQueries(self, A: List[int], Q: List[List[int]]) -> List[int]:
B = list(itertools.accumulate(A, func = operator.xor)) + [0]
return [B[L-1]^B[R] for L,R in Q]
- Junaid Mansuri
- Chicago, IL | xor-queries-of-a-subarray | Python 3 (two lines) (beats 100%) (412 ms) | junaidmansuri | 5 | 639 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,551 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/491909/Python3-Prefix-XOR | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
prefix = [0] * (len(arr)+1)
for i in range(len(arr)):
prefix[i+1] = prefix[i] ^ arr[i]
return [prefix[lo] ^ prefix[hi+1] for lo, hi in queries] | xor-queries-of-a-subarray | [Python3] Prefix XOR | ye15 | 1 | 197 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,552 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/2721475/Python3-or-Prefix-Xor-Array | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
n=len(arr)
m=len(queries)
prefixXor=[0 for i in range(n)]
ans=[]
for i in range(n):
prefixXor[i]=prefixXor[i-1]^arr[i] if i>=1 else arr[i]
for i in range(m):
... | xor-queries-of-a-subarray | [Python3] | Prefix Xor Array | swapnilsingh421 | 0 | 6 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,553 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/2711407/Simple-Prefix-Xor-Python | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
prefix_xor = [0]
for i in arr:
prefix_xor.append(prefix_xor[-1] ^ i)
res = []
for i, j in queries:
res.append(prefix_xor[i] ^ prefix_xor[j+1])
... | xor-queries-of-a-subarray | Simple Prefix Xor Python | anu1rag | 0 | 2 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,554 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/2705646/python-easy-solution-or-using-bit-manipulation | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
l=[arr[0]]
for i in arr[1:]:
l.append(l[-1]^i)
#print(l)
ans=[]
for i in queries:
if i[0]==0:
ans.append(l[i[1]] )
else:
... | xor-queries-of-a-subarray | python easy solution | using bit manipulation | tush18 | 0 | 6 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,555 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/2683466/Python3-or-Bit-Manipulation-Trick-O(N-%2B-M)-Time-and-O(N)-Space-Solution! | class Solution:
#Let n = len(arr) and m = len(queries)!
#Time-Complexity: O(n + m)
#Space-Complexity: O(n)
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
#Approach: To get prefix exclusive or from L to R indices, you can first get prefix exclusive
#ors from ... | xor-queries-of-a-subarray | Python3 | Bit Manipulation Trick O(N + M) Time and O(N) Space Solution! | JOON1234 | 0 | 89 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,556 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/2669438/Python3-Solution-oror-O(N)-Time-and-O(N)-Space-Complexity | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
xorSum=0
answer=[]
for i in range(len(arr)):
xorSum^=arr[i]
arr[i]=xorSum
for l,r in queries:
if l==0:
answer.append(arr[r])
el... | xor-queries-of-a-subarray | Python3 Solution || O(N) Time & O(N) Space Complexity | akshatkhanna37 | 0 | 6 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,557 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/1625207/Python-Solution-or-Bit-Manipulation-or-TC%3A-O(n)-or-90-Faster | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
#build prefix array
prefix = [0] * len(arr)
prefix[0] = prefix[0] ^ arr[0]
for i in range(1, len(arr)):
prefix[i] = prefix[i-1] ^ arr[i]
result = []
for q... | xor-queries-of-a-subarray | Python Solution | Bit Manipulation | TC: O(n) | 90% Faster | avi-arora | 0 | 75 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,558 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/1606538/Python3-Prefix-XORs-solution | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
for i in range(1, len(arr)):
arr[i] ^= arr[i - 1]
res = []
for x, y in queries:
if x == 0:
res.append(arr[y])
else:
re... | xor-queries-of-a-subarray | [Python3] Prefix XORs solution | maosipov11 | 0 | 44 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,559 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/1292746/Python3-solution-using-dictionary | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
d = {}
z = 0
for i in range(len(arr)):
z ^= arr[i]
d[(0,i)] = z
res = []
for i in queries:
if i[0] == i[1]:
x = arr[i[0]]
... | xor-queries-of-a-subarray | Python3 solution using dictionary | EklavyaJoshi | 0 | 49 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,560 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/1285590/Python-or-Prefix-of-xor-or-o(n)-TC-and-SC | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
prefix_xor = [num for num in arr]
for index in range(1, len(arr)):
prefix_xor[index] ^= prefix_xor[index-1]
# print(prefix_xor)
n = len(queries)
ans = [0]*n
... | xor-queries-of-a-subarray | Python | Prefix of xor | o(n) TC and SC | Sanjaychandak95 | 0 | 72 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,561 |
https://leetcode.com/problems/xor-queries-of-a-subarray/discuss/471428/Python3-simple-solution | class Solution:
def xorQueries(self, arr: List[int], queries: List[List[int]]) -> List[int]:
temp,res = [arr[0]],[]
for i in range(1,len(arr)):
temp.append(temp[i-1]^arr[i])
for query in queries:
a,b=query
if a == 0: res.append(temp[b])
else: res.append(temp[b]^temp[a-1])
return res | xor-queries-of-a-subarray | Python3 simple solution | jb07 | 0 | 80 | xor queries of a subarray | 1,310 | 0.722 | Medium | 19,562 |
https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/491936/Python3-Breadth-first-search | class Solution:
def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:
queue = [id]
count = 0
seen = set(queue)
while queue and count < level: #bfs
count += 1
temp = set()
for i... | get-watched-videos-by-your-friends | [Python3] Breadth-first search | ye15 | 2 | 322 | get watched videos by your friends | 1,311 | 0.459 | Medium | 19,563 |
https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/1431209/Find-friends-of-friends-84-speed | class Solution:
def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:
friends = [set(lst) for lst in friends]
row = friends[id]
previous_friends = {id}
for _ in range(1, level):
previous_friends.updat... | get-watched-videos-by-your-friends | Find friends of friends, 84% speed | EvgenySH | 1 | 106 | get watched videos by your friends | 1,311 | 0.459 | Medium | 19,564 |
https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/470998/Python-3-(six-lines) | class Solution:
def watchedVideosByFriends(self, W: List[List[str]], F: List[List[int]], ID: int, K: int) -> List[str]:
A, V = set(F[ID]), set([ID])
for _ in range(K-1):
A = set(sum([F[a] for a in A],[])) - V - A
V = V.union(A)
C = collections.Counter(sorted(sum([W[a]... | get-watched-videos-by-your-friends | Python 3 (six lines) | junaidmansuri | 1 | 152 | get watched videos by your friends | 1,311 | 0.459 | Medium | 19,565 |
https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/2779957/Python3-or-Dijkstra-%2B-Frequency-Map | class Solution:
def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:
def comparator(a,b):
if a[1] > b[1]:
return 1
elif a[1] < b[1]:
return -1
else:
if... | get-watched-videos-by-your-friends | [Python3] | Dijkstra + Frequency Map | swapnilsingh421 | 0 | 5 | get watched videos by your friends | 1,311 | 0.459 | Medium | 19,566 |
https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/1024878/Self-explainatory-code-no-library-used-PYTHON3 | class Solution:
def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:
friends_already_visited=set()
friends_at_last_level=set([id])
for l in range(0,level):
friends_already_visited.update(list(friends_at_last... | get-watched-videos-by-your-friends | Self explainatory code, no library used [PYTHON3] | v314b0i | 0 | 72 | get watched videos by your friends | 1,311 | 0.459 | Medium | 19,567 |
https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/481168/Python3%3A-280ms-(faster-than-99.6) | class Solution:
def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:
visited = [0] * len(friends)
visited[id] = level + 1
while level > 0:
for i in range(len(visited)):
if visited[i] == level... | get-watched-videos-by-your-friends | Python3: 280ms (faster than 99.6%) | andnik | 0 | 151 | get watched videos by your friends | 1,311 | 0.459 | Medium | 19,568 |
https://leetcode.com/problems/get-watched-videos-by-your-friends/discuss/470909/Python-BFS | class Solution:
def watchedVideosByFriends(self, watchedVideos: List[List[str]], friends: List[List[int]], id: int, level: int) -> List[str]:
graph = collections.defaultdict(list)
for u, v in enumerate(friends):
for i in v:
graph[u].append(i)
queue = collections.d... | get-watched-videos-by-your-friends | Python BFS | aj_to_rescue | 0 | 111 | get watched videos by your friends | 1,311 | 0.459 | Medium | 19,569 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/470856/Python-3-(four-lines)-(DP)-(LCS) | class Solution:
def minInsertions(self, S: str) -> int:
L = len(S)
DP = [[0 for _ in range(L+1)] for _ in range(L+1)]
for i,j in itertools.product(range(L),range(L)): DP[i+1][j+1] = DP[i][j] + 1 if S[i] == S[L-1-j] else max(DP[i][j+1],DP[i+1][j])
return L - DP[-1][-1]
- Junaid ... | minimum-insertion-steps-to-make-a-string-palindrome | Python 3 (four lines) (DP) (LCS) | junaidmansuri | 2 | 537 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,570 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/937752/Python-3-LCS-%2B-LPS. | class Solution:
def minInsertions(self, s: str) -> int:
if s == s[::-1]:
return 0
return len(s) - self.lps(s)
def lps(self,s):
revs = s[::-1]
return self.lcs(s,revs)
def lcs(self,a,b):
n = le... | minimum-insertion-steps-to-make-a-string-palindrome | [Python 3] LCS + LPS. | tilak_ | 1 | 245 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,571 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2815711/PYTHON-DFS-%2B-MEMO-EASY-TO-UNDERSTAND | class Solution:
def minInsertions(self, s: str) -> int:
@cache
def dfs(left,right):
if left >= right:
return 0
# Characters are the same, move both both pointers inwards
if s[left] == s[right]:
return dfs(left+1,right-1)
... | minimum-insertion-steps-to-make-a-string-palindrome | PYTHON DFS + MEMO EASY TO UNDERSTAND | tupsr | 0 | 2 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,572 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2790172/Simple-Python-Solution-or-Top-Down-orDynamic-Programming | class Solution:
def minInsertions(self, s: str) -> int:
w1 = s
m = len(s)
w2 = s[::-1]
n = len(s)
t = [[-1 for i in range(n + 1)] for j in range(m + 1)]
for i in range(m + 1):
for j in range(n + 1):
if i ==0 or j ==0:
t[i][j] = 0
for i in range(1, m + 1):
for j in range(1, n + 1):
... | minimum-insertion-steps-to-make-a-string-palindrome | Simple Python Solution | Top Down |Dynamic Programming | nikhitamore | 0 | 11 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,573 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2759380/Python-Least-Common-Subsequence. | class Solution:
def minInsertions(self, s: str) -> int:
dp = [[0 for _ in range(len(s)+1)] for _ in range(len(s)+1)]
r = s[::-1]
for i in range(1,len(s)+1):
for j in range(1,len(s)+1):
if s[i-1] == r[j-1]:
dp[i][j] = 1+dp[i-1][j-1]
... | minimum-insertion-steps-to-make-a-string-palindrome | Python - Least Common Subsequence. | aryan_codes_here | 0 | 6 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,574 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2664109/Python-by-Reduction-to-LCS-2D-DP-w-Comment | class Solution:
def minInsertions(self, s: str) -> int:
# we only need k insertion for those non-palindrome characters
# where k + len_of_max_palindrome = len(s)
len_of_max_palindrome = self.maxPalinSeq(s)
return len(s) - len_of_max_palindrome
# --... | minimum-insertion-steps-to-make-a-string-palindrome | Python by Reduction to LCS // 2D DP [w/ Comment] | brianchiang_tw | 0 | 28 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,575 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2599461/Python-Easy-Tabular-Method-oror-DP-oror-LCS-Variation | class Solution:
def minInsertions(self, s: str) -> int:
def lcs(x,y,n,m):
dp = [[-1 for _ in range(m+1)] for _ in range(n+1)]
for i in range(n+1):
for j in range(m+1):
if i==0 or j==0:
dp[i][j] = 0
... | minimum-insertion-steps-to-make-a-string-palindrome | Python Easy Tabular Method || DP || LCS Variation | ajinkyabhalerao11 | 0 | 50 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,576 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2592407/Easy-memoization-in-Python | class Solution:
@cache
def dp(self, s, l, r):
if r - l <= 1:
return 0
if s[l] == s[r-1]:
return self.dp(s, l + 1, r - 1)
return min(self.dp(s, l + 1, r), self.dp(s, l, r - 1)) + 1
def minInsertions(self, s: str) -> int:
return self.dp(s, 0, len(s)... | minimum-insertion-steps-to-make-a-string-palindrome | Easy memoization in Python | metaphysicalist | 0 | 60 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,577 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2458672/Python-easy-to-read-and-understand-or-lcs | class Solution:
def lcs(self, x, y, m, n):
if m == 0 or n == 0:
return 0
if x[m-1] == y[n-1]:
return1 + self.lcs(x, y, m-1, n-1)
else:
return max(self.lcs(x, y, m-1, n), self.lcs(x, y, m, n-1))
def minInsertions(self, s: str) -> int:
m, n... | minimum-insertion-steps-to-make-a-string-palindrome | Python easy to read and understand | lcs | sanial2001 | 0 | 68 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,578 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2458672/Python-easy-to-read-and-understand-or-lcs | class Solution:
def lcs(self, x, y, m, n):
if m == 0 or n == 0:
return 0
if (m, n) in self.d:
return self.d[(m, n)]
if x[m-1] == y[n-1]:
self.d[(m, n)] = 1 + self.lcs(x, y, m-1, n-1)
return self.d[(m, n)]
else:
self.d[(m, n)... | minimum-insertion-steps-to-make-a-string-palindrome | Python easy to read and understand | lcs | sanial2001 | 0 | 68 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,579 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2409250/Python-DP-Solution | class Solution:
def minInsertions(self, s: str) -> int:
t = ""
for i in s:
t = i+t
d = {}
if s == t:
return 0
slen = tlen = len(s)
def longestCommonSubSequence(index1, index2):
if index1 < 0 or index2 < 0:
r... | minimum-insertion-steps-to-make-a-string-palindrome | Python DP Solution | DietCoke777 | 0 | 23 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,580 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/2324273/Variation-of-LCS-(4-different-Solutions) | class Solution:
def minInsertions(self, s: str) -> int:
#Tabulation with Optimized Space:
t = s[::-1]
m = len(s)
n = len(t)
prev = [0 for j in range(n+1)]
for indx1 in range(1, m+1):
dp = [0 for j in range(n+1)]
for indx2 in range(1, n... | minimum-insertion-steps-to-make-a-string-palindrome | Variation of LCS (4 different Solutions) | iqti005 | 0 | 16 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,581 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/1791348/easy-way-with-memoization-but-15 | class Solution:
def minInsertions(self, s: str) -> int:
s1=s[::-1]
global table
table=[[-1 for i in range(len(s)+1)] for j in range(len(s)+1)]
def pss(s,s1,m,n):
global table
if m==len(s) or n==len(s):
return 0
if table[m][n]!=-1:
... | minimum-insertion-steps-to-make-a-string-palindrome | easy way with memoization but 15% | lakanavarapu | 0 | 46 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,582 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/1469458/python-3-solution-greater-len(s)-LCS-(-s-reverse-(s)-) | class Solution:
def minInsertions(self, s: str) -> int:
def LCS(x,y):
n=len(x)
m=len(y)
dp=[[-1]*(m+1)for i in range (n+1)]
#printing length of longest common subsequence
for i in range(n+1):
for j in range(m+1):
... | minimum-insertion-steps-to-make-a-string-palindrome | python 3 solution => len(s) - LCS ( s, reverse (s) ) | minato_namikaze | 0 | 115 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,583 |
https://leetcode.com/problems/minimum-insertion-steps-to-make-a-string-palindrome/discuss/549902/Diagonally-filling-the-dp-matrix | class Solution:
def minInsertions(self, s: str) -> int:
n = len(s)
dp = [[0 for i in range(n)] for j in range(n)]
r=0
c=1
while c<n:
ci = c
r = 0
while ci<n and r<n:
if s[ci] == s[r]:
... | minimum-insertion-steps-to-make-a-string-palindrome | Diagonally filling the dp matrix | cursydd | 0 | 171 | minimum insertion steps to make a string palindrome | 1,312 | 0.657 | Hard | 19,584 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/478426/Python-3-(one-line)-(beats-100) | class Solution:
def decompressRLElist(self, N: List[int]) -> List[int]:
L, A = len(N), []
for i in range(0,L,2):
A.extend(N[i]*[N[i+1]])
return A | decompress-run-length-encoded-list | Python 3 (one line) (beats 100%) | junaidmansuri | 23 | 3,400 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,585 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/478426/Python-3-(one-line)-(beats-100) | class Solution:
def decompressRLElist(self, N: List[int]) -> List[int]:
return sum([N[i]*[N[i+1]] for i in range(0,len(N),2)],[])
- Junaid Mansuri
- Chicago, IL | decompress-run-length-encoded-list | Python 3 (one line) (beats 100%) | junaidmansuri | 23 | 3,400 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,586 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2011729/Python-Solution | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
answer = []
for i in range(len(nums)//2):
answer += nums[2*i]*[nums[2*i+1]]
return answer | decompress-run-length-encoded-list | 🔴 Python Solution 🔴 | alekskram | 4 | 167 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,587 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1275371/or-Python-3-or-Easy-or-98.76-faster-solution-or | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
result = []
for i in range(0, len(nums), 2):
n = [nums[i + 1]] * nums[i]
result.extend(n)
return result
# With love for you | decompress-run-length-encoded-list | | Python 3 | Easy | 98.76% faster solution | | anotherprogramer | 3 | 166 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,588 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2745785/Python-Solution-or-Beginners-Friendly-or-Explained | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
res =[]
for i in range(len(nums)//2):
freq,val = nums[2*i] , nums[(2*i)+1]
for j in range(freq+1):
if j >=1 :
res.append(val)
return res | decompress-run-length-encoded-list | Python Solution | Beginners Friendly | Explained | sahil193101 | 2 | 25 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,589 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1759518/1313-Decompress-Run-Length-Encoded-List-python-solution-with-runtime-variance | class Solution(object):
def decompressRLElist(self, nums):
decompressed_list = []
j = 0
for j in range(int(len(nums)/2)):
freq , val = nums[2*j] , nums[2*j+1]
decompressed_list += [val]*freq
return decompressed_list | decompress-run-length-encoded-list | 1313 - Decompress Run Length Encoded List - python solution with runtime variance | ankit61d | 2 | 36 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,590 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2814602/58ms-fastest-python-solution-99.72-fast-and-98.48-memory-efficient | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
k=[]
for i in range(0,int(len(nums)/2)):
k.extend(list((nums[(2*i)+1],))*nums[2*i])
return k | decompress-run-length-encoded-list | 58ms fastest python solution 99.72% fast and 98.48% memory efficient | nandagaonkartik | 1 | 93 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,591 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1866997/Simple-And-Easy-Python-solution | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
result = []
index = 0
while index < len(nums):
frequence = nums[index]
value = nums[index + 1]
result.extend([value] * frequence)
index = index + 2
return result | decompress-run-length-encoded-list | Simple And Easy Python solution | hardik097 | 1 | 42 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,592 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/1372575/Simple-fast-and-easy-to-understand-python-code | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
res = []
for i in range(0, len(nums), 2):
j = i + 1
for x in range(0, nums[i]):
res.append(int(nums[j]))
return res | decompress-run-length-encoded-list | Simple, fast and easy to understand python code | umdowney | 1 | 92 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,593 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/498102/Python3-faster-than-97.12-with-explanation | class Solution(object):
def decompressRLElist(self, nums):
# If an array has only two items
# we just returns an array with second value and multiply it.
if len(nums) == 2:
return [nums[1]] * nums[0]
result = []
# We're iterating over an array
# and checks onl... | decompress-run-length-encoded-list | Python3, faster than 97.12%, with explanation | myusko | 1 | 175 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,594 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2849544/Simple-python3-solution | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
ans = []
st = False
for i,n in enumerate(nums):
if st:
for j in range(nums[i-1]):
ans.append(n)
st=False
else:
st=True
... | decompress-run-length-encoded-list | Simple python3 solution | abelops | 0 | 1 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,595 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2821994/Python3-one-line-beats-97.39 | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
return [x for i in range(1,len(nums),2) for x in [nums[i]] * nums[i-1]] | decompress-run-length-encoded-list | Python3 one line beats 97.39% | hcodecode | 0 | 1 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,596 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2813301/Python3-easy-solution | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
result = []
i = 0
length_nums = len(nums)
while (i+i+1) < length_nums:
result.extend([nums[2*i+1]]*nums[2*i])
i+=1
return result | decompress-run-length-encoded-list | Python3 easy solution | akhilesh1kr | 0 | 2 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,597 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2770563/oror-Python-Easy-solution-oror | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
n = len(nums)
i = 0
ans = []
while i < n:
ans += [nums[i + 1]]*nums[i]
i += 2
return ans | decompress-run-length-encoded-list | 💯 || Python Easy solution || 💯 | parth_panchal_10 | 0 | 4 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,598 |
https://leetcode.com/problems/decompress-run-length-encoded-list/discuss/2715439/Python%2BNumPy | class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
import numpy as np
return np.concatenate([[nums[i]]*nums[i-1] for i, x in enumerate(nums) if i%2==1]) | decompress-run-length-encoded-list | Python+NumPy | Leox2022 | 0 | 1 | decompress run length encoded list | 1,313 | 0.859 | Easy | 19,599 |
Subsets and Splits
Top 2 Solutions by Upvotes
Identifies the top 2 highest upvoted Python solutions for each problem, providing insight into popular approaches.