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?- A. 3
- B. 6
- C. 9
- 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
- Problem: What is the minimum number of cuts needed to partition 'abcde' into palindromes? Run the DP. python s = 'abcde' n = len(s) pal =…
- Problem: How many two-digit numbers have a digit sum that is a prime number? Run the code. python def isp(n): return n > 1 and all(n % d…
- Problem: How many subarrays of [1, 2, 2, 3, 3, 3] have all equal maximum and minimum values? Run the code. python a = [1, 2, 2, 3, 3, 3]…
- Problem: How many integers in [1, 100] have exactly two prime factors counted with multiplicity? Run the code. python def omega(n): c = 0…
- Problem: What is the sum of all proper divisors of 220 (divisors smaller than 220)? Run the code. python print(sum(d for d in range(1…
- Problem: What is the minimum number of coins from {1, 6, 10} that sum to 37? Run the DP. python INF = 10 9 d = [0] + [INF] 37 for v in…