All Questions
Tagged with dynamic-programming python
114 questions
5
votes
2
answers
176
views
LeetCode Number 416: Partition Equal Subset Sum
Problem: MLE
I am confused as to why the LeetCode judge reports Memory Limit Exceeded when my solution looks close to the editorial solution. I not too familiar with ...
4
votes
1
answer
117
views
Calculate optimal game upgrades, v2
This is the second iteration of the code I originally posted here: Calculate optimal game upgrades. Based on the feedback there, I chose to change the code to use a dynamic programming approach with ...
1
vote
1
answer
106
views
Finding the number of distinct decompositions a number has using only repdigits
This is a problem from a previous semester that I am trying to upsolve. I am trying to solve a problem involving the total number of ways of decomposing a number using only repdigits. A repdigit is a ...
2
votes
1
answer
50
views
Optimal Extraction of Longest Sorted Sequence from Individually Sorted Bucket Arrays Without Repetitions
Consider a bucket array containing sorted and/or empty buckets, and the goal is to extract the longest possible sequence in sorted order, under the following conditions:
Only one element in each ...
6
votes
1
answer
347
views
Codeforces: D2. Counting Is Fun (Hard Version)
The code works okay for the following problem.
Problem
An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
1
vote
1
answer
598
views
Leetcode: 2327. Number of People Aware of a Secret
On day 1, one person discovers a secret.
You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
1
vote
1
answer
163
views
Longest (more or less) ideal subsequence
An ideal subsequence is a subsequence of a string, where the distance between adjacent characters in the subsequence is bounded by a maximum, i.e. \$\lvert c[i] - c[i\pm 1] \rvert \leq k\$
Example:
...
2
votes
2
answers
166
views
Making my DP algorithm faster - longest palindromic substring
The following code is my solution to a LeetCode question - find the longest palindromic substring. My code is 100% correct, it passed once but it took too long, and in most of the reruns I hit a "...
3
votes
1
answer
118
views
Segmentation of list to minimize the largest sum
I have written the following code for diving a list 'seq' into 'k' segments such that the maximum sum of each segment is minimized. I have used dynamic programming to solve this problem. But my class &...
2
votes
1
answer
96
views
Find all non-crossing tuples which has the same content with a given tableau
Let T be a semistandard Young tableau of rectangular shape. For example,
[[1,2,4],[3,5,6]]
is such a tableau, where [1,2,4] and [3,5,6] are columns. All non-...
3
votes
1
answer
271
views
Longest Palindromic Substring | Python Code Giving TLE
Problem Statement
Given a string s , return the longest palindromic substring in s.
Constraints
...
2
votes
1
answer
127
views
Coin partitions
I am looking to obtain the partitions of coins that sum to a target amount
So I tried search online, but every single website loves to use this problem to show the benefits of dynamic programming. ...
5
votes
1
answer
65
views
RodCutting and learning Dynamic Programming
I tried to learn dynamic programming going from recursion to memoized version with the RodCutting problem: Returns the best obtainable price for a rod of length n and price[] as prices of different ...
2
votes
2
answers
2k
views
HackerRank: Sam and substrings | How can dynamic programming be used in my code?
Given a number as a string, no leading zeros, determine the sum of all integer values of substrings of the string.
Given an integer as a string, sum all of its substrings cast as integers. As the ...
1
vote
2
answers
141
views