Show problems as
Classic problem #2553EasyArraySimulation

Separate the Digits in an Array

Real-world version: Digit Cells for the Ticket Codes
Tracked in this browser only
Read Separate the Digits in an Array on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

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