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/check-array-formation-through-concatenation/discuss/928090/Python3-(Using-Hashmap)
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: #To avoid creating any of the ds or fors if not necessary if not arr and not pieces: return True if not arr or not pieces: return False result = list() ...
check-array-formation-through-concatenation
Python3 (Using Hashmap)
mcl91
1
104
check array formation through concatenation
1,640
0.561
Easy
23,800
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/2698392/python-O(n*n)-solution
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: hash_list = Counter(arr) for i in range(0 , len(pieces)): flag = True start = False k = 0 for j in range(0 , len(arr)): ...
check-array-formation-through-concatenation
python O(n*n) solution
akashp2001
0
4
check array formation through concatenation
1,640
0.561
Easy
23,801
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/2665960/Python3-solution
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: d = defaultdict(list) for piece in pieces: d[piece[0]] = piece i = 0 while i < len(arr): if arr[i] in d: temp = d[arr[i]][1:] ...
check-array-formation-through-concatenation
Python3 solution
mediocre-coder
0
6
check array formation through concatenation
1,640
0.561
Easy
23,802
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/1903856/Python-Solution
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: for piece in pieces: if piece[0] in arr: index = arr.index(piece[0]) if piece != arr[index: index + len(piece)]: return False else: ...
check-array-formation-through-concatenation
Python Solution
hgalytoby
0
76
check array formation through concatenation
1,640
0.561
Easy
23,803
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/1903856/Python-Solution
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: for piece in pieces: if piece[0] in arr: result = False index = 0 for i in range(arr.count(piece[0])): index = arr.index(piece[0], index) ...
check-array-formation-through-concatenation
Python Solution
hgalytoby
0
76
check array formation through concatenation
1,640
0.561
Easy
23,804
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/1796160/5-Lines-Python-Solution-(very-simple)-oror-90-Faster-(40ms)-oror-Memory-less-than-90
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: ans = [] for a in arr: for piece in pieces: if a == piece[0]: ans += piece ; break return ans == arr
check-array-formation-through-concatenation
5-Lines Python Solution (very simple) || 90% Faster (40ms) || Memory less than 90%
Taha-C
0
82
check array formation through concatenation
1,640
0.561
Easy
23,805
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/1569281/Python-Conditional-logic-Easy-to-understand-Beats-80.4
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: # Runtime: 40 ms, faster than 80.48% # Memory Usage: 14.3 MB, less than 34.81% src_len = len(arr) for piece in pieces: # If the first eleme...
check-array-formation-through-concatenation
Python - Conditional logic; Easy to understand; Beats 80.4%
inosuke4
0
67
check array formation through concatenation
1,640
0.561
Easy
23,806
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/1477120/Dictionary-on-pieces-94-speed
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: dict_p = dict() for lst in pieces: dict_p[lst[0]] = lst i, len_arr = 0, len(arr) while i < len_arr: if (arr[i] in dict_p and arr[i: i + len(dict_p[arr[...
check-array-formation-through-concatenation
Dictionary on pieces, 94% speed
EvgenySH
0
136
check array formation through concatenation
1,640
0.561
Easy
23,807
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/1218042/compare-list
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: l=[] for num in arr: i=0 while i <len(pieces): if num==pieces[i][0]: l.extend(pieces[i]) pieces.remove(pieces[i]) ...
check-array-formation-through-concatenation
compare list
janhaviborde23
0
38
check array formation through concatenation
1,640
0.561
Easy
23,808
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/1200518/Python-Simple-Solution-98.3-Faster
class Solution(object): def canFormArray(self, arr, pieces): """ :type arr: List[int] :type pieces: List[List[int]] :rtype: bool """ firstElem = [i[0] for i in pieces] i = 0 while i < len(arr): # print("Start Matching: ",arr[i]) ...
check-array-formation-through-concatenation
Python Simple Solution 98.3 Faster
sunnysharma03
0
136
check array formation through concatenation
1,640
0.561
Easy
23,809
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/997171/Python-99-time-or-List-Slicing-or-Happy-New-Year
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: match = dict() for i in range(len(arr)): match[arr[i]] = i for piece in pieces: if piece[0] not in match: return False start = match[piece[0]] ...
check-array-formation-through-concatenation
[Python] 99% time | List Slicing | Happy New Year
ryandeng32
0
103
check array formation through concatenation
1,640
0.561
Easy
23,810
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/996361/Simple-python-solution-using-hashmap
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: hashmap = dict() for start in pieces: hashmap[start[0]] = start ans = [] for i in arr: ans += hashmap.get(i, []) return ans == arr
check-array-formation-through-concatenation
Simple python solution using hashmap
amoghrajesh1999
0
37
check array formation through concatenation
1,640
0.561
Easy
23,811
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/935217/Intuitive-approach-(recursive-search)
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: # 0) Build search dict # pieces = [[1], [1,2], [2], [2,3]] # head_dict = {1: [[1], [1,2]], 2: [[2], [2,3]]} head_dict = {} for e in pieces: elist = head_dict.get(e[0], []) ...
check-array-formation-through-concatenation
Intuitive approach (recursive search)
puremonkey2001
0
37
check array formation through concatenation
1,640
0.561
Easy
23,812
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/924595/Python3-solution-Beats-100-memory
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: if len(arr) == 0 or len (pieces) == 0: return False p_f = {} for p in pieces: p_f[p[0]] = p flag = False i = 0 while i < len(arr): p...
check-array-formation-through-concatenation
Python3 solution Beats 100 % memory
sgrdswl
0
101
check array formation through concatenation
1,640
0.561
Easy
23,813
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/920748/Python3-recursive-solution-44ms-14.1MB
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: # recursion ends when both arr and pieces become empty if not arr and not pieces: return True # check which pieces can be used as the array's prefix for piece in pieces: if piece == a...
check-array-formation-through-concatenation
Python3 recursive solution, 44ms, 14.1MB
vashik
0
71
check array formation through concatenation
1,640
0.561
Easy
23,814
https://leetcode.com/problems/check-array-formation-through-concatenation/discuss/918562/Python3-Easy-solution-with-replacement-idea
class Solution: def canFormArray(self, arr: List[int], pieces: List[List[int]]) -> bool: joined = "##".join([str(i) for i in arr]) joined = "#" + joined + "#" pieces.sort() for pce in pieces: pJoined = "##".join(str(i) for i in pce) replaceStr = "#" + pJoined ...
check-array-formation-through-concatenation
[Python3] Easy solution with replacement idea
suthagar23
0
114
check array formation through concatenation
1,640
0.561
Easy
23,815
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027288/Python-4-approaches-(DP-Maths)
class Solution: def countVowelStrings(self, n: int) -> int: dp = [[0] * 6 for _ in range(n+1)] for i in range(1, 6): dp[1][i] = i for i in range(2, n+1): dp[i][1]=1 for j in range(2, 6): dp[i][j] = dp[i][j-1] + dp[i-1][j] ...
count-sorted-vowel-strings
✅ Python 4 approaches (DP, Maths)
constantine786
45
3,200
count sorted vowel strings
1,641
0.772
Medium
23,816
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027288/Python-4-approaches-(DP-Maths)
class Solution: def countVowelStrings(self, n: int) -> int: dp = [1] * 5 for i in range(2, n+1): for j in range(4, -1, -1): dp[j] += sum(dp[:j]) return sum(dp)
count-sorted-vowel-strings
✅ Python 4 approaches (DP, Maths)
constantine786
45
3,200
count sorted vowel strings
1,641
0.772
Medium
23,817
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027288/Python-4-approaches-(DP-Maths)
class Solution: def countVowelStrings(self, k: int) -> int: dp = [1] * 5 for _ in range(1, k): for i in range(1, 5): dp[i] = dp[i] + dp[i-1] return sum(dp)
count-sorted-vowel-strings
✅ Python 4 approaches (DP, Maths)
constantine786
45
3,200
count sorted vowel strings
1,641
0.772
Medium
23,818
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027288/Python-4-approaches-(DP-Maths)
class Solution: def countVowelStrings(self, n: int) -> int: return (n + 4) * (n + 3) * (n + 2) * (n + 1) // 24;
count-sorted-vowel-strings
✅ Python 4 approaches (DP, Maths)
constantine786
45
3,200
count sorted vowel strings
1,641
0.772
Medium
23,819
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027288/Python-4-approaches-(DP-Maths)
class Solution: def countVowelStrings(self, n: int) -> int: return math.comb(n + 4, 4)
count-sorted-vowel-strings
✅ Python 4 approaches (DP, Maths)
constantine786
45
3,200
count sorted vowel strings
1,641
0.772
Medium
23,820
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/1146804/Recursion-and-memoization-in-python
class Solution: def countVowelStrings(self, n: int) -> int: def count(n,vow): if vow == 0: mem[n][vow] = 0 return mem[n][vow] if n == 0: mem[n][vow] = 1 return mem[n][vow] if mem[n][vow]!=-1: ...
count-sorted-vowel-strings
Recursion and memoization in python
deleted_user
3
254
count sorted vowel strings
1,641
0.772
Medium
23,821
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2112845/Python-O(1)-one-liner-very-easy
class Solution: def countVowelStrings(self, n: int) -> int: # The formula is (n+5-1)C(n)=(n+4)C(n) return (n+4)*(n+3)*(n+2)*(n+1)//24
count-sorted-vowel-strings
Python O(1) one liner, very easy
pbhuvaneshwar
1
86
count sorted vowel strings
1,641
0.772
Medium
23,822
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2030183/Python-Math
class Solution(object): def countVowelStrings(self, n): """ :type n: int :rtype: int """ if n == 1: return 5 prev = [1, 1, 1, 1, 1] for i in range(n - 1): for j in range(1, len(prev)): prev[j] += prev[j - 1] return ...
count-sorted-vowel-strings
Python Math
Kennyyhhu
1
27
count sorted vowel strings
1,641
0.772
Medium
23,823
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/1381544/Simple-Solution-Python
class Solution: def countVowelStrings(self, n: int) -> int: @lru_cache(None) def factorial(n): return n * factorial(n-1) if n else 1 return factorial(4 + n)//(factorial(4) * factorial(n))
count-sorted-vowel-strings
Simple Solution Python
tenart
1
118
count sorted vowel strings
1,641
0.772
Medium
23,824
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/1381544/Simple-Solution-Python
class Solution: def countVowelStrings(self, n: int) -> int: # factorial(4) == 24 # factorial(n+k)/factorial(n) == (n + 1) * ... * (n + k) return (n + 1) * (n + 2) * (n + 3) * (n + 4) // 24
count-sorted-vowel-strings
Simple Solution Python
tenart
1
118
count sorted vowel strings
1,641
0.772
Medium
23,825
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/957800/Python3-Just-Simple-Math
class Solution: def countVowelStrings(self, n: int) -> int: if n == 1: return 5 cnt = [5, 4, 3, 2, 1] while (n > 2): cnt = [sum(cnt[i:]) for i in range(5)] n -= 1 return sum(cnt)
count-sorted-vowel-strings
[Python3] Just Simple Math
tp99
1
140
count sorted vowel strings
1,641
0.772
Medium
23,826
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/918403/Python3-top-down-dp-and-math
class Solution: def countVowelStrings(self, n: int) -> int: @lru_cache(None) def fn(n, k): """Return number of sorted strings of length n consisting of k vowels.""" if n == 1: return k # base case return sum(fn(n-1, kk) for kk in range(1, k+1)) ...
count-sorted-vowel-strings
[Python3] top-down dp & math
ye15
1
120
count sorted vowel strings
1,641
0.772
Medium
23,827
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/918403/Python3-top-down-dp-and-math
class Solution: def countVowelStrings(self, n: int) -> int: cnt = [1]*5 for _ in range(n-1): for i in range(1, 5): cnt[i] = cnt[i-1] + cnt[i] return sum(cnt)
count-sorted-vowel-strings
[Python3] top-down dp & math
ye15
1
120
count sorted vowel strings
1,641
0.772
Medium
23,828
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/918403/Python3-top-down-dp-and-math
class Solution: def countVowelStrings(self, n: int) -> int: return comb(n+4, 4)
count-sorted-vowel-strings
[Python3] top-down dp & math
ye15
1
120
count sorted vowel strings
1,641
0.772
Medium
23,829
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2721224/just-for-understanding
class Solution: def countVowelStrings(self, n: int) -> int: arr=["a","e","i","o","u"] self.res=0 sub=[] def fun(i): if len(sub.copy())==n: self.res+=1 return if i==len(arr) or len(sub[:])>n: return ...
count-sorted-vowel-strings
just for understanding
hemanth_12
0
1
count sorted vowel strings
1,641
0.772
Medium
23,830
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2697989/Easy-One-Line-Solution-Python
class Solution: def countVowelStrings(self, n: int) -> int: return comb(n+4,4)
count-sorted-vowel-strings
Easy One Line Solution Python
AnandSinhaProjects
0
6
count sorted vowel strings
1,641
0.772
Medium
23,831
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2680133/Python-Solution-using-math-calculation.
class Solution: @lru_cache def countVowelStrings(self, n: int) -> int: if(n == 1): return 5 dp = [[0]*5 for i in range(n)] dp[0] = [5,4,3,2,1] print(dp) for i in range(1,n): for j in range(4,-1,-1): if(j == 4): d...
count-sorted-vowel-strings
Python Solution using math calculation.
user2800NJ
0
5
count sorted vowel strings
1,641
0.772
Medium
23,832
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2588868/Python3-or-DP-Bottom-up
class Solution: def countVowelStrings(self, target_n: int) -> int: memo = {} def countVowel(n, prev_v): if n > target_n: return 0 if n == target_n: return 1 if (n, prev_v) in memo: return memo[(n, prev_v)] ...
count-sorted-vowel-strings
Python3 | DP Bottom up
Ploypaphat
0
34
count sorted vowel strings
1,641
0.772
Medium
23,833
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2581729/Python-easy-solution
class Solution: def countVowelStrings(self, n: int) -> int: d = {'a':1,'e':1,'i':1,'o':1,'u':1} for nn in range(1, n): u = 1 o = u+d['o'] i = o+d['i'] e = i+d['e'] a = e+d['a'] d['a']=a; d['e']=e; d['i']=i; d['o']=o; d['u']=u ...
count-sorted-vowel-strings
Python easy solution
Jack_Chang
0
36
count sorted vowel strings
1,641
0.772
Medium
23,834
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2574418/SIMPLE-PYTHON3-SOLUTION-faster
class Solution: def countVowelStrings(self, n: int) -> int: dp=[[0 for _ in range(5)] for _ in range(n)] for i in range(5): dp[0][i]=1 for i in range(1,n): for j in range(0,5): dp[i][j]=sum(dp[i-1][j:]) return sum(dp[-1])
count-sorted-vowel-strings
✅✔ SIMPLE PYTHON3 SOLUTION ✅✔faster
rajukommula
0
25
count sorted vowel strings
1,641
0.772
Medium
23,835
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2393067/Python-Accurate-Solution-using-Tuples-as-DP-Numbers-oror-Documented
class Solution: def countVowelStrings(self, n: int) -> int: a, e, i, o, u = 1, 1, 1, 1, 1 # dp numbers with initial value of 1 while n > 1: # modify the dp numbers by adding previous values based on rules a, e, i, o, u = (a+e+i+o+u), (e+i+o+u), (i+o+u), (o+u), u ...
count-sorted-vowel-strings
[Python] Accurate Solution using Tuples as DP Numbers || Documented
Buntynara
0
6
count sorted vowel strings
1,641
0.772
Medium
23,836
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2165292/Simple-Python-1-liner-with-builtin-math.comb-method
class Solution: def countVowelStrings(self, n: int) -> int: return math.comb(n + 4, n)
count-sorted-vowel-strings
Simple Python 1 liner with builtin math.comb method
rahulsura
0
40
count sorted vowel strings
1,641
0.772
Medium
23,837
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2029507/Python3-Solution-with-using-dynamic-programming
class Solution: def countVowelStrings(self, n: int) -> int: dp = [[0 for _ in range(5 + 1)] for _ in range(n)] for i in range(len(dp[0]) - 2, -1, -1): dp[0][i] = len(dp[0]) -1 - i for i in range(1, len(dp)): for j in range(len(dp[0]) - 2, -1, -1): ...
count-sorted-vowel-strings
[Python3] Solution with using dynamic programming
maosipov11
0
8
count sorted vowel strings
1,641
0.772
Medium
23,838
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2029353/Simple-Python-Solution-Using-itertools-oror-Explained
class Solution(object): def countVowelStrings(self, n): vowels = 'aeiou' comb = set(itertools.combinations_with_replacement(vowels,n)) return len(comb)
count-sorted-vowel-strings
Simple Python Solution Using itertools || Explained
NathanPaceydev
0
20
count sorted vowel strings
1,641
0.772
Medium
23,839
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2029353/Simple-Python-Solution-Using-itertools-oror-Explained
class Solution(object): def countVowelStrings(self, n): return len(set(itertools.combinations_with_replacement('aeiou',n)))
count-sorted-vowel-strings
Simple Python Solution Using itertools || Explained
NathanPaceydev
0
20
count sorted vowel strings
1,641
0.772
Medium
23,840
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2029244/Count-Sorted-Vowel-Strings
class Solution: def countVowelStrings(self, n: int) -> int: return ((n+4)*(n+3)*(n+2)*(n+1)//24)
count-sorted-vowel-strings
Count Sorted Vowel Strings
im_harshal11
0
14
count sorted vowel strings
1,641
0.772
Medium
23,841
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2028475/Python-Math-One-Line-Solution
class Solution: def countVowelStrings(self, n: int) -> int: return (n + 4) * (n + 3) * (n + 2) * (n + 1) // 24
count-sorted-vowel-strings
[ Python ] Math One Line Solution
crazypuppy
0
13
count sorted vowel strings
1,641
0.772
Medium
23,842
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2028068/python-java-simple-and-small-DP-solution-(commented)
class Solution: def countVowelStrings(self, n: int) -> int: vowels = [1,1,1,1,1] while(True): n -= 1 if n == 0 : return sum(vowels) for i in range(1,5): vowels[i] += vowels[i-1]
count-sorted-vowel-strings
python, java - simple & small DP solution (commented)
ZX007java
0
7
count sorted vowel strings
1,641
0.772
Medium
23,843
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027754/Easy-Python3-Solution
class Solution: def __init__(self): self.vowels = ["a","e","i","o","u"] def countVowelStrings(self, n: int) -> int: self.result = [] for i in range(n): if i==0: self.result = self.vowels else: self.result = [el+res for el in self.v...
count-sorted-vowel-strings
Easy Python3 Solution
yashchandani98
0
6
count sorted vowel strings
1,641
0.772
Medium
23,844
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027600/python-3-oror-one-line-oror-O(1)O(1)
class Solution: def countVowelStrings(self, n: int) -> int: return ((n + 1)*(n + 1)*(n + 2)*(2*n + 3) // 6 + (n + 1)*(n + 1)*(n + 2) // 2 - (n + 1)*(n + 1)*(n + 2)*(n + 2) // 4 + (n + 1)*(n + 2) // 2) // 2
count-sorted-vowel-strings
python 3 || one line || O(1)/O(1)
dereky4
0
25
count sorted vowel strings
1,641
0.772
Medium
23,845
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027390/Python-backtracking.-Slow-but-steady-and-does-the-job-%3A-)
class Solution: def countVowelStrings(self, n: int) -> int: def backtrack(i, v): if i == n: self.result += 1 return for idx in range(v, 5): backtrack(i + 1, idx) self.result = 0 backtrack(0, 0) ...
count-sorted-vowel-strings
Python, backtracking. Slow, but steady and does the job :-)
blue_sky5
0
12
count sorted vowel strings
1,641
0.772
Medium
23,846
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027304/Python-or-Backtrack-or-DP
class Solution: def countVowelStrings(self, n: int) -> int: arr = ['a', 'e', 'i', 'o', 'u'] result = [] candidate = [] count = 0 def backtrack(index, n): nonlocal count if n == 0: count += 1 result....
count-sorted-vowel-strings
Python | Backtrack | DP
Mikey98
0
26
count sorted vowel strings
1,641
0.772
Medium
23,847
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027304/Python-or-Backtrack-or-DP
class Solution: def countVowelStrings(self, n: int) -> int: # dp[i][j] represents total no. of string of length i , starting with characters of column j and after j. # dp[i][j] = dp[i - 1][j] + dp[i][j + 1] dp = [[i for i in range(5,0,-1)] for _ in range(n)] for i i...
count-sorted-vowel-strings
Python | Backtrack | DP
Mikey98
0
26
count sorted vowel strings
1,641
0.772
Medium
23,848
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/2027285/Python-Simple-and-Easy-Solution-oror-O(1)-Time-complexity
class Solution: def countVowelStrings(self, n: int) -> int: return int((n + 4) * (n + 3) * (n + 2) * (n + 1) / 24)
count-sorted-vowel-strings
Python - Simple and Easy Solution || O(1) Time complexity
dayaniravi123
0
27
count sorted vowel strings
1,641
0.772
Medium
23,849
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/1185347/Python-oror-99.43-faster-oror-Simple-Math-formula-oror-Well-Explained
class Solution: def countVowelStrings(self, r: int) -> int: # (n+r-1)!//(n-1!)*(r!) # n=5 and r as parameter num = math.factorial(5+r-1) d1 = 24 # math.fact(4) = 24 d2 = math.factorial(r) den = d1*d2 return num//den
count-sorted-vowel-strings
Python || 99.43% faster || Simple Math formula || Well Explained
abhi9Rai
0
188
count sorted vowel strings
1,641
0.772
Medium
23,850
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/1122374/Python-DP-Solution-or-O(n)-Time-and-Space-asymptotics-or-Faster-than-91.57-solutions
class Solution: def countVowelStrings(self, n: int) -> int: dp = [[0]*5 for _ in range(51)] dp[0] = [1]*5 for i in range(1, 51): c = 0 for j in range(4, -1, -1): c += dp[i-1][j] dp[i][j] = c re...
count-sorted-vowel-strings
[Python] DP Solution | O(n) Time & Space asymptotics | Faster than 91.57% solutions
vvedant99
0
115
count sorted vowel strings
1,641
0.772
Medium
23,851
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/963952/Simple-Python-Recursive-Solution
class Solution(object): def countVowelStrings(self, n, p=0, sumVal=0): if n == 0: return 1 for i in range(p, 5): sumVal += self.countVowelStrings(n-1, i) return sumVal
count-sorted-vowel-strings
Simple Python Recursive Solution
theriley106
0
98
count sorted vowel strings
1,641
0.772
Medium
23,852
https://leetcode.com/problems/count-sorted-vowel-strings/discuss/963952/Simple-Python-Recursive-Solution
class Solution(object): def countVowelStrings(self, n, p=0): if n == 0: return 1 return sum([self.countVowelStrings(n-1, i) for i in range(p, 5)])
count-sorted-vowel-strings
Simple Python Recursive Solution
theriley106
0
98
count sorted vowel strings
1,641
0.772
Medium
23,853
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/2176666/Python-or-Min-Heap-or-With-Explanation-or-Easy-to-Understand
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: # prepare: use a min heap to store each difference(climb) between two contiguous buildings # strategy: use the ladders for the longest climbs and the bricks for the shortest climbs min_...
furthest-building-you-can-reach
Python | Min Heap | With Explanation | Easy to Understand
Mikey98
32
1,800
furthest building you can reach
1,642
0.483
Medium
23,854
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/1881964/Python-easy-to-read-and-understand-or-heap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: pq = [] n = len(heights) for i in range(n-1): diff = heights[i+1] - heights[i] if diff > 0: heapq.heappush(pq, diff) if len(pq) > lad...
furthest-building-you-can-reach
Python easy to read and understand | heap
sanial2001
4
235
furthest building you can reach
1,642
0.483
Medium
23,855
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/918419/Python3-greedy-via-heap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: pq = [] # max heap (priority queue) for i in range(1, len(heights)): ht = heights[i] - heights[i-1] # height diff if ht > 0: heappush(pq, -ht) ...
furthest-building-you-can-reach
[Python3] greedy via heap
ye15
3
181
furthest building you can reach
1,642
0.483
Medium
23,856
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/918419/Python3-greedy-via-heap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: pq = [] for i in range(1, len(heights)): diff = heights[i] - heights[i-1] if diff > 0: heappush(pq, -diff) bricks -= diff if br...
furthest-building-you-can-reach
[Python3] greedy via heap
ye15
3
181
furthest building you can reach
1,642
0.483
Medium
23,857
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/918419/Python3-greedy-via-heap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: pq = [] # min heap for i in range(1, len(heights)): diff = heights[i] - heights[i-1] if diff > 0: heappush(pq, diff) if len(pq) > ladders: ...
furthest-building-you-can-reach
[Python3] greedy via heap
ye15
3
181
furthest building you can reach
1,642
0.483
Medium
23,858
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/2176571/Python-heap.-Time%3A-O(N-log-N)-Space%3A-O(N)
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: idx = 0 h = [] while idx < len(heights) - 1: diff = heights[idx + 1] - heights[idx] if diff <= 0: pass elif diff <= bricks: he...
furthest-building-you-can-reach
Python, heap. Time: O(N log N), Space: O(N)
blue_sky5
1
74
furthest building you can reach
1,642
0.483
Medium
23,859
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/2139261/python-3-oror-simple-min-heap-solution
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: laddersUsed = [] for i in range(len(heights) - 1): diff = heights[i + 1] - heights[i] if diff <= 0: continue heapq.heappush(laddersUsed,...
furthest-building-you-can-reach
python 3 || simple min heap solution
dereky4
1
116
furthest building you can reach
1,642
0.483
Medium
23,860
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/1634796/Python3-O(n)-faster-than-92-Solution-using-a-min-heap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: furthest = 0 q = [] for i in range(1, len(heights)): delta = heights[i] - heights[i-1] if delta > 0: heapq.heappush(q, delta) if ladders =...
furthest-building-you-can-reach
[Python3] [O(n)] [faster than 92%] Solution using a min-heap
lolitsgab
1
149
furthest building you can reach
1,642
0.483
Medium
23,861
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/1179221/PythonPython3-Solution-using-minHeap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: minHeap = [] for i in range(len(heights)-1): buildHeight = heights[i+1]-heights[i] if buildHeight <= 0: continue heappush(minHeap,buildHeight) ...
furthest-building-you-can-reach
Python/Python3 Solution using minHeap
prasanthksp1009
1
115
furthest building you can reach
1,642
0.483
Medium
23,862
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/918653/Python-Binary-Search
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: # return max if we have inf ladders length = len(heights) if ladders == length: return length-1 # # def helper function canIReach(List, l, b): return true if I can, retu...
furthest-building-you-can-reach
Python Binary Search
meiyaowen
1
159
furthest building you can reach
1,642
0.483
Medium
23,863
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/2228568/Python3-Solution-with-using-heap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: heap = [] for i in range(len(heights) - 1): h_diff = heights[i + 1] - heights[i] if h_diff > 0: heapq.heappush(heap, h_diff) ...
furthest-building-you-can-reach
[Python3] Solution with using heap
maosipov11
0
37
furthest building you can reach
1,642
0.483
Medium
23,864
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/2179457/Python-Recursion-%2B-Memoization-%2B-Heap
class Solution: def furthestBuilding(self, heights: list[int], bricks: int, ladders: int) -> int: return self.furthestBuildingHelper(heights, bricks, ladders, 0) # Hypothesis: Function, will always return maximum number of buildings climbed def furthestBuildingHelper(self, heights, bricks, ladders,...
furthest-building-you-can-reach
Python Recursion + Memoization + Heap
zippysphinx
0
61
furthest building you can reach
1,642
0.483
Medium
23,865
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/2179457/Python-Recursion-%2B-Memoization-%2B-Heap
class Solution: def furthestBuilding(self, heights: list[int], bricks: int, ladders: int) -> int: memo = [[[-1 for _ in range(ladders + 1)] for _ in range(bricks + 1)] for _ in range(len(heights) + 1)] return self.furthestBuildingHelper(heights, bricks, ladders, 0, memo) def furthestBuildingHel...
furthest-building-you-can-reach
Python Recursion + Memoization + Heap
zippysphinx
0
61
furthest building you can reach
1,642
0.483
Medium
23,866
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/2179457/Python-Recursion-%2B-Memoization-%2B-Heap
class Solution: def furthestBuilding(self, heights: list[int], bricks: int, ladders: int) -> int: memo = [[-1 for _ in range(ladders + 1)] for _ in range(bricks + 1)] return self.furthestBuildingHelper(heights, bricks, ladders, 0, memo) def furthestBuildingHelper(self, heights, bricks, ladders,...
furthest-building-you-can-reach
Python Recursion + Memoization + Heap
zippysphinx
0
61
furthest building you can reach
1,642
0.483
Medium
23,867
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/1140107/Python-clean-logic-without-heap
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: l=len(heights) l1=[] i=0 while(i<l-1): if(heights[i]>=heights[i+1]): i=i+1 continue else: brea...
furthest-building-you-can-reach
Python clean logic without heap
Rajashekar_Booreddy
0
155
furthest building you can reach
1,642
0.483
Medium
23,868
https://leetcode.com/problems/furthest-building-you-can-reach/discuss/918884/Python-100-speed-100-space-Clean-code-Explanation
class Solution: def furthestBuilding(self, heights: List[int], bricks: int, ladders: int) -> int: s = 0 for i in range(1,len(heights)): if heights[i] > heights[i-1]: s += heights[i] - heights[i-1] # height to be climbed if bricks >= s: ...
furthest-building-you-can-reach
Python [100% speed] [100% space] [Clean code] [Explanation]
mihirrane
-1
111
furthest building you can reach
1,642
0.483
Medium
23,869
https://leetcode.com/problems/kth-smallest-instructions/discuss/918429/Python3-greedy
class Solution: def kthSmallestPath(self, destination: List[int], k: int) -> str: m, n = destination # m "V" &amp; n "H" in total ans = "" while n: kk = comb(m+n-1, n-1) # (m+n-1 choose n-1) instructions starting with "H" if kk >= k: ans += "H" ...
kth-smallest-instructions
[Python3] greedy
ye15
5
286
kth smallest instructions
1,643
0.469
Hard
23,870
https://leetcode.com/problems/kth-smallest-instructions/discuss/2682554/Eay-Python-O(n**2)
class Solution: def kthSmallestPath(self, destination: List[int], k: int) -> str: x,y=destination arr=[[0 for i in range(y+1)] for j in range(x+1)] arr[x][y]=1 for i in range(x,-1,-1): for j in range(y,-1,-1): if i+1<=x: arr[i][j]+=arr...
kth-smallest-instructions
Eay Python O(n**2)
saianirudh_me
0
5
kth smallest instructions
1,643
0.469
Hard
23,871
https://leetcode.com/problems/kth-smallest-instructions/discuss/1965604/Python-solution
class Solution: def kthSmallestPath(self, destination: List[int], k: int) -> str: from math import comb result=[] r=destination[0] c=destination[1] down=r for i in range(r+c): total=r+c-(i+1) step=comb(total,down) if step>=k: ...
kth-smallest-instructions
Python solution
g0urav
0
55
kth smallest instructions
1,643
0.469
Hard
23,872
https://leetcode.com/problems/kth-smallest-instructions/discuss/918667/Python-real-O(M%2BN)
class Solution: def fact(self, n): """factorial with cache""" if n in self.fact_cache: return self.fact_cache[n] x = self.fact(n-1) * n self.fact_cache[n] = x return x def max_k(self, x, y): """number of combinations for ordering x and y identical elements if x ...
kth-smallest-instructions
[Python] real O(M+N)
louis925
0
83
kth smallest instructions
1,643
0.469
Hard
23,873
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1754391/Python-O(1)-solution
class Solution: def getMaximumGenerated(self, n: int) -> int: max_nums = [0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 11, 11, 11, 11, 11, 11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,...
get-maximum-in-generated-array
Python O(1) solution
wssx349
18
510
get maximum in generated array
1,646
0.502
Easy
23,874
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1158473/Python3-simple-solution-best-90-users
class Solution: def getMaximumGenerated(self, n: int) -> int: if n == 0: return 0 elif n == 1: return 1 else: nums = [0,1] for i in range(2,n+1): if i%2 == 0: nums.append(nums[i//2]) else: ...
get-maximum-in-generated-array
Python3 simple solution best 90% users
EklavyaJoshi
2
62
get maximum in generated array
1,646
0.502
Easy
23,875
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2433098/Simple-Python-Solution
class Solution: def getMaximumGenerated(self, n: int) -> int: if n < 2: return n arr = [0]*(n+1) arr[1] = 1 max_num = 0 for i in range(2, n+1): if i%2 == 0: arr[i] = arr[i//2] else: arr[i] = arr[i//2] + arr[i...
get-maximum-in-generated-array
Simple Python Solution
zip_demons
1
90
get maximum in generated array
1,646
0.502
Easy
23,876
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2271104/Solution-(-96.51-Faster)
class Solution: def getMaximumGenerated(self, n: int) -> int: l1 = [0,1] if n == 2 or n == 1: return (1) elif n == 0: return (0) for i in range(1,n): l1.append(l1[i]) if (i * 2) == n: break l1.append((l1[i]) ...
get-maximum-in-generated-array
Solution ( 96.51% Faster)
fiqbal997
1
78
get maximum in generated array
1,646
0.502
Easy
23,877
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1587108/Python-3-O(n)
class Solution: def getMaximumGenerated(self, n: int) -> int: if n <= 1: return n nums = [0, 1] res = 1 for k in range(2, n + 1): if k % 2 == 0: nums.append(nums[k // 2]) else: nums.append(nums[k // 2] + nums[k // 2 ...
get-maximum-in-generated-array
Python 3 O(n)
dereky4
1
118
get maximum in generated array
1,646
0.502
Easy
23,878
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/927516/Python3-create-array-as-told
class Solution: def getMaximumGenerated(self, n: int) -> int: if not n: return 0 # edge case ans = [0, 1] for i in range(2, n+1): ans.append(ans[i>>1] + (ans[i+1>>1] if i&amp;1 else 0)) return max(ans)
get-maximum-in-generated-array
[Python3] create array as told
ye15
1
136
get maximum in generated array
1,646
0.502
Easy
23,879
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/927516/Python3-create-array-as-told
class Solution: def getMaximumGenerated(self, n: int) -> int: @lru_cache(None) def fn(k): """Return kth value.""" if k <= 1: return k if k&amp;1: return fn(k>>1) + fn(k+1>>1) return fn(k>>1) return max(fn(k) for k in range(n+1...
get-maximum-in-generated-array
[Python3] create array as told
ye15
1
136
get maximum in generated array
1,646
0.502
Easy
23,880
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2836329/Python-easy-code-solution-or-For-Beginners
class Solution: def getMaximumGenerated(self, n: int) -> int: nums = [0] * (n+1) if(n == 0): return 0 elif(n == 1): return 1 else: nums[0] = 0 nums[1] = 1 for i in range(1, n+1): if(2 <= 2 * i <= n): ...
get-maximum-in-generated-array
Python easy code solution | For Beginners
anshu71
0
4
get maximum in generated array
1,646
0.502
Easy
23,881
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2779207/Easy-code
class Solution: def getMaximumGenerated(self, n: int) -> int: temp=[] for i in range (0,n+1): if i==0: temp.append(0) elif i==1: temp.append(1) elif i%2==0: temp.append(temp[i//2]) else : ...
get-maximum-in-generated-array
Easy code
nishithakonuganti
0
2
get maximum in generated array
1,646
0.502
Easy
23,882
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2697899/Easy-Solution-using-list-manipulation
class Solution: def getMaximumGenerated(self, n: int) -> int: nums = [0]*(n+2) nums[0] = 0 nums[1] = 1 if n<1: return 0 else: for i in range(2,n+1): if i%2==0: nums[i]=nums[i//2] else: ...
get-maximum-in-generated-array
Easy Solution using list manipulation
AnandSinhaProjects
0
4
get maximum in generated array
1,646
0.502
Easy
23,883
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2561912/EASY-PYTHON3-SOLUTION
class Solution: def getMaximumGenerated(self, n: int) -> int: if n==0 or n==1: return n arr=[0]*(n+1) arr[1]=1 largest=1 for i in range(2,n+1): if i%2==0: arr[i]=arr[i//2] else: arr[i]=arr[i//2]+arr[i//2+1] ...
get-maximum-in-generated-array
✅✔ EASY PYTHON3 SOLUTION
rajukommula
0
36
get maximum in generated array
1,646
0.502
Easy
23,884
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2270136/Get-Max.-in-Gen.-Array-or-Python-3(DP-with-Bottom-Up-Approach)
class Solution: def getMaximumGenerated(self, n: int) -> int: #memoization array w/ bottom-up approach! memo = [0, 1] #base cases! if(n == 0): return 0 if(n == 1): return 1 for a in range(2, n+1): if(a % 2 == 0): ...
get-maximum-in-generated-array
Get Max. in Gen. Array | Python 3(DP with Bottom-Up Approach)
JOON1234
0
20
get maximum in generated array
1,646
0.502
Easy
23,885
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2162198/Dynamic-Programming-oror-Fastest-Optimal-Solution-oror-TC-%3A-O(N)-oror-SC-%3A-O(N)
class Solution: def getMaximumGenerated(self, n: int) -> int: dpArray = [-1]*(n+1) if n <= 1: return n dpArray[0] = 0 dpArray[1] = 1 for i in range(2,n+1): if i%2 == 0: dpArray[i] = dpArray[i//2] else: ...
get-maximum-in-generated-array
Dynamic Programming || Fastest Optimal Solution || TC :- O(N) || SC :- O(N)
Vaibhav7860
0
78
get maximum in generated array
1,646
0.502
Easy
23,886
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/2066657/19ms-100-Faster-(Best)
class Solution: def getMaximumGenerated(self, n: int) -> int: nums = [0] * (n + 1) for i in range(1, n + 1): if i == 1: nums[i] = 1 val = 2 * i if 2 <= val <= n: nums[val] = nums[i] val += 1 if 2 <= val <= n:...
get-maximum-in-generated-array
19ms 100% Faster (Best)
andrewnerdimo
0
39
get maximum in generated array
1,646
0.502
Easy
23,887
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1993210/Python-easy-iterative-solution-for-beginners
class Solution: def getMaximumGenerated(self, n: int) -> int: if n == 0: return 0 if n == 1: return 1 nums = [0] * (n + 1) nums[1] = 1 pos = 1 ind = 2 while ind < n: nums[ind] = nums[pos] ind += 1 num...
get-maximum-in-generated-array
Python easy iterative solution for beginners
alishak1999
0
28
get maximum in generated array
1,646
0.502
Easy
23,888
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1889734/Python
class Solution: def getMaximumGenerated(self, n: int) -> int: if n==0: return 0 nums = [0]*(n+1) nums[1]=1 for i in range(1,n//2+1): nums[2 * i] = nums[i] if 2 * i + 1 <= n: nums[2 * i + 1] = nums[i] + nums[i + 1] return max(nums)
get-maximum-in-generated-array
Python
zouhair11elhadi
0
67
get maximum in generated array
1,646
0.502
Easy
23,889
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1831228/6-Lines-Python-Solution-oror-95-Faster-(28ms)-oror-Memory-less-than-60
class Solution: def getMaximumGenerated(self, n: int) -> int: if n==0: return 0 nums = [0,1] for i in range(2,n+1): if i%2==0: nums.append(nums[i//2]) else: nums.append(nums[i//2]+nums[i//2+1]) return max(nums)
get-maximum-in-generated-array
6-Lines Python Solution || 95% Faster (28ms) || Memory less than 60%
Taha-C
0
52
get maximum in generated array
1,646
0.502
Easy
23,890
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1763902/Python-dollarolution
class Solution: def getMaximumGenerated(self, n: int) -> int: v = [0,1] for i in range(2,n+1,2): v.append(v[i//2]) v.append(v[i//2] + v[i//2+1]) if n%2 ==0: return max(v[:-1]) return max(v)
get-maximum-in-generated-array
Python $olution
AakRay
0
38
get maximum in generated array
1,646
0.502
Easy
23,891
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1759513/Python-Dynamic-Programming-solution-explained
class Solution: def getMaximumGenerated(self, n: int) -> int: # for n in [0, 1]; return early if n < 2: return n # maintain a dp array which will # store the generated array dp = [0] * (n + 1) # initialize the first two elements # dp[0] = 0 i...
get-maximum-in-generated-array
[Python] Dynamic Programming solution explained
buccatini
0
139
get maximum in generated array
1,646
0.502
Easy
23,892
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1632310/C%2B%2B-and-Python-or-0ms-Faster-than-100-or-Simple-and-Readable
class Solution: def getMaximumGenerated(self, n: int) -> int: if n < 2: return n nums = [0, 1] result = -2000 for i in range(2, n + 1): if i % 2 == 0: nums.append(nums[i // 2]) else: nums.append(nums[i // 2] + nums[(i...
get-maximum-in-generated-array
C++ & Python | 0ms Faster than 100% | Simple and Readable
indujashankar
0
84
get maximum in generated array
1,646
0.502
Easy
23,893
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1547294/loop-for-n2-times-only
class Solution: def getMaximumGenerated(self, n: int) -> int: if n == 0: return 0 dp = [0]*(n+1) dp[0], dp[1] = 0, 1 for i in range((n+1)//2): dp[2*i] = dp[i] dp[(2*i)+1] = dp[i] +dp[i+1] return max(dp)
get-maximum-in-generated-array
loop for n//2 times only
siddp6
0
68
get maximum in generated array
1,646
0.502
Easy
23,894
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/1426233/Python3-Simulation-Short-Solution-Faster-Than-85.63
class Solution: def getMaximumGenerated(self, n: int) -> int: nums, i = [0, 1], 1 while len(nums) < n + 1: nums += [nums[i]] nums += [nums[i] + nums[i + 1]] i += 1 return max(nums[:-1]) if n % 2 == 0 else max(nums)
get-maximum-in-generated-array
Python3 Simulation Short Solution, Faster Than 85.63%
Hejita
0
32
get maximum in generated array
1,646
0.502
Easy
23,895
https://leetcode.com/problems/get-maximum-in-generated-array/discuss/943746/Intuitive-approach-by-caching-calculation-result
class Solution: def __init__(self): self.nums = [0, 1] for i in range(2, 101): d, r = divmod(i, 2) if r == 0: self.nums.append(self.nums[d]) else: p = int(i/2) self.nums.append(self.nums[d] + self.nums[d+1]) ...
get-maximum-in-generated-array
Intuitive approach by caching calculation result
puremonkey2001
0
29
get maximum in generated array
1,646
0.502
Easy
23,896
https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/discuss/927527/Python3-most-to-least-frequent-characters
class Solution: def minDeletions(self, s: str) -> int: freq = {} # frequency table for c in s: freq[c] = 1 + freq.get(c, 0) ans = 0 seen = set() for k in sorted(freq.values(), reverse=True): while k in seen: k -= 1 ans ...
minimum-deletions-to-make-character-frequencies-unique
[Python3] most to least frequent characters
ye15
34
4,100
minimum deletions to make character frequencies unique
1,647
0.592
Medium
23,897
https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/discuss/927527/Python3-most-to-least-frequent-characters
class Solution: def minDeletions(self, s: str) -> int: freq = {} # frequency table for c in s: freq[c] = 1 + freq.get(c, 0) ans = 0 seen = set() for k in freq.values(): while k in seen: k -= 1 ans += 1 if k:...
minimum-deletions-to-make-character-frequencies-unique
[Python3] most to least frequent characters
ye15
34
4,100
minimum deletions to make character frequencies unique
1,647
0.592
Medium
23,898
https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/discuss/2207086/Python-Easy-Sorting-approach
class Solution: def minDeletions(self, s: str) -> int: freqs=[0]*26 # capture count of all lowercase characters for c in s: freqs[ord(c)-ord('a')]+=1 freqs.sort(reverse=True) # reverse sort: O(nlogn) deletions=0 #initialize with...
minimum-deletions-to-make-character-frequencies-unique
Python Easy Sorting approach
constantine786
9
848
minimum deletions to make character frequencies unique
1,647
0.592
Medium
23,899