Source: https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-fall-2011/14dca83afa6ba2239ff765bbcf0642a3_MIT6_006F11_quiz1_sol.pdf