Problem Statement
Using only the letters 'a' and 'b' return how many palindromes of length len do not have forbidden as a substring. A palindrome is a word that is unchanged by reversing it.
Definition
- Class:
- PalindromePatterns
- Method:
- howMany
- Parameters:
- String, int
- Returns:
- long
- Method signature:
- long howMany(String forbidden, int len)
- (be sure your method is public)
Constraints
- forbidden will contain between 1 and 5 characters inclusive.
- len will be between 1 and 100 inclusive.
- Each character in forbidden must be 'a' or 'b'.
Examples
"a"
5
Returns: 1
Only one possible palindrome."aaaaa"
5
Returns: 7
7 of the 8 possible palindromes work here."aa"
10
Returns: 8
"aa"
30
Returns: 987
"a"
1
Returns: 1