Amazon Interview Question

To calculate the Kevin Bacon number