Nagarro interview question

Java code chef challenge