Headout interview question

DSA Question of easy-mid difficulty