Design a Prefix-Suggestion Search Interface
Company: Charta Health
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
Design and explain the implementation of a search-box interface that offers ten prefix-matching suggestions from `wikipedia-latest-titles.txt` as the user types, when enough matches are available.
The file contents and complete interaction contract are not supplied. Clarify what constitutes one searchable entry, the matching rules, the ordering of matches, and behavior when fewer than ten matches exist. Keep these choices explicit rather than claiming an exact output for an unseen file.
### Part 1 — Load and search the entries
Explain how the application reads the file, represents its entries, and retrieves the suggestions for a prefix.
#### What This Part Should Cover
- File format, encoding, duplicate handling, and the relationship between stored text and displayed text.
- Case, whitespace, Unicode, and ordering rules that must agree between indexing and lookup.
- A simple baseline and an index appropriate to the file's size and query frequency.
### Part 2 — Keep the interface correct as input changes
Describe the input, suggestion list, loading and error states, and selection behavior. Explain how the interface handles rapid typing and delayed search results.
#### What This Part Should Cover
- A result list tied to the current input, including empty input and no-match behavior.
- Prevention of stale responses replacing newer suggestions.
- Keyboard navigation, selection, and accessible labeling.
### What a Strong Answer Covers
- A complete path from the supplied title file to visible prefix suggestions.
- Consistent text and ordering policies, with retrieval and rendering work kept bounded.
- Concrete checks for matching, request races, and selecting an item from the current list.
### Follow-up Questions
- A response for a shorter prefix arrives after a response for the user's current longer prefix. What should happen?
- How would you change the design if the title file were too large to load into the browser?
Overview: Design a prefix-search interface over a title file, with clear matching rules, efficient lookup, accessible suggestions, and protection from stale results.
Read the full Charta Health Software Engineer interview experience this question came from