Apple interview question

logic design problems