General Motors (GM) Interview Question

LeetCode Hard question number #1044.