FastPrepMinimum Genetic Mutation

Minimum Genetic Mutation

Benchling logoBenchling● MediumNEW GRADOA
Learn

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[]) → int

Examples

Example 1

startGene = "AACCGGTT"endGene = "AACCGGTA"bank = ["AACCGGTA"]return = 1

Changing 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 = 2

The 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, and T.

More Benchling problems

See Benchling hiring insights
public int minMutation(String startGene, String endGene, String[] bank) {
    // Write your solution here.
}
startGene"AACCGGTT"
endGene"AACCGGTA"
bank["AACCGGTA"]
expected1
Checking account…