Bloomberg interview question

String related question but it required two Data structures to solve it.