Google Interview Question

Code challenge on javascript using graph