General doubt jj

j shoulf start from i + 1 right

You can do it j =i to, both will work in this case.