Decode Ways
Real-world version: Split The Swatch TapeThe statement here is our own: the same inputs, outputs and technique.
A colour lab keeps twenty-six swatches, numbered 1 through 26. When a batch is mixed, the machine punches the swatch numbers onto a paper tape one after another with no separator between them, so a batch of swatch 8 then swatch 15 comes out as the tape "815".
You are handed a finished tape as the digit string tape and have to work out how many batches could have punched it. A swatch number is punched with no padding, so no number on the tape may begin with 0, and every number must land in the range 1 to 26.
Return the count of batches that produce tape. Return 0 when the tape cannot have come from any batch.
Examples
Example 1
- Input
- tape = "2613"
- Output
- 4
The tape splits as 2,6,1,3 or 26,1,3 or 2,6,13 or 26,13, so four batches fit.
Example 2
- Input
- tape = "907"
- Output
- 0
The middle 0 cannot stand alone and 90 is past 26, so nothing accounts for it.
Example 3
- Input
- tape = "1120"
- Output
- 2
The trailing 0 has to join the 2 in front of it as 20, leaving 1,1,20 or 11,20.
Constraints
- 1 <= tape.length <= 100
- tape contains only digits and may begin with one or more zeros.
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 count_tape_readings(tape: str) -> int:public int countTapeReadings(String tape)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 16 test cases: 16 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