Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the maximum length of a strictly decreasing subsequence of [9, 4, 6, 3, 8, 1] ? Run the code.

Problem: What is the maximum length of a strictly decreasing subsequence of [9, 4, 6, 3, 8, 1] ? Run the code.
a = [9, 4, 6, 3, 8, 1]
L = [1] * len(a)
for i in range(len(a)):
    for j in range(i):
        if a[j] > a[i]:
            L[i] = max(L[i], L[j] + 1)
print(max(L))
What is printed?
  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 6

Correct answer: A. 4

The decreasing subsequence 9, 6, 3, 1 has length 4, and no longer one exists.

More Coding Interview Problems questions

Exams that ask this topic