Back to the Problem
Count all |S|−1 bigrams in a map; pick the smallest among maxima.
Complexity: O(|S|)