Backbase Interview Question

Java programme with medium difficulty