Optiver interview question

First question involved some logical thinking and string handling.