Hamming Distance
ABC 399Problem 17 of 50
EasyWhat to do
Given two strings of equal length, count the number of positions where the characters differ. This is called the Hamming distance. For example, 'abcarc' vs 'agcahc' differ at positions 2 and 5, so the distance is 2.
Key Concepts
loops
conditional statements
string manipulation
counting
Examples
Input:
s = 'abcarc', t = 'agcahc'
Output:
2
Input:
s = 'atcoder', t = 'contest'
Output:
7
Tips for Beginners
- Focus on understanding the logic, not memorizing syntax
- Use print statements to debug your code
- Don't worry about input parsing - the function handles that for you
- If stuck, try writing out your solution on paper first
Python Editor
Loading Python...