My code is not submitting.
Neither showing testcases failed or passed.
Here is my code:
Code is not submitting due to website issue
i guess time limit exceeding. I have done correct but how to reduce time complexity.
it may be becoz of some network issue
soln exists in o(n)
simplest approach : required next smaller element
in a array store the next smaller element in left and right side respectively.
so at each pnt u know the left side and rt side smaller element index
so u can find the area( area=> left smaller index+1 TO right smaller index-1 )
and compare and store the area
hope this will help u
pls rate my work
i got you to the point how to find area but i didnt get how to store left and right smaller element in one go means in O(n)
i need to use nested loops . How to do it in a single loop
bhaiya help! i need to know before tmorrow 1 pm. Tomorrow is my placement drive and i am getting gut feeling for similar kind of que
sorry for the late reply
have you solved a qn named find next smaller element
stack is used in this qn
or next greater element
suppose we have to find next smaller element (left to right)
e.g
1 6 2 8 4
so put 1 onto the stack
now 6 is not smaller than the peek of stack, so put this value also
now stack - 1 , 6
now 2
so 2 is smaller than peek so
pop peek set the ans that 2 is the next smaller element for the 6 element
but 2 can’t pop 1
[
now stack- 1
res== 6 next smaller elem=2
}
now 8
push onto the stack(can’t pop becoz 8 is grtr than peek)
stack-- 1, 8
now 4
4<peek(8)
pop the stack till the peek is smaller than the curr element and set the ans for the peek element
pop 8
set 8 next smll elem - 4
cant pop 1(1<4)
push 4 onto the stack
finallly
stack – 1,4
res==
6 nxt sm ele-2
8 nxt sm ele-4
the elem which r present in stack
don’t have any smaller elem on the right side
O(n)
hope this will help u
pls rate my work
pls