Papaya Global interview question

Some random leet code quesiton