Optiver interview question

Graph traversal question (dynamic programming)