Problema
Ver traduçãoAt each step, choose a nonzero decimal digit currently present in the number and subtract that digit. Digits are taken from the new value after every step. Find the minimum number of steps needed to reach zero.
Implement removing_digits(n).
Input
n: The positive starting number.
Output
Return the fewest subtraction steps.
Restrições
1 ≤ n ≤ 1,000,000. Subtracting zero is not a useful move and is excluded.
Exemplos
Entrada:
n = 14
Saída esperada:
expected = 3
Entrada:
long long n = 14;
Saída esperada:
long long expected = 3;
Entrada:
long n = 14;
Saída esperada:
long expected = 3;
Explicação
14 → 10 → 9 → 0 uses three steps. Neither possible first subtraction can reach zero in only two steps.
Entrada:
n = 7
Saída esperada:
expected = 1
Entrada:
long long n = 7;
Saída esperada:
long long expected = 1;
Entrada:
long n = 7;
Saída esperada:
long expected = 1;
Explicação
Subtract the only digit, 7, to reach 0 immediately.
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.