Problem Statement
You are given an integer (provided as
Definition
- Class:
- MagicNumberThree
- Method:
- countSubsequences
- Parameters:
- String
- Returns:
- int
- Method signature:
- int countSubsequences(String s)
- (be sure your method is public)
Constraints
- s will contain between 1 and 50 characters, inclusive.
- Each character of s will be between '0' and '9', inclusive.
Examples
"132"
Returns: 3
There are 7 total subsequences of the given digits, but only some of them work: 3, 12, and 132 are divisible by 3. 1, 2, 13, and 32 are not.
"9"
Returns: 1
There's only one subsequence to consider here, and it is divisible by 3.
"333"
Returns: 7
There are three ways to make a "3" as a subsequence, and we could all of them individually. There are also three ways to make a subsequence of "33", which we also count. And, of course, "333" also works.
"123456"
Returns: 23
"00"
Returns: 3
Remember that 0 is divisible by three. The sequence 00 of course also has the value 0.
"33333333333333333333333333333333333333333333333333"
Returns: 898961330
"62384743394755163270431467082083782018151384161323"
Returns: 966233066
"30165309167602009721451281463066597821289264752531"
Returns: 967019498
"74118889738451011152784322864398222154080338046446"
Returns: 966331370
"30013897969143401388570614453754279881842744988049"
Returns: 966495210
"33650603094342059736105468256254133276638419983234"
Returns: 943950826
"91688271924467302088720076954859123473514564847369"
Returns: 966233066
"52457605013271742438295641552395952256463223828573"
Returns: 966331370
"13977677151537272284950740718239881552765859588410"
Returns: 966319082
"96724632278588216466104190002512072725452390709673"
Returns: 965970922
"14859915336296565054819038043913383735835611903241"
Returns: 960728042
"0000000000000000000000000000000000000000"
Returns: 511620082
"41184676334265001916915724114782935826962244645705"
Returns: 966364138
"12345678901234567890123456789012345678901234567890"
Returns: 967019498
"32132132133213213213321321321332132132133213213213"
Returns: 967019498
"0000000000000000000000000000000000000000000000000"
Returns: 949480668
"01234067891111111111111122222222222222222222111111"
Returns: 966320458