ChangingString
SRM 341 · 2007-03-10 · by pure_
Problem Statement
You are given two
You must change exactly K characters in A into other lowercase letters. Return the minimum possible distance between A and B after you perform that change.
Constraints
- A and B will each contain between 1 and 50 characters, inclusive.
- K will be between 1 and the length of A, inclusive.
- A and B will contain the same number of characters.
- A and B will contain only lowercase letters ('a' - 'z').
"ab" "ba" 2 Returns: 0
The minimum distance (equal to 0) can be achieved when we change 'a' to 'b' and 'b' to 'a'.
"aa" "aa" 2 Returns: 2
We must change both letters 'a' to some other letters. Changing them to 'b' results in the smallest distance.
"aaa" "baz" 1 Returns: 1
"fdfdfdfdfdsfabasd" "jhlakfjdklsakdjfk" 8 Returns: 24
"aa" "bb" 2 Returns: 0
Submissions are judged against all 101 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ChangingString with a public method int distance(string A, string B, int K) · 101 test cases · 2 s / 256 MB per case