btw there is also an O(nlogn ) approach to solve this problem and with that certainly you will not get this veridict so i think you should check this out i have provided an explanation of that at the end::
if you like this answer dont forget to cast votes::