Amazon OA
Anonymous User
1510

Just wanted to share this question here, as I have been benefited a lot from the leetcode comumity in the past few years. However, during the assessment I was unable to come up with an optimal approach unfortunately.


Given a list of integers, count the number of subarrays that either the start and the end of a subarray is the maximum in the subarray

e.g.1
input = [2, 3, 2]
result = 5

Because the subarrays are:
[2],[2,3],
[3],[3,2],
[2]

e.g.2
input = [3, 1, 3, 5]
result = 10

Because the subarrays are:
[3],[3,1],[3,1,3],[3,1,3,5],
[1],[1,3],[1,3,5],
[3],[3,5],
[5]


Role: SDEII
Location: London

Comments (7)