The Substring Wrapper (commonly known as Surround Substrings) is a frequent Uber onsite coding interview question. You are given two arrays: words and parts. Your task is to modify each word in words so that any occurrence of a substring from parts is enclosed in square brackets []. 4 5
When multiple substrings from parts match a word, you must follow specific tie-breaking rules: 4
Input:
Output & Reasoning:
Word | Matches Found | Wrapped Result | Reason --- | --- | --- | --- Apple | None | "Apple" | Case-sensitive: "a" does not match "A". Melon | "mel", "lon" | "Me[lon]" | "mel" and "lon" are equal length; "mel" appears first. Note: Some variations prefer "lon" based on specific logic, but priority is usually length then position. Orange | "a" | "Or[a]nge" | Only "a" matches. Watermelon | "a", "mel", "lon" | "Water[mel]on" | "mel" and "lon" (length 3) are longer than "a" (length 1). "mel" appears before "lon".
To solve this efficiently for large datasets, interviewers typically expect a Trie (Prefix Tree): 3 2
Complexity Targets:
Would you like to see a Python or Java implementation of the Trie-based solution?
[0] - Uber | Onsite | Surround substrings - Discuss - LeetCode [1] - Uber Coding & Algorithms Questions (Updated 2026) - PracHub [2] - How to Crack Uber Coding Interviews in 2026 | CodeJeet [3] - Uber SWE Interview Breakdown: From CodeSignal to System ... [4] - Uber | Onsite | Surround substrings - Discuss - LeetCode [5] - Uber | Onsite | Surround substrings - Discuss - LeetCode [6] - Uber | Onsite | Surround substrings - Discuss [7] - 820. Short Encoding of Words - In-Depth Explanation