algorithm to caculate the max length substr between 2 strings