Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
What is the length of the longest run of equal consecutive values in [4, 4, 1, 2, 2, 2, 5, 1]?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
Track the current run length and reset it when the value changes; the longest run is 2, 2, 2 which has length 3. Counting distinct values gives a different quantity.
More Coding Interview Problems questions
- Problem: Two sorted arrays of sizes m and n are merged in O(m + n) time with two pointers. What is the complexity of finding the median of…
- Array a = [3, 2, 5, 1, 4, 6, 2, 7]. Consider all contiguous subarrays and count those whose sum is a power of two from the set {1, 2, 4…
- Array a = [4, 7, 1, 8, 3, 6, 5, 2]. What is the largest sum of a contiguous subarray that contains exactly two odd numbers?
- Array a = [2, 5, 1, 6, 3, 8, 4]. How many ordered pairs of distinct positions (i, j) satisfy a[j] >= 2 a[i]?
- From the values [4, 9, 1, 12, 7, 3, 10, 6], keep as many as possible so that in the kept set the maximum is at most twice the minimum. How…
- Seven people weigh [3, 5, 3, 4, 2, 6, 1] (kg). A boat carries at most two people and at most 7 kg in total. What is the minimum number of…