Mphasis interview question

Algorithm writing on paper