TopcoderArchive
Archive
Algorithm problem

DigitCorrections

Problem statement, definition, constraints, and public examples.

Problem Statement

Your company has built totalParts components and has evenly distributed them into numBins containers. Some of the digits in totalParts may be erroneous. Return the smallest number of digits that need to be changed in totalParts such that it is an integer multiple of numBins. You may not add or remove digits, but leading digits can be changed into zeros.

Definition

Class:
DigitCorrections
Method:
getMin
Parameters:
String, int
Returns:
int
Method signature:
int getMin(String totalParts, int numBins)
(be sure your method is public)

Constraints

  • totalParts will contain between 1 and 50 digits ('0'-'9'), inclusive.
  • The first character of totalParts will not be '0'.
  • numBins will be between 1 and 50000, inclusive.

Examples

  1. "22"
    100
    Returns: 2
    The only solution here is to change both digits to 0.
  2. "1004"
    25
    Returns: 1
    Changing 4 to 0 requires the fewest changes.
  3. "203"
    107
    Returns: 2
    Here we can change the last two digits to 14.
  4. "882349823048203948203948230948230498"
    49999
    Returns: 3
  5. "12345678901234567890123456789012345678901234567890"
    50000
    Returns: 4
Back to all problems