Amazon Interview Question

To solve a given problem with optimize coding