General Motors (GM) interview question

Two pointer leet code question