If current character is ‘a’, then there are following possibilities : a) Current character begins a new subsequence. b) Current character is part of aCount subsequences. c) Current character is not part of aCount subsequences. Therefore we do aCount = (1 + 2 * aCount);

If current character is ‘b’, then there are following possibilities : a) Current character begins a new subsequence of b’s with aCount subsequences. b) Current character is part of bCount subsequences. c) Current character is not part of bCount subsequences. Therefore we do bCount = (aCount + 2 * bCount);

If current character is ‘c’, then there are following possibilities : a) Current character begins a new subsequence of c’s with bCount subsequences. b) Current character is part of cCount subsequences. c) Current character is not part of cCount subsequences. Therefore we do cCount = (bCount + 2 * cCount);