Toppan Ecquaria Interview Question

Got paper test and if you do coding in Java, should be easy