Amazon Interview Question

DSA question based on array but very difficult