Product
Pricing
Blog
Forum
NEW
Referral
Description
Solution
Discussion
Submissions
Ask AI
AI Insights
Quick Summary
Segment an input string into tokens using a provided dictionary of key-value pairs.
Apply a greedy strategy that always selects the longest matching prefix at each step.
Unmatched characters are preserved and emitted as individual literal tokens.
What This Tests
Trie construction and efficient prefix matching
Greedy algorithm design and state management
Linear pass string segmentation
Handling overlapping or nested dictionary keys
Common Patterns
Trie
Greedy
Collapse
Hint 1
Hint 2
What Interviewers May Ask Next
Report
Report seen similar question in interview
Accepted
2.2k
/5.1k
Acceptance Rate
43.2%
Ask AI Assistant
Ask AI Assistant
Ask me anything about this coding question!
Python3
Auto
Debug
Run
Submit
Test Cases
Input
text =
dictionary =
Output
Expected