GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday, 10 May 2022

Most Similar Words Codeforces Solution | Codeforces Problem Solution 2022

C. Most Similar Words
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given n words of equal length m, consisting of lowercase Latin alphabet letters. The i-th word is denoted si.

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'.

Solution Click Below:-  CLICK HERE

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 1+10+0+0=11.

Find the minimum difference of si and sj such that (i<j). In other words, find the minimum difference over all possible pairs of the n words.

Input

The first line of the input contains a single integer t (1t100) — the number of test cases. The description of test cases follows.

Most Similar Words Codeforces Solution

The first line of each test case contains 2 integers n and m (2n501m8) — the number of strings and their length respectively.

Then follows n lines, the i-th of which containing a single string si of length m, consisting of lowercase Latin letters.

Output

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