Uber | Onsite | Surround substrings

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2019-05-22Added By Anonymous
Source: Link

Company: Uber
Role: unknown
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

You have two arrays of strings, words and parts. Write a function findSubstrings(words, parts) that returns the array that contains the strings from words, modified so that any occurrences of the substrings from parts are surrounded by square brackets [], following these guidelines:

1.If several parts substrings occur in one string in words, choose the longest one.
2.If there is still more than one such part, then choose the one that appears first in the string.

Example 1:
Input: words = ["Apple", "Melon", "Orange", "Watermelon"], parts = ["a", "mel", "lon", "el", "An"]
Output: ["Apple", "Me[lon]", "Or[a]nge", "Water[mel]on"].
Explanation: While "Watermelon" contains three substrings from the parts array ("a", "mel", and "lon") "mel" is the longest substring that appears first in the string.

Comments