Rank Channel Autocomplete By Word Prefix And Recency
Last updated: November 29, 2026
Quick Overview
Build the channel switcher behind Slack's quick switcher: given channels with names like 'eng-backend' and a last-activity timestamp, return the top k channels the user belongs to whose name or any hyphen-separated word starts with the typed prefix. Rank full-name prefix matches first, then by recency.
Slack
November 29, 20260
0
0 solved
Build the channel switcher behind Slack's quick switcher: given channels with names like 'eng-backend' and a last-activity timestamp, return the top k channels the user belongs to whose name or any hyphen-separated word starts with the typed prefix. Rank full-name prefix matches first, then by recency.
Fits a Slack onsite coding round because the quick switcher (Cmd+K) has to feel instant across thousands of channels in an Enterprise Grid org. The interviewer wants a data structure choice that is justified, correct ranking, and a plan for updates as channels become active.
What the Interviewer Expects
- Index each word of the channel name, not just the full name, so 'back' matches 'eng-backend'
- Choose a trie or sorted prefix structure and explain why over a linear scan
- Filter by the viewer's membership before ranking
- Use a heap or nlargest for top k instead of a full sort when k is small
- Support updating recency without rebuilding the index
- Discuss memory cost of storing ids at every trie node
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you cap memory if each trie node stores every matching channel id?
- How would you add fuzzy matching for one typo?
- Where should this run: in the desktop client, at the edge cache, or on the server, and why?
- How would you blend in personal signals like channels the user opened recently?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Operations: add_channel(id, name, last_active), touch(id, ts) when a message lands, query(prefix, k, member_of). Matching is case-insensitive on any word split by - or _. Ranking key: full-n...
High-Level Design
A trie keyed by characters of each word. Every node keeps the set of channel ids whose some word passes through it, so a prefix query is a walk of len(prefix) steps and then reads one set. Recency l...