solve maximal substring