Store the index of current element and its just smaller element in array w [ ]
int currElementPos = pos . get ( a [ curr ] ) ; int prevElementPos = pos . get ( a [ curr - 1 ] ) ; if ( currElementPos > prevElementPos ) continue ;