Harver Interview Question

an algorithm problem with node