GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesReplace with Root Words

Gamified challenge · Tries

Replace with Root Words

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.

Sign in to play Replace with Root Words

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

or log in with email · create an account