Data Structures & AlgorithmsVery hardGATE CS · DSA
A mountain is a contiguous subarray of length ≥ 3 that strictly increases to a single peak and then strictly decreases. What is the length of the longest mountain in [6, 4, 7, 8, 8, 5, 3, 7, 7, 8, 1, 2] (0 if none)?
- A. 5
- B. 2
- C. 3
- D. 4
Correct answer: C. 3
For each peak, extend left while values strictly rise towards it and right while they strictly fall; plateaus break a mountain. The longest has length 3.
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 inversions (pairs i < j with a[i] > a[j]) does [38, 33, 1, 17, 31, 28, 18, 35] have? (This is also the number of swaps bubble…
- What is the worst-case number of comparisons made by binary search (three-way comparison per probe) on a sorted array of 1,000 elements…
- Keys 110, 52, 100, 101, 53, 74, 96 are inserted in this order into an empty table of size 13 using quadratic probing: probe i goes to (k…
- For the binary array [1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1], replace 0 by −1 and use prefix sums with a first-occurrence map. What is the…
- XOR linked list: each node stores link = address(prev) XOR address(next). Which statement is correct?
- Evaluate the postfix expression 1 9 9 ÷ 4 − 7 + − (all divisions are exact). What is its value, and what is the maximum number of operands…