Data Structures & AlgorithmsHardCodeforces Div2 B · DP warm-up
Problem: What is the time complexity of computing the longest increasing subsequence using patience-sorting with binary search, versus the naive O(n^2) DP?
- A. O(n log n) with binary search over the 'tails' array, versus O(n^2) for the naive DP
- B. Both are O(n^2)
- C. O(n) with binary search, O(n log n) for the DP
- D. O(log n) with binary search, O(n) for the DP
Correct answer: A. O(n log n) with binary search over the 'tails' array, versus O(n^2) for the naive DP
Maintaining the smallest possible tail value for each achievable subsequence length and binary-searching where a new element fits brings the naive O(n^2) DP down to O(n log n).
More Coding Interview Problems questions
- Problem: The longest common subsequence (LCS) of two strings of length n and m is typically solved with which approach and complexity?
- Problem: Subset-sum (does any subset of n integers sum exactly to a target T?) has a DP solution running in O(nT). Why is this not…
- Problem: What is the average-case and worst-case time complexity of the quickselect algorithm for finding the k-th smallest element?
- Problem: Which of these sorting algorithms is guaranteed O(n log n) in the worst case AND is stable (preserves the relative order of equal…
- Problem: Counting sort can sort n integers in the range [0, k] in O(n + k) time. What is the key limitation that makes it unsuitable for…
- Problem: A trie (prefix tree) storing n words with total length L supports which operation's time complexity most efficiently?