Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Suggestion Oracle

Learn
Play
Prove
Problem context and objectives
Mission briefing

Rune decoder · Thousands of spells share the same opening symbols

Reuse shared prefixes to complete the requested spell: The Suggestion Oracle.

Checking every full spell makes each keystroke feel slow.

How you win

  1. 1Recognize when Trie autocomplete matches the clues
  2. 2Keep this true after every move: every enumerated node extends the requested prefix and results remain in lexicographic order
  3. 3Reach the result within O(prefix length + characters explored for k results)

Rules and pressure

  • Target cost: O(prefix length + characters explored for k results)
  • State rule: every enumerated node extends the requested prefix and results remain in lexicographic order
Lesson 1 of 3

Live algorithm trace

Trie autocomplete

Complete execution
1 of 6
mobile
word
mouse
moneypot
monitor
mousepad

Build one trie containing all five catalog words.

1build a trie with word markers
2walk the requested prefix
3return empty if the path is missing
4dfs children in sorted order
5emit at word markers
6stop after k suggestions
words = 5sharedPrefix = mo
Truth to preserve / Cost target
Truth to preserve

every enumerated node extends the requested prefix and results remain in lexicographic order

Cost target

O(prefix length + characters explored for k results)

Autocomplete first walks the fixed prefix. From that node, depth-first traversal in sorted child order emits matching words lexicographically and can stop as soon as k suggestions are collected.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead