Problem Statement
You will be given 2 numbers start and finish each with the same number of digits. Both may have leading zeros. You are going to transform start into finish using the following kinds of transformation steps:
- 1) Increment a digit less than 9 by 1. For example, changing 354 to 364.
- 2) Decrement a digit greater than 0 by 1. For example, changing 354 to 254.
- 3) Swapping two digits. For example, changing 354 to 453.
Definition
- Class:
- NumberChanger
- Method:
- transform
- Parameters:
- String, String
- Returns:
- int
- Method signature:
- int transform(String start, String finish)
- (be sure your method is public)
Constraints
- start will contain between 1 and 8 characters inclusive.
- Each character in start will be a digit ('0'-'9').
- finish will contain the same number of characters as start.
Examples
"01234567"
"01234567"
Returns: 0
No steps required."11119999"
"99991111"
Returns: 4
4 swaps does the trick."55555555"
"12345678"
Returns: 16
Swapping is of no use here."77771111"
"00446688"
Returns: 16
"12"
"30"
Returns: 3