Einfach 0 gelöst 0% Erfolgsquote

Hamming Distance

Compare two DNA strings position by position and count the differences.

Problem

Compare two DNA strings position by position and count the differences. Only characters at the same position are compared; do not insert, delete, or shift characters. No biology knowledge is needed.

Implement hamming_distance(first, second).

Input

first: The first DNA string.

second: The equal-length second DNA string.

Output

Return the number of positions with different characters.

Einschränkungen

Both strings have the same length, from 0 to 100,000. Characters are uppercase A, C, G, or T.

Beispiele

Beispiel 1
Eingabe:
first = "ACCT"
second = "AGCA"

Erwartete Ausgabe:
expected = 2
Eingabe:
std::string first = "ACCT";
std::string second = "AGCA";

Erwartete Ausgabe:
long long expected = 2;
Eingabe:
string first = "ACCT";
string second = "AGCA";

Erwartete Ausgabe:
long expected = 2;

Erläuterung

The second position is C versus G and the fourth is T versus A. The first and third match: two differences.

Beispiel 2
Eingabe:
first = "GATT"
second = "GATT"

Erwartete Ausgabe:
expected = 0
Eingabe:
std::string first = "GATT";
std::string second = "GATT";

Erwartete Ausgabe:
long long expected = 0;
Eingabe:
string first = "GATT";
string second = "GATT";

Erwartete Ausgabe:
long expected = 0;

Erläuterung

All four positions match, so no differences are counted.

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.