Todos los desafíos
Fácil 0 resueltos 0% de aceptación

Hamming Distance

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

Problema

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.

Restricciones

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

Ejemplos

Ejemplo 1
Entrada:
first = "ACCT"
second = "AGCA"

Salida esperada:
expected = 2
Entrada:
std::string first = "ACCT";
std::string second = "AGCA";

Salida esperada:
long long expected = 2;
Entrada:
string first = "ACCT";
string second = "AGCA";

Salida esperada:
long expected = 2;

Explicación

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

Ejemplo 2
Entrada:
first = "GATT"
second = "GATT"

Salida esperada:
expected = 0
Entrada:
std::string first = "GATT";
std::string second = "GATT";

Salida esperada:
long long expected = 0;
Entrada:
string first = "GATT";
string second = "GATT";

Salida esperada:
long expected = 0;

Explicación

All four positions match, so no differences are counted.

Referencias

Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.

Aprende de otros

Soluciones de la comunidad

Aún no hay soluciones publicadas. Resuelve este reto para compartir la primera.