IMC Trading Interview Question

Basic DP question involving substrings