Optiver Interview Question

First question involved some logical thinking and string handling.