Cruise interview question

Leetcode hard problem