Problem · Trie
Extract Company Tickers from News
Learn this problemProblem statement
Given a news article, parallel arrays of company names and ticker symbols, return the tickers for companies mentioned in the article.
For this exercise, assume matching is case-insensitive over maximal alphanumeric words, while punctuation separates words. Company names may contain multiple words. Scan from left to right; when several names begin at the same word, select the longest name. Return each ticker only on its first matched mention.
Function
extractTickers(news: String, companyNames: String[], tickers: String[]) → String[]Examples
Example 1
news = "Apple partnered with Goldman Sachs; Apple shares rose."companyNames = ["Apple","Goldman Sachs"]tickers = ["AAPL","GS"]return = ["AAPL","GS"]The first mentions occur in the order Apple, then Goldman Sachs. The second Apple mention does not duplicate AAPL.
Example 2
news = "The New York Times expanded coverage in New York."companyNames = ["New York","New York Times"]tickers = ["NY","NYT"]return = ["NYT","NY"]The longest name wins at the first position. The later standalone New York mention then adds NY.
Constraints
0 <= news.length <= 2 * 10^51 <= companyNames.length = tickers.length <= 10^4- Normalized company names are unique and nonempty.
- The total company-name length is at most
2 * 10^5.