Goldman Sachs Interview Question

DSA question based on stack