For example, given string "abc fghi bc kl abcd lkm abcdefg", the function should return string "abcd" and the count of 2.
A O(n^2) solution seems easy but I am looking for a better solution.
Edited: If nothing better than O(n^2) is possible than which approach would be best performance wise.