General Motors (GM) interview question

Got an home assignment to solve an algorithmic problem