Given two distinct words startWord and targetWord, and a list denoting wordList of unique words of equal lengths. Find the length of the shortest transformation sequence from startWord to targetWord.
Keep the following conditions in mind:
	A word can only consist of lowercase characters.
	Only one letter can be changed in each transformation.
	Each transformed word must exist in the wordList including the targetWord.
	startWord may or may not be part of the wordList
The second part of this problem can be found here.
Note: If no possible way to transform sequence from startWord to targetWord return 0
Example 1:
Input:
wordList = {"des","der","dfr","dgt","dfs"}
startWord = "der", targetWord= "dfs",
Output:
3
Explanation:
The length of the smallest transformation
sequence from "der" to "dfs" is 3
i,e "der" -> "dfr" -> "dfs".
Example 2:
Input:
wordList = {"geek", "gefk"}
startWord = "gedk", targetWord= "geek", 
Output:
2
Explanation:
gedk -> geek
Example 3:
Input: 
wordList = {"poon", "plee", "same", "poie","plea","plie","poin"}
startWord = "toon", targetWord= "plea",
Output: 7 
Explanation:
toon -> poon -> poin -> poie -> plie -> plee -> plea 
 
Your Task:
You don't need to read or print anything, Your task is to complete the function wordLadderLength() which takes startWord, targetWord and wordList as input parameter and returns the length of the shortest transformation sequence from startWord to targetWord. If not possible return 0.
Expected Time Compelxity: O(N^{2} * M)
Expected Auxiliary Space: O(N * M) where N = length of wordList and M = |wordList_{i}|
Constraints:
1 ≤ N ≤ 100
1 ≤ M ≤ 10

Difficulty: MEDIUM_HARD
Tags: Data structures

Graph algorithms

Graph traversal
Skill types: Data structures
Expected Time Complexity: O(N2 * M)
Expected Auxiliary Space:  O(N * M) where N = length of wordList and M = |wordListi|

Starter code:
class Solution:

	def wordLadderLength(self, startWord, targetWord, wordList):

		#Code here

Solutions:
from collections import deque

class Solution:

	def wordLadderLength(self, startWord, targetWord, wordList):
		queue = deque()
		queue.append((startWord, 1))
		visited_set = set(wordList)
		if startWord in visited_set:
			visited_set.remove(startWord)
		while queue:
			(word, steps) = queue.popleft()
			if word == targetWord:
				return steps
			word = list(word)
			for i in range(len(word)):
				originalletter = word[i]
				for ch in range(ord('a'), ord('z') + 1):
					word[i] = chr(ch)
					if ''.join(word) in visited_set:
						queue.append((''.join(word), steps + 1))
						visited_set.remove(''.join(word))
				word[i] = originalletter
		return 0


from queue import deque

class Solution:

	def wordLadderLength(self, startWord, targetWord, wordList):
		wset = set(wordList)
		q = deque()
		q.append((startWord, 1))
		while q:
			(wrd, steps) = q.popleft()
			if wrd == targetWord:
				return steps
			for j in range(len(wrd)):
				for i in range(26):
					l = list(wrd)
					l[j] = chr(i + 97)
					nwrd = ''.join(l)
					if nwrd in wset:
						q.append((nwrd, steps + 1))
						wset.remove(nwrd)
		return 0


from collections import deque

class Solution:

	def wordLadderLength(self, startWord, targetWord, wordList):
		queue = deque()
		queue.append([startWord, 1])
		st = set(wordList)
		st.discard(startWord)
		while queue:
			ele = queue.popleft()
			word = ele[0]
			steps = ele[1]
			n = len(word)
			if word == targetWord:
				return steps
			for i in range(0, n):
				for ch in 'abcdefghijklmnopqrstuvwxyz':
					newword = word[:i] + ch + word[i + 1:]
					if newword in st:
						st.discard(newword)
						queue.append([newword, steps + 1])
		return 0


import queue

class Solution:

	def wordLadderLength(self, startWord, targetWord, wordList):
		s = queue.Queue()
		vis = set()
		for i in wordList:
			vis.add(i)
		s.put([startWord, 1])
		while not s.empty():
			curr = s.get()
			curr_word = curr[0]
			curr_size = curr[1]
			if curr_word == targetWord:
				return curr_size
			for word in range(len(curr_word)):
				for alpha in range(97, 123):
					replace_word = ''
					for j in range(len(curr_word)):
						if word == j:
							replace_word += chr(alpha)
						else:
							replace_word += curr_word[j]
					if replace_word in vis:
						s.put([replace_word, curr_size + 1])
						vis.remove(replace_word)
		return 0


from collections import deque

class Solution:

	def wordLadderLength(self, startWord, targetWord, wordList):
		s = set(wordList)
		q = deque()
		q.append([startWord, 1])
		if startWord in s:
			s.remove(startWord)
		while q:
			(word, steps) = q.pop()
			if word == targetWord:
				return steps
			for i in range(len(word)):
				for c in 'abcdefghijklmnopqrstuvwxyz':
					new_word = word[:i] + c + word[i + 1:]
					if new_word in s:
						s.remove(new_word)
						q.appendleft([new_word, steps + 1])
		return 0