dynamic-programming Questions
1
I'm trying to optimize an algorithm that counts permutations with specific constraints. Given integers n, t, a, b where:
n is the length of permutation (1 to n)
t is the required number of fixed p...
Erhard asked 31/10 at 12:15
3
Solved
Context: I'm building a car dealership app using Django 3.1.4, and trying to implement a feature where by every time a new ad is created, so is a new folder (via the upload_to method) within /media...
Wolof asked 5/1, 2021 at 23:56
12
This is the question:
codility.com/programmers/task/number_solitaire
and below link is my result (50% from Codility):
https://codility.com/demo/results/training8AMJZH-RTA/
My code (at the first, ...
Armlet asked 5/12, 2015 at 1:52
8
Solved
I'm trying to find a solution to a codility question on minimum slice of a subarray, and I've devised a solution using a modified version of Kadane's algorithm. I've currently gotten 90/100 and man...
Fillister asked 3/3, 2014 at 3:2
11
Solved
My friend ran into a question in an interview and he was told that there is an O(n) solution. However, neither of us can think it up. Here is the question:
There is a string which contains just ( ...
Menace asked 20/9, 2014 at 19:6
8
This is an interview question. Count all numbers with unique digits (in decimal) in the range [1, N].
The obvious solution is to test each number in the range if its digits are unique. We can also...
Brayton asked 1/3, 2013 at 10:11
5
Solved
To calculate min edit distance (the minimum amount of insertions, deletions and substitutions required to transform one word to another), a dynamic programming solution is based on the recurrence r...
Earsplitting asked 7/3, 2016 at 3:55
6
Solved
I know that Knapsack is NP-complete while it can be solved by DP. They say that the DP solution is pseudo-polynomial, since it is exponential in the "length of input" (i.e. the numbers of bits requ...
Magyar asked 27/12, 2010 at 12:19
2
Solved
You are given a matrix V of dimensions m × n, where each element represents the prices of m different vegetables seeds for n consecutive days in a produce market. Furthermore, you are given an inte...
Mutualize asked 18/9, 2023 at 12:42
3
Solved
Consider a lock, made of a system of wheels. Each wheel has 26 letters of the alphabet, in order, and each wheel is initialized with 'a'. If you move one wheel up, the display for that wheel moves ...
Pungent asked 11/6, 2013 at 20:55
9
Solved
Given an array of integers arr, your task is to count the number of contiguous subarrays that represent a sawtooth sequence of at least two elements.
For arr = [9, 8, 7, 6, 5], the output should be...
Nibelung asked 28/9, 2021 at 5:39
6
Solved
I'm trying to sort any array with array_multisort() and everything is working great. However, based on conditions in my script, I need to change the options.
What I have so far is this:
array_multi...
Odalisque asked 19/3, 2010 at 2:55
3
Someone asked me this question:
You are given a list of intervals. You have to design an algorithm to find the sequence of non-overlapping intervals so that the sum of the range of intervals is max...
Convolve asked 15/8, 2013 at 21:23
11
Solved
Given any number n, and three operations on n:
add 1
subtract 1
divide by 2 if the number is even
I want to find the minimum number of the above operations to reduce n to 1. I have tried dynami...
Single asked 20/9, 2016 at 7:52
5
I am working on a time series data. The data available is multi-variate. So for every instance of time there are three data points available.
Format:
| X | Y | Z |
So one time series data in a...
Ledaledah asked 20/5, 2016 at 14:48
7
Solved
The building bridges problem is stated as follows:
There is a river that runs horizontally through an area. There are a set of cities above and below the river. Each city above the river is matche...
Extrajudicial asked 2/9, 2011 at 19:53
21
Solved
I have a set of integers. I want to find the longest increasing subsequence of that set using dynamic programming.
Recollect asked 13/4, 2010 at 17:26
14
The common substring algorithm :
LCS(x,y) = 1+ LCS(x[0...xi-1],y[0...yj-1] if x[xi]==y[yj]
else 0
Now the Dynamic Programming solution is well understood. However I am unable to figure out the ...
Irrefrangible asked 3/7, 2014 at 6:46
7
Here maximum sum subset is one of k subsets that give maximum sum
e.g: arr = [10,5,3,7] and k = 2
possible ways to divide arr in k subsets is
{10,[5,3,7]},{[10,5],[3,7},{[10,5,3],7}
and
{[10,5],[...
Vineyard asked 24/9, 2016 at 7:47
5
Solved
There are many problems that can be solved using Dynamic programming e.g. Longest increasing subsequence. This problem can be solved by using 2 approaches
Memoization (Top Down) - Using recursion...
Tantalic asked 20/8, 2012 at 17:40
14
Solved
I was given the following problem in an interview:
Given a staircase with N steps, you can go up with 1 or 2 steps each time. Output all possible way you go from bottom to top.
For example:
...
Lilas asked 24/2, 2011 at 1:18
44
This question was asked in the Google programming interview. I thought of two approaches for the same:
Find all the subsequences of length. While doing so compute the sum and of the two elements ...
Naturalism asked 12/7, 2018 at 8:6
6
Is there any way of finding the longest common subsequence of two sequences in O(NlogN) time?
I read somewhere that there is a way to achieve this using binary search.
I know the dp approach th...
Affiche asked 10/6, 2015 at 22:46
6
Solved
I am aware of solutions that uses the bottom up dynamic programing approach to solve this problem in O(n^2). I am specifically looking for a top down dp approach. Is it possible to achieve longest ...
Barracks asked 30/4, 2015 at 4:26
5
Solved
This problem was asked to me in Amazon interview -
Given a array of positive integers, you have to find the smallest positive integer that can not be formed from the sum of numbers from array.
Ex...
Conjunctiva asked 12/1, 2014 at 17:19
1 Next >
© 2022 - 2024 — McMap. All rights reserved.