Converting string to integer array for ease of computations ( Indexing in arr [ ] is considered to be starting from 1 )
let arr = new Array ( n + 1 ) ; for ( let i = 1 ; i <= n ; i ++ ) arr [ i ] = ( str [ i - 1 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; for ( let i = 1 ; i <= n ; i ++ ) { dp [ i ] [ arr [ i ] % 8 ] = 1 ; for ( let j = 0 ; j < 8 ; j ++ ) {