Amazon Online Assessment (OA) - Winning Sequence

Given the lower and upper bound of a range of integers, find the largest "mountain array". A mountain array is defined as in the Peak of mountain array problem, i.e. An array that

  • has at least 3 elements
  • let's call the element with the largest value the "peak", with index k. The array elements monotonically increase from the first element to A[k], and then monotonically decreases from A[k + 1] to the last element of the array. Thus creating a "mountain" of numbers.

If more tham one valid mountain arrays can be built from a given range of integers, the largest array is the one with the maximum values starting from the left side. For example, [6, 7, 6, 5] is larger than [5, 6, 7, 5] because first value is larger in the first array.

Return the largest mountain array satisfying the constraints, or -1 if it's not possible.


Example 1:

Input: num = 4, lowerEnd = 3, upperEnd = 10
Output: [9 10 9 8]

Example 2:

Input: num = 5, lowerEnd = 1, upperEnd = 3
Output: [1 2 3 2 1]

Try it yourself




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]

Get premium for instant access to all content and solutions