NimbleRx interview question

String question, optimize solution much as possible