Advanced graphs and trees · 14 / 15 Exercise Hard

Autocomplete with a trie

Objective

A trie (prefix tree) stores words letter by letter in nested dictionaries: words sharing a prefix share a path. It is the typical structure behind autocompletion.

Instructions

  • The first line has lowercase words separated by spaces and the second a prefix.
  • Show, sorted alphabetically and one per line, the words that start with that prefix (including the word itself if it matches). If there are none, show None.
Input
casa casco cosa cama car
ca
Output
cama
car
casa
casco

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise