ARI Simulation Interview Question

Logic based question on Programming language.