Staples Interview Question

Time/Space complexity of the code