Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: What is the length of the longest strictly increasing contiguous subarray of [3, 4, 5, 1, 2, 3, 4, 5, 6]? Run the code.

Problem: What is the length of the longest strictly increasing contiguous subarray of [3, 4, 5, 1, 2, 3, 4, 5, 6]? Run the code.
a = [3, 4, 5, 1, 2, 3, 4, 5, 6]
best = cur = 1
for i in range(1, len(a)):
    cur = cur + 1 if a[i] > a[i - 1] else 1
    best = max(best, cur)
print(best)
What is printed?
  1. A. 3
  2. B. 6
  3. C. 9
  4. D. 7

Correct answer: B. 6

cur resets at the drop 5 → 1, then the run 1, 2, 3, 4, 5, 6 reaches 6. The first run gives 3, 9 is the whole length, and 7 counts all rising steps rather than a contiguous run.

More Coding Interview Problems questions

Exams that ask this topic