Dictionary Tokenizer with Longest Match

Asked at Google · Coding Questions · Difficulty: Easy · Last asked Jun 15, 2026

A tokenizer turns text into a list of integer ids using a fixed vocabulary of tokens. It reads the text from left to right and always takes the longest vocabulary token that fits at the current position. Characters that no token covers are dropped.

Loading the problem…