O(N^2) solution for gamma
"close to O(N)" version that collapses overlapping palindromes