I have still not put the code for the condition of printing -1,but I am not able to understand how to use the break statement so that the loop does not run for two times printing the greater element on both the sides.Please help.Also when I put the condition for -1 it gets printed two times.Please help.
Greater element problem
@srshubhi398 whenever you print the answer for any element make a bool found variable to true. if found is false then run second for loop and after second for loop too if found is false then print -1.
well what you are doing is brute force technique so it may give TLE for bigger cases. if you get TLE try implementing this problem using stack.
then do I need to use break?
yeah after making found = true break for loop.
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.
1 Like