Rakuten interview question

basics question from java and algorithms