General Motors (GM) interview question

LeetCode Hard question number #1044.