Tip 1: We can consider the simplication where we check whether a given K works. How to solve that? Tip 2: The solution to tip 1 is: store all strings of length K in a set and check for duplicates. Tip 3: Search K by dichotomy.