Fast Enterprises Interview Question

Logic portion is too long. Programming questions were easy.