It isnt passing all the test cases please check once
hello @gaganpreetsachdev1
a) use else (otherwise both if will execute in single iteration)
b) in ur second if u r increment r and then in line number u r using r-l+1 (here index r is not incuded u it should be r-l only for second if)
c) why u are updating bestl in every iteration (it should be updated only when u encounter value which is greater than ans)