Let\'s define eleven-non-free
numbers:
If we consider a number as a string, then if any substring inside is a (non-zero) power of 11
, then this
This sounds like a divide and conquer algorithm to me.
This problem feels very similar to: http://www.geeksforgeeks.org/divide-and-conquer-maximum-sum-subarray/
and this: http://en.wikipedia.org/wiki/Maximum_subarray_problem
When you divide you split the original String s into 2 parts that are roughly 1/2 as big. At the bottom of your recursion you have easy problems with small 1 char Strings that are all eleven-free (because they don't contain enough chars to have any powers of 11 inside).
The "trick" comes in when you "step up" in the recursion. In this step you need to take advantage of the fact that any "power" (i.e. 121) you are looking for MUST bridge the "middle" of the input string.
For example, when you "step up" from Strings of length 1 to Strings of length 2 you'll know that some of the power you're looking for is in the first half, and some is in the second half of the input string.