Problema
Ver traduçãoCount integers from left through right, including both endpoints, that have no equal neighboring digits. Use their usual decimal writing with no leading zeroes. Zero and all other single-digit numbers qualify.
Implement counting_numbers(left, right).
Input
left: The first allowed value.
right: The last allowed value.
Output
Return how many values satisfy the rule.
Restrições
0 ≤ left ≤ right ≤ 10¹⁸. The range may be too large to inspect each integer individually.
Exemplos
Entrada:
left = 10
right = 15
Saída esperada:
expected = 5
Entrada:
long long left = 10;
long long right = 15;
Saída esperada:
long long expected = 5;
Entrada:
long left = 10;
long right = 15;
Saída esperada:
long expected = 5;
Explicação
Only 11 has equal neighboring digits. The other five numbers qualify.
Entrada:
left = 0
right = 9
Saída esperada:
expected = 10
Entrada:
long long left = 0;
long long right = 9;
Saída esperada:
long long expected = 10;
Entrada:
long left = 0;
long right = 9;
Saída esperada:
long expected = 10;
Explicação
All ten values have just one digit and therefore no equal neighbors.
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.