PIXELBANKv9.1.0
Menu

Extract relevant context windows from a document for a given query.

Given a document (list of sentences) and a query, find sentences that contain at least one query word and return them with their indices.

Input format:

  • Line 1: Query string (space-separated words, lowercase)
  • Line 2: Number of sentences N
  • Lines 3 to N+2: One sentence per line (lowercase)

Output: A list of tuples (index, sentence) for sentences containing at least one query word. Matching is case-insensitive (both already lowercase).

Example:

Input:
machine learning
4
deep learning is a subset of machine learning
natural language processing uses rules
machine translation converts text between languages
learning algorithms improve with data
Output:
[(0, 'deep learning is a subset of machine learning'), (2, 'machine translation converts text between languages'), (3, 'learning algorithms improve with data')]
Reasoning:

Query words: {"machine", "learning"}

  • Sentence 0: "deep learning is a subset of machine learning" — contains both "learning" and "machine" => MATCH
  • Sentence 1: "natural language processing uses rules" — no match
  • Sentence 2: "machine translation converts text between languages" — contains "machine" => MATCH
  • Sentence 3: "learning algorithms improve with data" — contains "learning" => MATCH

Constraints:

  • Match whole words only (split on whitespace)
  • Both query and sentences are lowercase
  • Return matches in order of appearance
  • A sentence matches if it contains ANY query word
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.