26 · Graphs: BFS & DFS

#433 Minimum Genetic Mutation

Mediumsolve on LeetCode ↗

frequently reported atAmazonGoogleBloombergMicrosoft

the problem

In plain words

A gene is an 8-letter string over A, C, G and T. One mutation changes exactly one letter. You may only pass through genes listed in bank (the start gene doesn't need to be there, but the end gene does). Return the fewest mutations to turn startGene into endGene, or -1 if it can't be done.

in startGene = "AACCGGTT", endGene = "AACCGGTA", bank = ["AACCGGTA"]

out 1

Change the last T to A.

in startGene = "AACCGGTT", endGene = "AAACGGTA", bank = ["AACCGGTA","AACCGCTA","AAACGGTA"]

out 2

AACCGGTT → AACCGGTA → AAACGGTA.

  • 0 ≤ bank.length ≤ 10
  • startGene, endGene and bank[i] have length 8
  • Only the letters A, C, G, T

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #127
      Word Ladder
      Hardin Graphs
    2. #909
      Snakes and Ladders
      Mediumin Graphs
    3. #1197
      Minimum Knight Moves
      Mediumin GraphsLeetCode Premium