List Numbers Whose Neighboring Digits Differ by One

Quick Overview

List Numbers Whose Neighboring Digits Differ by One. Return all integers in the inclusive interval[low,high] whose adjacent decimal digits differ in absolute value by exactly1.

List Numbers Whose Neighboring Digits Differ by One

Company: eBay

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Return all integers in the inclusive interval [low,high] whose adjacent decimal digits differ in absolute value by exactly 1. Single-digit numbers, including 0, satisfy this rule. Return the list in increasing order, with no leading-zero representations. ```cpp class Solution { public: vector<int> countSteppingNumbers(int low, int high); }; ``` ### Examples **Example 1:** ```text Input: low = 20, high = 35 Output: [21,23,32,34] Explanation: Each listed two-digit number has digit difference1; every other number in the range fails. ``` **Example 2:** ```text Input: low = 0, high = 0 Output: [0] Explanation: The sole candidate has no adjacent digit pair to violate the rule. ``` ### Constraints - `0 <= low <= high <= 2000000000`. ### Contract considerations The rule concerns decimal adjacent digits, not differences between consecutive returned numbers. ```hint Read the boundary condition Does the single-digit value zero meet the rule, and are both interval endpoints included? ``` ### Boundary reminders The rule concerns decimal adjacent digits, not differences between consecutive returned numbers.

Overview: List Numbers Whose Neighboring Digits Differ by One. Return all integers in the inclusive interval[low,high] whose adjacent decimal digits differ in absolute value by exactly1.

eBay logo
eBay
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return all integers in the inclusive interval [low,high] whose adjacent decimal digits differ in absolute value by exactly 1. Single-digit numbers, including 0, satisfy this rule. Return the list in increasing order, with no leading-zero representations.

class Solution {
public:
    vector<int> countSteppingNumbers(int low, int high);
};

Examples

Example 1:

Input: low = 20, high = 35
Output: [21,23,32,34]
Explanation: Each listed two-digit number has digit difference1; every other number in the range fails.

Example 2:

Input: low = 0, high = 0
Output: [0]
Explanation: The sole candidate has no adjacent digit pair to violate the rule.

Constraints

  • 0 <= low <= high <= 2000000000 .

Contract considerations

The rule concerns decimal adjacent digits, not differences between consecutive returned numbers.

Boundary reminders

The rule concerns decimal adjacent digits, not differences between consecutive returned numbers.