Magna International Interview Question

The algorithm I used in my undergraduate thesis.