# Easy Solution with 17 lines python

• Check distance from 1 to end.

``````class Solution(object):
def minMutation(self, start, end, bank):

def getLevel(gene):
return len([i for i in range(len(start)) if start[i] != gene[i]])

level_to_end = getLevel(end)
level_set =  set(range(1, level_to_end+1))

for gene in bank:
level = getLevel(gene)
level in level_set and level_set.remove(level)

if len(level_set) != 0:
return -1

return level_to_end

``````

• class Solution(object):
def minMutation(self, start, end, bank):

``````    def getLevel(gene):
return len([i for i in range(len(start)) if start[i] != gene[i]])

level_to_end = getLevel(end)
level_set =  set(range(1, level_to_end+1))

for gene in bank:
level = getLevel(gene)
level in level_set and level_set.remove(level)

if len(level_set) != 0:
return -1

return level_to_end
``````

It doesn't check whether the end is in the bank and the connection between levels.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.