Is any better approach possible doing comparartors

https://onlinegdb.com/H1I3s0rEP pls check and give a brief info if possible.

hello @asinghal1_be19 the logic of your code is optimised only but make sure you also learn to implemnt it in the more optimised way.
https://ide.codingblocks.com/s/331726 this is the code in which i have optimised your logic .
do you need the explanation of logic also ?
Happy Learning !!

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.