Count the subsequences of length 4 divisible by 9

Viewed 1543

To count the subsequences of length 4 of a string of length n which are divisible by 9.

For example if the input string is 9999 then cnt=1

My approach is similar to Brute Force and takes O(n^3).Any better approach than this?

4 Answers
Related