Robinhood interview question

Medium level questions from leetcode