HotWax Systems interview question

same question which i put a solution in interview process as asked in coding test