Add boundary case , when array n is zero Depend on smart pointers
let tailIndices = new Array ( n ) ; let prevIndices = new Array ( n ) ; for ( let i = 0 ; i < n ; i ++ ) { tailIndices [ i ] = 0 ; prevIndices [ i ] = - 1 ; }