Amazon Interview Question

The puzzle in third round