Keyword-Based FAQ Matcher
Given a list of FAQ (question, answer) pairs and a user's question, find the FAQ answer whose question shares the most keywords with the user's question — a simple, non-embedding retrieval approach.
Approach: turn both the user's question and each FAQ question into a set of lowercased words, count the overlap, and return the answer for whichever FAQ has the highest overlap (first one wins on a tie).
Input: First line: the number of FAQs n. Next n lines: question|answer. Final line: the user's question.
Output: One line: the best-matching FAQ's answer.
3 How do I reset my password|Go to settings and click reset What are your hours|We are open 9 to 5 How do I contact support|Email support@example.com How can I reset my password please
Go to settings and click reset
- 1 <= n <= 100
Hint 1
set(text.lower().split()) turns a sentence into a set of lowercased words.
Hint 2
The & operator between two sets gives their intersection — the shared keywords.
Hint 3
Track the best (question, answer) seen so far as you loop, updating only when a strictly higher overlap is found.
Converting both the user's question and each FAQ question into a lowercased set of words lets len(keywords & user_keywords) count how many words they share, regardless of order or exact phrasing. Keeping track of the highest overlap seen so far as you loop through the FAQs picks the best-matching one — a simple, effective retrieval approach that doesn't need embeddings or an LLM at all, exactly as the notes describe.