โจทย์
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 กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน