** Examples :**

Input:arr [] = {“abc”, “abd”, “bbd”}

Output:2

(abc, abd) and (abd, bbd) are the only valid pairs.

Input:arr [] = {“Def”, “deg”, “dmf”, “xef”, “dxg”}

Output:4

** Method 1: ** For each possible pair, check if both strings differ at exactly the same index position with one row traversal.

** Method 2: ** two strings can be compare as follows to check if they differ at the same index position:

Let

str1 = “abc”andstr2 = “adc”

Forstr1, add“#bc”,“a # c”and“ab #” to a set .

Now forstr2, generate the string in the similar manner and if any of the generated string

is already present in the set then both the strings differ in exactly 1 index position.

For example,“a # c”is one of the generated strings.

Notethat “#” is used because it will not be a part of any of the original strings.

Below is the implementation of the above approach:

```
``` |

** Exit :**

2

X
# Submit new EBook