John Deere Interview Question

general approach for a solution