Create an array of size len + 1 and initialize it with 0. Store remainders from left to right when divided by ' a '
let lr = [ ] ; for ( let i = 0 ; i < len + 1 ; i ++ ) lr . push ( 0 ) ; lr [ 0 ] = ( str [ 0 ] - ' ' ) % a ; for ( let i = 1 ; i < len ; i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str . charCodeAt ( i ) ) ) % a ;