Gamified challenge · Tries
A scribe is paid by the page, and ink is precious. The scribe has a dictionary of roots (lowercase strings). When copying a sentence, any word that starts with a root is written as just that root; if several roots fit, the shortest one is used. Words that start with no root are copied unchanged.
Write replaceRoots(roots, sentence) (Python: replace_roots(roots, sentence)). sentence is lowercase words separated by single spaces (it may be empty). Return the copied sentence, words still separated by single spaces.
Example: roots ["sun", "moon", "star"] and "sunny moonlight sky" give "sun moon sky". A root may equal the whole word ("go" stays "go"), but a root longer than the word doesn't fit.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google