• + 1 comment

    I'm solving this in C# and I'm getting timeouts after 3rd test case as lot of other people here. I'd really like to know whether my algorithm is so inefficient, or it's something else. What I do is, I loop through every letter in DNA, take substring of virus size and compare if they're equal (this should be O(n)). Of course then it comes to figuring out whether there's more than 1 mistake between the DNA substring and virus. So I recursively halve the substring and the virus and check on both halves whether they're the same; If both halves are different, check stops because that means there is more than one mistake. For most cases this should stop immediately, so overall performance should still be O(n) or very close in typical case, of course in the worst case scenario where there's only 1 mistake, for just the searching mistake part it's O(log n)... so worst case scenario should be O(x log n), where x is length of DNA and n is length of virus sequence. Is this really so inefficient? Is there O(n) solution for this?