HotWax Systems Interview Question

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