SpaceX interview question

1 leetcode question, around medium difficulty