Walmart | OA | Peak and Drop
Anonymous User
611

Dear Leetcode,

Given an array nums = [1,3,2,7] with nums[i]>=0 & nums.length>=3 always.
Peak of i'th element : Any element greater than nums[i] (peak element's index must be greater than i).
Drop of i'th element : Any element less than nums[i]'s peak (drop element's index must be greater than peak's index of nums[i]).

Lets take an example:
For element i=0 :
Peak : 3
Drop: 2
Add {nums[i] , peak , drop} to result.
[1,3,2]

For element i=1;
Peak : 7
Drop : None.
So add {-1,-1,-1} to result.
[-1,-1,-1]

For i=3:
[-1,-1,-1]

For i=4:
[-1,-1,-1]

Ans : [ [1,3,2],[-1,-1,-1],[-1,-1,-1],[-1,-1,-1] ]

Find the peak and drop lists for every i'th element in the array nums & return result list.

Please share your answers :)

Comments (1)