1. If there is no possible path to change BEGIN to END then just return -1.
2. All the words have the same length and contain only lowercase english alphabets.
3. The beginning word i.e. BEGIN will always be different from the end word i.e. END (BEGIN != END).
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains a string BEGIN.
The second line of each test case contains a string END.
The third line of each test case contains a single integer N denoting the length of the DICT i.e. the array of strings.
The fourth line of each test case contains N space-separated strings denoting the strings present in the DICT array.
For each test case, print a single integer representing the length of the shortest transformation sequence from BEGIN to END.
The output of each test case will be printed in a separate line.
You don’t have to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N<= 10^2
1 <= |S| <= 10^2
Where ‘T’ is the total number of test cases, ‘N’ denotes the length of the DICT array and |S| represents the length of each string.
The idea is to use BFS traversal of the graph because considering an edge between any two adjacent words(words that will have a difference of only one alphabet) after that you just have to find the shortest between the start word and the target word and that can be done using BFS.
Here is the algorithm:
The idea is to use BFS traversal but along with that make use of trie data structure for storing the words of "DICT".
Here is the algorithm:
The idea is to use BFS traversal but doing it from both "END"s, that is from the target "END" word and "BEGIN" word, we are doing this because we can calculate the distance in half the time rather than compared to single BFS as in the previous approach-
Here is the algorithm:
Prime Digit Sum
Prime Digit Sum
Mario And His Princess
Combination Sum III
Combination Sum III
Combination Sum III
Generate All Strings
8-Queen Problem