Minimum Genetic Mutation
Problem statement
A gene is an eight-character string whose characters are chosen from A, C, G, and T.
One mutation changes exactly one character. Every gene reached after a mutation must occur in bank. The starting gene is valid even when it is not in the bank.
Given startGene, endGene, and bank, return the minimum number of mutations needed to reach endGene. Return -1 when no valid sequence exists.
Function
minMutation(startGene: String, endGene: String, bank: String[]) → intExamples
Example 1
startGene = "AACCGGTT"endGene = "AACCGGTA"bank = ["AACCGGTA"]return = 1Changing the final character from T to A reaches the bank gene in one mutation.
Example 2
startGene = "AACCGGTT"endGene = "AAACGGTA"bank = ["AACCGGTA","AACCGCTA","AAACGGTA"]return = 2The sequence AACCGGTT, AACCGGTA, AAACGGTA uses two valid mutations.
Constraints
0 <= bank.length <= 10.startGene.length == 8.endGene.length == 8.- Every bank gene has length
8. - Every gene contains only
A,C,G, andT.