Data Structures & AlgorithmsHard
What is the length of the longest contiguous subarray of 1 3 5 4 2 6 8 7 3 1 that is bitonic, meaning it strictly increases up to one peak and then strictly decreases (a purely increasing or purely decreasing block is not bitonic)?
- A. 3
- B. 6
- C. 4
- D. 7
Correct answer: B. 6
Scan with two states, rising then falling; a bitonic block has a single peak strictly inside it. Pure increasing or decreasing runs are excluded by the requirement of both phases.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many contiguous subarrays of 2 1 4 7 3 2 5 3 1 are mountains? A mountain has length at least 3, strictly increases to a single peak…
- In the sorted array 1 3 4 7 9 12 14, how many index pairs i < j satisfy A[j] − A[i] ≥ 5?
- Count the CIRCULAR descents of 3 4 5 1 2: positions i (0 ≤ i < n) where A[i] > A[(i+1) mod n], with the last element compared to the…
- How many contiguous subarrays of 1 2 1 1 3 1 2 have a STRICT majority element, meaning some value occurs more than half the time in the…
- How many index pairs i < j in 0 1 2 2 3 4 0 satisfy A[i]·A[j] = A[i] + A[j]?
- How many contiguous subarrays of 3 1 2 2 4 3 5 consist of consecutive integers (their values, in some order, are k, k+1, …, k+L−1 with no…