PIXELBANKv9.1.0
Menu

Given a document (list of words) and a query word, find the context window of size k around each occurrence of the query word. Return all unique context windows.

Input format:

  • Line 1: The document text
  • Line 2: The query word
  • Line 3: Window size k (number of words on each side)

Output: Each context window on a separate line (words joined by spaces). Matching is case-insensitive. Print windows in order of appearance.

Example:

Input:
the cat sat on the mat near the door
the
1
Output:
the cat
on the mat
near the door
Reasoning:

Step 1: Find occurrences of "the" (positions 0, 4, 7)

Step 2: Extract windows (k=1 on each side) Position 0: [max(0,0-1):0+1+1] = words[0:2] = "the cat" Position 4: words[3:6] = "on the mat" Position 7: words[6:9] = "near the door"

Constraints:

  • Case-insensitive matching for query word
  • Window extends k words on each side
  • Clip at document boundaries
  • Output unique windows in order of first appearance
solution.py

Test Results

0/0
Run code to see test results.
Context Window Finder - Easy | PixelBank