Amazon Interview Question

one graph question ,one backtracking question