Minimum Genetic Mutation
A gene is a string of 8 letters, each A, C, G or T. One mutation changes one letter, and only genes from a given bank are allowed along the way; the start gene does not have to be in the bank. Find the fewest mutations from the start gene to the end gene, or -1 if it cannot be done. Our example: start AAGGTTCC, end AAGCTTCA, bank [AAGCTTCA, TAGGTTCC, AAGGTTCA] — the answer is 2.
- input
startGeneandendGene: genes, strings of 8 lettersA,C,G,T;bank: the genes a mutation may make.- returns
- The fewest mutations that turn
startGeneintoendGene. A mutation changes one letter of the gene, and the gene it makes must be inbank;startGeneneed not be there.-1if there is no way. - constraints
- 0 ≤ bank.length ≤ 10
- startGene, endGene and bank[i] are 8 letters long, each of A, C, G, T
- startGene ≠ endGene
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} startGene
* @param {string} endGene
* @param {string[]} bank
* @return {number}
*/
function minMutation(startGene, endGene, bank) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more breadth-first search (bfs) problems
- 637Average of Levels in Binary TreeEasysolve
- 102Binary Tree Level Order TraversalMediumsolve
- 199Binary Tree Right Side ViewMediumsolve
- 994Rotting OrangesMediumsolve
- 1091Shortest Path in Binary MatrixMedium
- 841Keys and RoomsMediumsolve
- 117Populating Next Right Pointers in Each Node IIMediumsolve
- 103Binary Tree Zigzag Level Order TraversalMediumsolve
- 909Snakes and LaddersMediumsolve
- 127Word LadderHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.