Sub | Array to store the sum of digits ; Utility function to evaluate a character 's  integer value ; This function receives the string representation of the number and precomputes the sum array ; This function receives l and r representing the indices and prints the required output ; Driver Code
let sum = [ ] ; function toInt ( x ) { return x - ' ' ; } function prepareSum ( s ) { sum [ 0 ] = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { sum [ i + 1 ] = sum [ i ] + toInt ( s [ i ] ) ; } } function query ( l , r ) { if ( ( sum [ r + 1 ] - sum [ l ] ) % 3 == 0 ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } let n = " " ; prepareSum ( n ) ; query ( 0 , 1 ) ; query ( 1 , 2 ) ; query ( 3 , 6 ) ; query ( 0 , 10 ) ;