21/10/19, 11(03 pm
Problem Statement
If X and Y are two Strings of equal length N, then the difference between them is defined as the number of indices i where the i-th character of X and the i-th character of Y are different. For example, the difference between the words “ant” and “art” is 1.
You are given two Strings, A and B, where the length of A is less than or equal to the length of B. You can apply an arbitrary number of operations to A, where each operation is one of the following:
Choose a character c and add it to the beginning of A. Choose a character c and add it to the end of A.
Apply the operations in such a way that A and B have the same length and the difference between
them is as small as
Definition
possible. Return this minimum possible difference.
Class:
Method:
Parameters:
Returns:
Method signature:
(be sure your method is public)
DifferentStrings minimize String, String int
int minimize(String A, String B)
Constraints
– A and B will each contain between 1 and 50 characters, inclusive.
– A and B will both contain only lowercase letters (‘a’-‘z’).
– The length of A will be less than or equal to the length of B.
Examples
0)
1)
“koder”
“topcoder”
Returns: 1
You can prepend “top” to “koder” and you’ll get “topkoder”. The difference between “topkoder” and “topcoder” is 1.
“hello”
https://cs.adelaide.edu.au/users/second/pssd/15s2-pssd-adelaide/week10practice/DifferentStrings/content.php Page 1 of 2
21/10/19, 11(03 pm
“xello”
Returns: 1
A and B already have the same length so you cannot add any characters to A. 2)
“abc”
“topabcoder”
Returns: 0
3)
4)
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2006, TopCoder, Inc. All rights reserved.
“adaabc”
“aababbc”
Returns: 2
“giorgi”
“igroig”
Returns: 6
https://cs.adelaide.edu.au/users/second/pssd/15s2-pssd-adelaide/week10practice/DifferentStrings/content.php Page 2 of 2
Reviews
There are no reviews yet.