Anyone has an idea how to solve it ?

The problem is : Problem G. String without repetitions (High)

Anyone has an idea how to solve it ?