Most Similar Words Codeforces Solution | Codeforces Problem Solution 2022
You are given words of equal length , consisting of lowercase Latin alphabet letters. The -th word is denoted .
In one move you can choose any position in any single word and change the letter at that position to the previous or next letter in alphabetical order. For example:
- you can change 'e' to 'd' or to 'f';
- 'a' can only be changed to 'b';
- 'z' can only be changed to 'y'.
The difference between two words is the minimum number of moves required to make them equal. For example, the difference between "best" and "cost" is .
Find the minimum difference of and such that . In other words, find the minimum difference over all possible pairs of the words.
The first line of the input contains a single integer () — the number of test cases. The description of test cases follows.
Most Similar Words Codeforces Solution
The first line of each test case contains integers and (, ) — the number of strings and their length respectively.
Then follows lines, the -th of which containing a single string of length , consisting of lowercase Latin letters.
For each test case, print a single integer — the minimum difference over all possible pairs of the given strings.
Join Now for Solution:-
No comments:
Post a Comment