All problems
0500EasyArraySimulation

Digit Cells for the Ticket Codes

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2553Separate the Digits in an Array

This 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 cloakroom board shows ticket codes on a long strip of cells, one digit per cell.

The board works through codes from the first entry to the last. For each code it fills the next few cells with that code's digits, taken left to right as the code is written, and then carries straight on with the code after it. Nothing separates one code from the next on the strip.

Return the digits in the cells, in the order the board filled them.

Examples

Example 1

Input
codes = [4021, 7, 100000, 605]
Output
[4, 0, 2, 1, 7, 1, 0, 0, 0, 0, 0, 6, 0, 5]

The board fills 4, 0, 2, 1 for the first code, then a single cell with 7, then 1, 0, 0, 0, 0, 0 for the third code, then 6, 0, 5 for the last.

Example 2

Input
codes = [86, 4, 517, 20]
Output
[8, 6, 4, 5, 1, 7, 2, 0]

Reading the strip back gives 8, 6 then 4 then 5, 1, 7 then 2, 0, which is each code's digits in writing order with the codes still in their original order.

Example 3

Input
codes = [1005]
Output
[1, 0, 0, 5]

One code fills four cells, and the two zeros in the middle of the code each take a cell of their own.

Constraints

  • 1 <= codes.length <= 1000
  • 1 <= codes[i] <= 10^5

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def digit_cells(codes: list[int]) -> list[int]:
Java
public int[] digitCells(int[] codes)
September 7
Apply