Couldn't understood why in some test cases my code has failed

@coe17b030 initialize j with i inside the outer loop. If you don’t do that, j will be at the last index just after the first iteration of the outer loop.
Hope this helps.