Fast Enterprises interview question

Logic portion is too long. Programming questions were easy.