Tutte le sfide
Difficile 0 risolte 0% di accettazione

Count Numbers With Distinct Neighbors

Count range values whose adjacent decimal digits are never equal.

Count 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.

Vincoli

0 ≤ left ≤ right ≤ 10¹⁸. The range may be too large to inspect each integer individually.

Esempi

Esempio 1
Input:
left = 10
right = 15

Output atteso:
expected = 5
Input:
long long left = 10;
long long right = 15;

Output atteso:
long long expected = 5;
Input:
long left = 10;
long right = 15;

Output atteso:
long expected = 5;

Spiegazione

Only 11 has equal neighboring digits. The other five numbers qualify.

Esempio 2
Input:
left = 0
right = 9

Output atteso:
expected = 10
Input:
long long left = 0;
long long right = 9;

Output atteso:
long long expected = 10;
Input:
long left = 0;
long right = 9;

Output atteso:
long expected = 10;

Spiegazione

All ten values have just one digit and therefore no equal neighbors.

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.