FastPrepSimilar DNA Under Rotation and Substitution

Similar DNA Under Rotation and Substitution

Benchling logoBenchling● MediumFULLTIMEOA
Learn

Problem statement

Given a reference DNA string and candidate DNA strings, count how many candidates have some circular rotation whose Hamming distance from the reference is at most three.

Only substitutions are allowed; insertion and deletion are not allowed.

Function

countSimilarDNA(reference: String, candidates: String[]) → int

Examples

Example 1

reference = "AAAAG"candidates = ["AAAGA","CCCCC","AAAAT"]return = 2

AAAGA matches after rotation, AAAAT needs one substitution, and CCCCC needs more than three.

Constraints

  • 1 <= reference.length <= 200.
  • 1 <= candidates.length <= 1000.
  • Every string contains only A, C, G, and T.

More Benchling problems

See Benchling hiring insights
public int countSimilarDNA(String reference, String[] candidates) {
    // Write your code here.
}
reference"AAAAG"
candidates["AAAGA","CCCCC","AAAAT"]
expected2
Checking account…