Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA
Problem: What is the length of the longest strictly increasing subsequence of the sequence 10, 9, 2, 5, 3, 7, 101, 18, 4, 6, 8, 1, 12?
- A. 6
- B. 12
- C. 3
- D. 5
Correct answer: A. 6
Patience sorting ends with tails [1, 3, 4, 6, 8, 12], so the LIS length is 6 (e.g. 2, 3, 4, 6, 8, 12). Reporting the last tail value gives 12, the longest contiguous increasing run is only 3 (2, 5 or 3, 7, 101), and the longest decreasing subsequence is 5.
More Coding Interview Problems questions
- Problem: Coins of denominations 5, 12 and 20 are available in unlimited supply. What is the minimum number of coins needed to make exactly…
- Problem: The list [25, 14, 9, 31, 7, 18, 3, 12] is turned into a min-heap in place with heapify (standard bottom-up sift-down, 0-indexed)…
- Problem: The sorted array [2, 4, 4, 4, 7, 9, 9, 12] is searched with bisectleft and bisectright. What is bisectright(a, 4) − bisectleft(a…
- Problem: Compute (7^2026 + 11^2026) mod 1000, where ^ is exponentiation.
- Problem: Maximum number of non-overlapping meetings that can be held in one room, where a meeting is an interval [start, end) and two…
- Problem: How many contiguous subarrays of [3, -1, 4, -2, 5, -6, 2, 1] have sum at most 6 when the sum is computed over all non-empty…