Imagine you are one of the earliest engineers at Google, and you need to implement a feature on Google Search that checks whether the user input is present in the database or not.
As youβre just starting to work on the search algorithm, youβre playing with a test dataset that only contains text with 3 lowercase letters a, b, and c.
There are n strings in the database and you are given k queries. You want to make the search engine both performant and fault-tolerant, so youβve decided to allow at most 1 misspelled letter.
For each query string, the program should check if the query string is present in the database while allowing at most one misspelled character (no adding or removing characters).
Input
The first line of the input contains a single integer n (1 β€ n β€ 100 000).
The next n lines contain the strings present in the database . Itβs guaranteed that the sum of the lengths of the strings in the database doesnβt exceed 100 000.
The first line of the input contains a single integer k (1 β€ k β€ 100 000) the number of queries.
The next k lines contain the query strings . Itβs guaranteed that the sum of the lengths of the query strings doesnβt exceed 100 000.
Output
For each of the query strings, the program should print Yes if it exists in the database and No otherwise, while allowing for at most 1 misspelled letter.