A, C, G or T. One edit replaces a single character of the string with another.
A lab wants to turn gene start into gene goal through a sequence of edits. After every edit the result must be a viable gene, meaning a string from the list allowed. start itself counts as viable even if it is not on the list.
Return the fewest edits needed, or -1 if it cannot be done.start="GATTACAA", goal="GATTACCC", allowed=["GATTACCA", "GATTACCC"] → 2
GATTACAA → GATTACCA → GATTACCC: two edits, and every intermediate string is in allowed.
start="GATTACAA", goal="GATTACCC", allowed=["GATTACCC"] → -1
The goal is two letters away and there is no allowed gene in between, so the answer is -1.
start="CCCCCCCC", goal="CCCCCCCC", allowed=[] → 0
A, C, G, Tstart="GATTACAA", goal="GATTACCC", allowed=["GATTACCA", "GATTACCC"]
2
Run checks the first 3 tests in your browser. Submit checks all 61 tests on the server, hidden ones included.