Goodnotes interview question

A string manipulation problem and generate random word under certain rules