Honeywell interview question

Write a program to solve given task.