Minimum Genetic Mutation
MediumGraphs
Decode it first. Clues, constraints, pattern and plan before any code.A gene is a string of 8 characters, each one of A, C, G or T. A mutation changes exactly one character of a gene. You are given a start gene, an end gene and a bank of allowed genes. Every gene you mutate into must be in the bank (start itself does not have to be). Return the fewest mutations that turn start into end, 0 if they are already equal, or -1 if it cannot be done.
start = "TTGGCCAA", end = "TTGGCCAC", bank = ["TTGGCCAC"] → 1
start = "GGGGGGGG", end = "TTGGGGGG", bank = ["TGGGGGGG", "TTGGGGGG", "GTGGGGGG"] → 2
start = "AACCTTGG", end = "AACCTTGA", bank = [] → -1Constraints
0 <= bank.length <= 10start,endand everybank[i]have length 8.- Every gene contains only the characters
A,C,GandT.