Skip to main content
All questions
MediumStrings · Hash Map

Search Suggestion Ranking

Written by a community member · · 1 attempt · 0% pass

1

Implement a function that ranks search suggestions for a mock news site.

Given a list of article titles and a query string, return the titles that match the query words, ordered by relevance.

Rules:

  • Treat words case-insensitively.
  • Match by exact whole-word tokens only.
  • A title matches if it contains every query word as a whole word, in any order.
  • If two titles match, preserve their original order.
  • Return only the matching titles.

Examples:

  1. titles = ["Washington Post Full Stack Engineer", "Full Stack Engineer at Washington Post", "Senior Editor"]
    query = "Washington Post"
    output = ["Washington Post Full Stack Engineer", "Full Stack Engineer at Washington Post"]

  2. titles = ["Newsroom Tools", "Tools for Newsroom", "Breaking News"]
    query = "news tools"
    output = []
    (No title contains both exact words news and tools as whole words.)