Goldman Sachs Interview Question

given some codes to debug