Iterate until current element position is at most its just smaller element position
while ( currElementPos <= prevElementPos || filled . containsKey ( currElementPos ) && filled . containsKey ( currElementPos ) ) { currElementPos += jump . get ( a [ curr ] ) ; ans ++ ; }