BNY Interview Question

Make sure to know time and space complexity