Условие
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.
Ограничения
Both strings have the same length, from 0 to 100,000. Characters are uppercase A, C, G, or T.
Примеры
Ввод:
first = "ACCT"
second = "AGCA"
Ожидаемый вывод:
expected = 2
Ввод:
std::string first = "ACCT";
std::string second = "AGCA";
Ожидаемый вывод:
long long expected = 2;
Ввод:
string first = "ACCT";
string second = "AGCA";
Ожидаемый вывод:
long expected = 2;
Пояснение
The second position is C versus G and the fourth is T versus A. The first and third match: two differences.
Ввод:
first = "GATT"
second = "GATT"
Ожидаемый вывод:
expected = 0
Ввод:
std::string first = "GATT";
std::string second = "GATT";
Ожидаемый вывод:
long long expected = 0;
Ввод:
string first = "GATT";
string second = "GATT";
Ожидаемый вывод:
long expected = 0;
Пояснение
All four positions match, so no differences are counted.
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.