Level: Unknown Level
Round: Full Journey · Type: Coding · Difficulty: 2/10 · Duration: 60 min · Interviewer: Neutral
Topics: String manipulation, Substring search
Location: Mountain View, CA
Interview date: 2026-01-20
Question: Given a string s consisting of multiple words separated by spaces, and a list of strings elements, identify the first substring in each word of s that matches any string in elements. Once a match is found, wrap the substring in square brackets "[ ]". For example, given "hello uber" and the list ["ll", "ub"], return "he[ll]o [ub]er".
The coding question I got was:
`python def find_and_wrap_substrings(s, elements): words = s.split() result = [] for word in words: found = False for element in elements: index = word.find(element) if index != -1: result.append(word[:index] + "[" + element + "]" + word[index + len(element):]) found = True break if not found: result.append(word) return " ".join(result)
s = "hello uber" elements = ["ll", "ub"] print(find_and_wrap_substrings(s, elements)) `
My approach:
split() method.join() method.Key insights:
find() method returns the index of the first occurrence of a substring in a string. If the substring is not found, it returns -1.join() method can be used to concatenate a list of strings into a single string.