All Questions
11 questions
-1
votes
1
answer
111
views
LeetCode Climbing Stairs
I tried to separate the climbing scenarios into scenarios of how many 2 steps can be taken and to solve the question according to the sum of the combinations of the moments where 2 steps can be taken ...
1
vote
1
answer
171
views
Recurrence relation for T(n) of Top-Down approach solution of Fibonacci sequence
What is the recurrence for T(n) of this code and the initial conditions of this recurrence? Notice that the code is in python and it is a top-down procedure solution for the Fibonacci sequence 0, 1, 1,...
1
vote
1
answer
180
views
Trouble finding the smallest number of 1's required to represent an integer
I'm doing some programming challenges for fun and I've gotten really stuck on one particular problem regarding how to represent integers using only ones. The question is what is the least number of ...
0
votes
2
answers
2k
views
Leetcode: Stone Game (How can I code it differently)
Problem statement:
Alice and Bob play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].
The objective ...
2
votes
2
answers
785
views
Largest subset from set of numbers (also negative) having sum equal 0
I have a huge set of numbers with a defined order. The logic in simple terms would look like this:
data['values'] = [1,1,3,4,4,-9,10]
data['order'] = [1,2,3,4,5,6,7]
ExpectedSum = 0
What I wish to ...
1
vote
3
answers
3k
views
Given a rod of length N , you need to cut it into R pieces , such that each piece's length is positive, how many ways are there to do so?
Description:
Given two positive integers N and R, how many different ways are there to cut a rod of length N into R pieces, such that the length of each piece is a positive integer? Output this answer ...
0
votes
1
answer
431
views
Is there a DP solution for my subset average problem?
I have a combinatorics problem that I can't solve.
Given a set of vectors and a target vector, return a scalar for each vector, so that the average of the scaled vectors in the set is closest to the ...
2
votes
2
answers
459
views
Given a list of ranges, find all combination for these ranges that sums upto k
I have 34 ranges of numbers.
For example :
x1 = {25,35}
x2 = {28,36}
x3 = {15,20}
.
.
x34 = {28,37}
I have to find all combinations such that i choose a number from every range and all those 34 ...
-1
votes
1
answer
395
views
solve O(n log n) dynamic programming question for max total length of some intervals
N intervals is given. A_i= [S_i, F_i] means start and finishing time of each interval. Start and finishing time of all interval is distinct. we wan to maximize total length of selected intervals that ...
1
vote
3
answers
73
views
Checking if an element is generated in a particular function
I have a function i.e
f(n) = (2* f(n-1)) - (2* f(n-2))
Where f(0)=0 and f(1) = 1
I have a list (num_list). How do I check if the elements of num_list has been generated by the function f(n). Where ...
3
votes
0
answers
305
views
Translating math to Python code
This is part of the Value Iteration algorithm in dynamic programming. The whole code can be found here. And an explanation of the algorithm can be found here
Math notation
Vk[s] = maxa ∑s' P(s'|s,a) ...