Morgan Stanley | Coding | region of array element- efficient solution??
Anonymous User
497

Given an input array of integers, return a result array of 'region' sizes for each element.
Region of a[i] is max length continuous subarray in which a[i] is equal to the max element
For example a[]={1,2,1}
for a[0], its 1
for a[1], its 3

I wrote a function which used 2 pointers at each element in opposite direction, but got timeout for few test cases...
Is there is a better way to approach this problem??

Comments (4)