Amazon Interview Question

logical Star method