Question bank › Trie
Dsa Trie Medium

Prefix Highlighting

You are tasked with creating a program that highlights the prefixes of certain words found in a list. Given a list of words and a search string, find all words in the list that start with the search string and output them with the search string highlighted. The highlights should be made by wrapping the search string in asterisks. If no words match, output 'No matches found'. Input: The first line contains an integer N (1 <= N <= 10^4), the number of words in the list. The next N lines each contain a single word consisting of lowercase letters. The last line contains the search string, a lowercase string (1 <= len <= 20). Output: Output a list of words that match the prefix with the highlighted search string, each word on a new line. If no matches are found, output 'No matches found'. Example: Input: 5 apple appetite banana apricot blueberry app Output: ap*pp*le app*etite ap*pricot

Key concepts

triestring manipulationprefix searching

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.