Separate the Digits in an Array
Real-world version: Digit Cells for the Ticket CodesThe 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.
def digit_cells(codes: list[int]) -> list[int]:public int[] digitCells(int[] codes)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Concatenation of ArrayReal-world version: Two Cycle PlayoutEasy
- Reshape the MatrixReal-world version: Relaying the Contact SheetEasy
- Distribute Elements Into Two Arrays IReal-world version: Splitting Parcels Onto Two Intake TraysEasy
- Transpose MatrixReal-world version: Flip a Reading Grid Onto Its SideEasy