Count of different numbers divisible by 3 that can be obtained by changing at most one digit | Function to count the number of possible numbers divisible by 3 ; Calculate the sum ; Store the answer ; Iterate over the range ; Decreasing the sum ; Iterate over the range ; Checking if the new sum is divisible by 3 or not ; If yes increment the value of the count ; Given number
function findCount ( number ) { let sum = 0 ; for ( let i = 0 ; i < number . length ; ++ i ) { sum += number [ i ] - 48 ; } let count = 0 ; for ( let i = 0 ; i < number . length ; ++ i ) { let remaining_sum = sum - ( number [ i ] - 48 ) ; for ( let j = 0 ; j <= 9 ; ++ j ) { if ( ( remaining_sum + j ) % 3 == 0 && j != number [ i ] - 48 ) { ++ count ; } } } document . write ( count ) ; } let number = " " ; findCount ( number ) ;