Connection Status:
Competition Arena > ObtainingDigitK
SRM 367 · 2007-09-26 · by gevak · Greedy
Class Name: ObtainingDigitK
Return Type: int
Method Name: minNumberToAdd
Arg Types: (string, int)
Problem Statement

Problem Statement

Return the smallest non-negative integer that can be added to originalNumber such that the resulting integer contains at least one digit k. All numbers should have no extra leading zeroes.

Constraints

  • originalNumber will contain between 1 and 50 characters, inclusive.
  • originalNumber will contain only digits ('0'-'9').
  • originalNumber will represent a non-negative integer with no extra leading zeroes.
  • k will be between 0 and 9, inclusive.
Examples
0)
"153"
7
Returns: 4

153 + 4 = 157

1)
"158"
7
Returns: 9

158 + 9 = 167

2)
"7853192"
2
Returns: 0

Digit '2' is already present in the number.

3)
"99999999999999999999999999999999999999999999999"
0
Returns: 1

Add 1 to get a lot of zeroes.

4)
"519"
2
Returns: 1

Submissions are judged against all 250 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ObtainingDigitK with a public method int minNumberToAdd(string originalNumber, int k) · 250 test cases · 2 s / 256 MB per case

Submitting as anonymous