Robinhood interview question

Coding - given question code a solution