Amazon Interview Question

One DSA coding problem and it was difficult