Katkat

Find Company Tickers Mentioned in a News Headline

SIG (Susquehanna)Software Engineer · Onsite

Last updated

Implement a headline scanner that identifies mentioned company names using whole-word matching and returns their unique stock tickers in the order specified by the input mapping.

Problem Statement

Financial news feeds require real-time entity recognition to route articles to relevant trading desks. Given a news headline string and a list of mappings containing company name and ticker pairs, identify which companies are mentioned in the headline and return their unique tickers.

Rules

  1. Tokenization: Words are defined as maximal contiguous sequences of alphanumeric characters ([a-zA-Z0-9]). All non-alphanumeric characters (punctuation, spaces, symbols) serve as delimiters.
  2. Case Insensitivity: Matching between company names and headline words must be case-insensitive.
  3. Whole-Word Matching: A company name matches if and only if all its words appear consecutively in the headline in the exact order as separate tokens. For example, "App" does not match "Apple".
  4. Deduplication & Ordering: Return unique tickers ordered by their first occurrence in the input mappings list, not by their appearance in the headline.

Function Interface

def find_mentioned_tickers(headline: str, mappings: list[tuple[str, str]]) -> list[str]:
    """
    headline: A string containing the news headline.
    mappings: A list of (company_name, ticker) tuples.
    
    Returns: A list of unique ticker strings in mapping order.
    """
    pass

Constraints

  • 1 <= len(headline) <= 10^5
  • 1 <= len(mappings) <= 10^4
  • Each company_name has between 1 and 10 words, each word consisting of alphanumeric characters.
  • headline consists of standard printable ASCII characters.
  • Tickers are non-empty strings of uppercase alphanumeric characters.

Examples

Example 1

headline = "Apple, along with Microsoft Corp., announced a partnership with OpenAI."
mappings = [
    ("Apple", "AAPL"),
    ("Amazon", "AMZN"),
    ("Microsoft Corp", "MSFT"),
    ("OpenAI", "OPAI"),
    ("Microsoft", "MSFT")
]

output = find_mentioned_tickers(headline, mappings)
# Output: ["AAPL", "MSFT", "OPAI"]

Explanation: "Apple", "Microsoft Corp", and "OpenAI" are found in the headline. "Amazon" is not. Although "Microsoft" also matches, its ticker "MSFT" has already been included. Unique tickers in mapping order are ["AAPL", "MSFT", "OPAI"].

Example 2

headline = "Meta Platforms and meta are investing heavily in AI."
mappings = [
    ("Meta Platforms", "META"),
    ("Meta", "META")
]

output = find_mentioned_tickers(headline, mappings)
# Output: ["META"]

Explanation: Both entries match, but the ticker "META" is added only once.

Hints

Hint 1

Normalize both the headline and company names by tokenizing on non-alphanumeric characters and converting tokens to lowercase.

Hint 2

A company name with k words matches if its k-token sequence appears as a contiguous sub-slice within the headline token list.

Hint 3

Use a set to track already seen tickers to guarantee uniqueness while iterating through mappings in their original order.

Follow-up questions

  • How would you scale this solution if the mappings list contained 500,000 company names evaluated against a stream of headlines? (Hint: Aho-Corasick or Trie-based matching).
  • How would you handle valid punctuation inside company names like 'Moody's', 'AT&T', or 'Yahoo!' without breaking them into separate tokens?
  • If overlapping matches were not allowed and you had to enforce greedy longest-match (e.g., 'Apple Inc' consuming both tokens so 'Apple' cannot match at the same offset), how would you modify the algorithm?