Genesys interview question

Koko banana question from leet code