You are given a string s of length n. Each character is both of the primary k lowercase Latin letters or a question mark. You are asked to supplant each inquiry mark with one of the primary k lowercase Latin letters so that the accompanying worth is augmented. Let fi be the most extreme length substring of string s, which
C++ only. Do not copy. Correct code will upvoted else downvote.
You are given a string s of length n. Each character is both of the primary k lowercase Latin letters or a question mark.
You are asked to supplant each inquiry mark with one of the primary k lowercase Latin letters so that the accompanying worth is augmented. Let fi be the most extreme length substring of string s, which comprises altogether of the I-th Latin letter. A substring of a string is a bordering aftereffect of that string. Assuming the I-th letter doesn't show up in a string, fi is equivalent to 0.
The worth of a string s is the base worth among fi for all I from 1 to k.
What is the most extreme worth the string can have?
Input : The primary line contains two integers n and k (1≤n≤2⋅105; 1≤k≤17) — the length of the string and the number of first Latin letters utilized.The subsequent line contains a string s, comprising of n characters. Each character is both of the principal k lowercase Latin letters or a question mark.
Output : Print a solitary integer — the greatest worth of the string after each question mark is supplanted with one of the primary k lowercase Latin letters.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images