please review my answer
One testcase is not passing
@Mihir163 removed j=i and used erase instead of clear (little error in logic) .
hope its clear if yes dont forget to mark resolved 
actually i am trying with different approach but thanks âŠi realized my mistake sir