Trains the technique from
LeetCode 967Numbers With Same Consecutive DifferencesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A site office issues badge codes. A code is a whole number written with exactly size digits, and the badge printer refuses a code whose first digit is 0, so no code may carry a leading zero.
The office also insists that neighbouring digits step by a fixed amount: for every pair of digits standing next to each other in the code, the absolute difference between them must equal gap exactly. A difference smaller or larger than gap is rejected, and the step may go up or down at each position.
Return every badge code the office would accept, as integers, in any order. When gap is 0 each digit has to match the one before it, so exactly one code exists per leading digit.
Example 1
Every listed code has two digits whose absolute difference is 7: 1 and 8, 2 and 9, 7 and 0, 8 and 1, 9 and 2. The pair 0 and 7 also differs by 7 but `07` would start with a zero, so it is not a code.
Example 2
A gap of 0 forces every digit to equal the digit before it, so each code is one digit written four times. `0000` is left out because a code may not begin with 0.
Example 3
The only two digits nine apart are 0 and 9, so the digits have to alternate between them, and the code cannot begin with 0.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def badge_codes(size: int, gap: int) -> list[int]:public int[] badgeCodes(int size, int gap)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.