Data Structures & AlgorithmsHardAmazon · Microsoft coding round
The array is [3, 3, 4, 4, 5, 1, 2, 2, 6, 3, 7]. What is the length of its longest non-decreasing (not strictly increasing) subsequence?
- A. 5
- B. 6
- C. 8
- D. 7
Correct answer: D. 7
One longest choice is 3, 3, 4, 4, 5, 6, 7 with length 7, while a strict LIS only reaches 5. Duplicates may be reused, so the binary-search method must use upper bound instead of lower bound.
More Coding Interview Problems questions
- For the circular array [5, -3, 5, -2, 6, -8, 4], what is the maximum sum of a non-empty contiguous subarray when the subarray is allowed…
- A robot moves only right or down from the top-left to the bottom-right cell of this 6×6 grid, where # is a blocked cell and . is free…
- For the array [4, 5, 0, -2, -3, 1, 7, -9, 6] and k = 5, how many non-empty contiguous subarrays have a sum divisible by k?
- How many pairs of indices (i, j) with i < j satisfy a[i] > 2·a[j] in a = [5, 2, 6, 1, 7, 3, 9, 2, 4]?
- A walker moves from (0,0) to (4,4) on lattice points using steps (1,0), (0,1) and (1,1). The point (2,2) is forbidden. How many different…
- How many permutations of {1, 2, …, 8} have exactly two fixed points (positions i with π(i) = i)?