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?- A. 4
- B. 5
- C. 3
- 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
- Problem: How many numbers in [1, 1000] are divisible by 3 and whose digit sum is also divisible by 3? Run the code. python print(sum(1 for…
- Problem: What is the time complexity of finding all prime factors of n up to 10^12 by trial division?
- Problem: Which problem is solved by the 'meet in the middle' technique on a subset-sum instance with n = 40?
- Problem: What does the 'two-phase' Kosaraju algorithm compute?
- Problem: Which best describes the complexity of Dijkstra on a graph with V = 10^5 and E = 10^6 using an array instead of a heap?
- Problem: What is the Stern-Brocot tree's relevance to competitive programming?