Citadel Interview Question

Pretty normal algorithm coding question