prob: https://hack.codingblocks.com/app/contests/2022/1053/problem
sol: https://ide.codingblocks.com/s/413848
getting tle in some test cases
prob: https://hack.codingblocks.com/app/contests/2022/1053/problem
sol: https://ide.codingblocks.com/s/413848
getting tle in some test cases
This is because your code is O(n^2). This question can be done using a stack in O(n). See the stack solution on this link https://www.geeksforgeeks.org/next-greater-element/
did it that way but the order of last 2 elements of stack is slightly different than the required output, so it won’t get accepted
Traverse from right to left and store the answer. I adjusted your code for that https://ide.codingblocks.com/s/416785
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.