Tap here to switch tabs
Problem
Submissions

Problem: Minimum Genetic Mutation

med
30 min
Try to solve the Minimum Genetic Mutation problem.

Statement

You are given two gene strings startGene and endGene, along with a list bank of valid gene strings. A single mutation changes exactly one character in the current gene to a different character.

Return the minimum number of mutations needed to transform startGene into endGene, where every intermediate gene string produced during the process must appear in bank. If it is impossible to reach endGene under these rules, return −1-1.

Implement int minMutation(str startGene, str endGene, List[str] bank).

Note: Each mutation must change exactly one position, and every intermediate gene must be contained in bank.

Constraints:

  • 0≤0 \leq bank.length ≤10\leq 10

  • startGene.length ==== endGene.length ==== bank[i].length ==8== 8

  • startGene, endGene, and bank[i] consist only of the characters ['A', 'C', 'G', 'T']

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Genetic Mutation

med
30 min
Try to solve the Minimum Genetic Mutation problem.

Statement

You are given two gene strings startGene and endGene, along with a list bank of valid gene strings. A single mutation changes exactly one character in the current gene to a different character.

Return the minimum number of mutations needed to transform startGene into endGene, where every intermediate gene string produced during the process must appear in bank. If it is impossible to reach endGene under these rules, return −1-1.

Implement int minMutation(str startGene, str endGene, List[str] bank).

Note: Each mutation must change exactly one position, and every intermediate gene must be contained in bank.

Constraints:

  • 0≤0 \leq bank.length ≤10\leq 10

  • startGene.length ==== endGene.length ==== bank[i].length ==8== 8

  • startGene, endGene, and bank[i] consist only of the characters ['A', 'C', 'G', 'T']