Data Structures & AlgorithmsVery hardProduct placement · Amazon/Microsoft
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 [5, 4, 5, 3, 1, 5, 2, 3, 2, 1, 4, 6] (0 if none)?
- A. 3
- B. 5
- C. 4
- D. 6
Correct answer: C. 4
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 4.
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
- For each day, a monotonic stack finds how many days you must wait for a strictly warmer temperature (0 if never). What is printed? python…
- Count palindromic substrings by expanding around all 2n − 1 centres, and also count DISTINCT palindromic substrings. What is printed?…
- An array holds n distinct elements. What is the minimum number of comparisons that ANY comparison-based algorithm needs, in the worst…
- Shell sort with gap sequence 4, 2, 1 (gapped insertion sort for each gap). What is the array after the gap-4 pass only? python a = [35, 8…
- Keys 107, 29, 82, 81, 18, 115, 85 are inserted in this order into an empty table of size 17 using quadratic probing: probe i goes to (k…
- Keys 80, 25, 99, 55, 30, 13, 57, 42 are inserted in this order into an empty table of size 13 with h(k) = k mod 13 and linear probing…