Toppan Ecquaria interview question

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