There is a problem in one leetcode problem please help me out


question link
solution link

kindly check why it is throwing error

AddressSanitizer:DEADLYSIGNAL ================================================================= ==31==ERROR: AddressSanitizer: SEGV on unknown address 0x6021da7e24d0 (pc 0x0000003780a9 bp 0x7fff769f8990 sp 0x7fff769f8880 T0) ==31==The signal is caused by a READ memory access. #3 0x7fbc5680f0b2 (/lib/x86_64-linux-gnu/libc.so.6+0x270b2) AddressSanitizer can not provide additional info. ==31==ABORTING this error is coming

hello @shivammishra20121999
pls wait , i m checking ur code

@aman212yadav bro are u checking?

yeah …
here is ur updated code->

@aman212yadav bro we have to find lowest element after ex which is greter than ar[ex-1]

yeah correct.

image
a) first of all i and ex will remain same.
b)
we know that from index [ex…n-1] array is sorted in decreasing order right.
so the last element that satisfy the if condition will be our required candidate for swapping

@aman212yadav got it thanks a lot