Can someone make me understand why did we select the max of the two substrings when last character do not match?