Got a wrong answer

Below is my code and according to me i have done everything accordingly ans longest area should be covered . Can you please tell me my mistake . https://ide.codingblocks.com/s/372679

please explain your approach once
also take into consideration the long constraints which will fail your code

i’m making an array of next smallest element in right and next smallest element in left . After finding both for each elements in an array , I store finded elements index . After that i find the maximum area as if next smallest elemet will be shorter then the area length will be increased accordingly and will print max area covered .

Please check the code and tell my mistake as , for long it is not running , but for all test cases that i tried is running perfectly .

here:


you just needed to use long