Christmas string
Practice
3.9 (14 votes)
Easy Medium
Approved
Greedy algorithm
Problem
87% Success 8205 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Little Santa has made a list of all the nice children to whom he have to give the present. While getting ready to deliver the gifts he forgot where he kept the list. He remembered a string S containing lowercase letters and stars ( * ). Star denotes that he didn't remember that letter of the string S.

enter image description here

Little Santa is wondering what is the maximum number of names of the nice children in the list that can possibly match with the string S if he will change at most one letter in the string S to a star. String A can possibly match with the string S if letters on non star positions are equal. He is getting late to deliver the gifts so he asked you to solve this.

Note: All the names and the string S will have same length.

Input format:
First line contains a string S \((1 \le |S| \le 3000)\), denoting the star string. S only contains lowercase letters and stars ( * ). Second line contains an integer N \((1 \le N \le 3000)\), denoting the number of names on the list. Next N lines contains a string each, \(str_i\) \((1 \le |str_i| \le 3000)\), denoting the names of the children on the list. \(str_i\) consists of only lowercase letters.

Output format:
Print an integer denoting the maximum number of names of the nice children in the list that can possibly match with the string S if he will change at most one letter in the string S to a star.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
188 votes
Tags:
Depth-first searchEasy-Medium
Points:30
864 votes
Tags:
Data StructuresEasy-MediumApprovedBinary search algorithm
Points:30
16 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpen