Epic interview question

Programming is a bit tough part need to write logic correctly.