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/number-of-beautiful-partitions/discuss/2846874/Python-oror-DP%2BMemoization-oror-Explained
class Solution: def beautifulPartitions(self, s: str, k: int, min_len: int) -> int: n=len(s) mod=10**9+7 prime=set(['2','3','5','7']) if s[0] not in prime or s[-1] in prime: return 0 arr=[] last,i=0,1 while i<n: if (i==n-1) or (s[i] not in prime an...
number-of-beautiful-partitions
Python || DP+Memoization || Explained
ketan_raut
0
5
number of beautiful partitions
2,478
0.294
Hard
34,000
https://leetcode.com/problems/number-of-beautiful-partitions/discuss/2835340/My-Python3-solution
class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: n, primes, mod = len(s), set('2357'), (10 ** 9) + 7 @cache def dp(i, at_start, k): if i == n: return int(k == 0) if i > n or k == 0 or s[i] not in primes and at_start: return 0 ...
number-of-beautiful-partitions
My Python3 solution
Chiki1601
0
7
number of beautiful partitions
2,478
0.294
Hard
34,001
https://leetcode.com/problems/number-of-beautiful-partitions/discuss/2834324/Python3-bottom-up-dp
class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: prime = "2357" dp = [[0]*(len(s)+1) for _ in range(k)] if s[0] in prime and s[-1] not in prime: for j in range(len(s)+1): dp[0][j] = 1 for i in range(1, k): for j i...
number-of-beautiful-partitions
[Python3] bottom-up dp
ye15
0
14
number of beautiful partitions
2,478
0.294
Hard
34,002
https://leetcode.com/problems/number-of-beautiful-partitions/discuss/2832507/Over-optimized-O(nk)-dp-solution-~400-ms
class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: mod = 10 ** 9 + 7 n = len(s) prime = {'2', '3', '5', '7'} if s[0] in prime and s[-1] not in prime: op = [] for i in range(1, n - 1): if s[i] not in prime and ...
number-of-beautiful-partitions
Over-optimized O(nk) dp solution, ~400 ms
chuan-chih
0
21
number of beautiful partitions
2,478
0.294
Hard
34,003
https://leetcode.com/problems/number-of-beautiful-partitions/discuss/2832418/python3-DP-%2B-accumulative-sum-O(n*k)
class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: primes = {'2','3','5','7'} # prunning if len(s) < k*minLength or s[0] not in primes or s[-1] in primes: return 0 dd_int = functools.partial(defaultdict, int) dp = defaultdict(dd...
number-of-beautiful-partitions
[python3] DP + accumulative sum O(n*k)
hieuvpm
0
18
number of beautiful partitions
2,478
0.294
Hard
34,004
https://leetcode.com/problems/number-of-beautiful-partitions/discuss/2832064/O(nk)-time-complexity-O(n)-space-complexity-DP
class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: n = len(s) mod = 10 ** 9 + 7 if k * minLength > n: return 0 dp = [[0] * (2) for _ in range(n+1)] dp[0][0] = 1 prime_indices = [i + 1 for i in range(n) if s[i] in '2357'...
number-of-beautiful-partitions
O(nk) time complexity, O(n) space complexity DP
zhanghaotian19
0
20
number of beautiful partitions
2,478
0.294
Hard
34,005
https://leetcode.com/problems/number-of-beautiful-partitions/discuss/2831967/Fastest-Python-solution-so-far
class Solution: def beautifulPartitions(self, s: str, k: int, minLength: int) -> int: s=list(s) l0=len(s) prime={'2', '3', '5', '7'} for i in range(l0): s[i]=s[i] in prime if not s[0]: return 0 if s[-1]: return 0 p=10**9+7 ...
number-of-beautiful-partitions
Fastest Python solution so far
mbeceanu
0
40
number of beautiful partitions
2,478
0.294
Hard
34,006