IMC Trading interview question

Basic DP question involving substrings