Question 71
HardWhat does the DP for the longest common substring (not subsequence) store in dp[i][j]?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What does the DP for the longest common substring (not subsequence) store in dp[i][j]?
Whether a[i] = b[j]
The length of the common suffix of a[:i] and b[:j], reset to 0 on a mismatch
The edit distance
The LCS length of the prefixes
Sign up free to see the answer and a step-by-step explanation.
What is the recurrence for the number of ways to tile a 2 × n board with 1 × 2 dominoes?
T(n) = 2T(n − 1)
T(n) = n!
T(n) = T(n − 1) + T(n − 2)
T(n) = T(n − 1) + 1
Sign up free to see the answer and a step-by-step explanation.
In the 'house robber' problem on a circle of houses, how is the answer computed?
Take every other house
Solve the line problem twice, once without the first house and once without the last, and take the better
It can't be solved by DP
Solve once for the whole circle
Sign up free to see the answer and a step-by-step explanation.
What is the state for the 'best time to buy and sell stock with at most k transactions' DP?
(day, transactions used, holding or not)
(day) only
(price) only
(transactions) only
Sign up free to see the answer and a step-by-step explanation.
How does the bitmask DP for the travelling salesman problem run?
O(n² 2ⁿ), over states (set of visited cities, current city)
O(2ⁿ) without n
O(n!)
O(n³)
Sign up free to see the answer and a step-by-step explanation.
What is the key difference between DP on a DAG and on a graph with cycles?
There is no difference
A DAG has a topological order, so subproblems can be solved before they are needed; cycles break this
DAGs can't be solved by DP
DP needs cycles
Sign up free to see the answer and a step-by-step explanation.
Which technique reduces the memory of the LCS DP from O(mn) to O(min(m, n)) for the length only?
Using a hash map
Using recursion
Keeping only the previous row
Sorting the strings
Sign up free to see the answer and a step-by-step explanation.
How do top-down (memoised) and bottom-up (tabulated) dynamic programming differ in what they compute?
Top-down never stores results
Top-down computes only the subproblems actually reached; bottom-up usually fills every table entry
Bottom-up needs recursion
They compute different answers
Sign up free to see the answer and a step-by-step explanation.
With coins {1, 5, 6, 8}, what is the minimum number of coins that make 11?
2
1
4
3
Sign up free to see the answer and a step-by-step explanation.
The number of binary strings of length n with no two consecutive 1s is:
F(n + 2), a Fibonacci number
n + 1
n²
2ⁿ
Sign up free to see the answer and a step-by-step explanation.