This question evaluates string manipulation, anagram detection, and constrained dictionary mapping skills, testing attention to character-level constraints and correct disambiguation among similar vocabulary entries.
You are given:
vocab
: a list of lowercase words (the "dictionary")
s
: a string containing space-separated scrambled words
Each scrambled word in s is guaranteed to be an anagram of exactly one word in vocab, with these extra constraints:
Note: Some vocabulary words can be anagrams of each other (e.g., "pears" and "spear"). In that case, the additional constraint (same first/last character) is what makes the mapping unique for each scrambled token.
Return the decoded sentence by replacing each scrambled word with its matching vocabulary word, preserving word order and spaces.
Example:
vocab = ["pears", "spear", "something"]
s = "seapr sothinmeg"
"spear something"
Implement a function:
string[] vocab, string s
string decoded