Count Palindromic Subsequences
Real-world version: Five-Digit Mirror PicksThe statement here is our own: the same inputs, outputs and technique.
A cloakroom prints a strip of digits on every ticket. The strip is given as the string strip, made up of digit characters.
A pick marks five positions of the strip and reads the digits sitting there from the lowest marked position to the highest. A pick is a mirror pick when the five digits it reads are unchanged by reading them the other way round, that is, when the first digit equals the fifth and the second equals the fourth. The digit in the middle is under no such condition.
Two picks count as different when the sets of positions they mark are different, even if both read the same five digits. Return the number of mirror picks as a remainder modulo 10^9 + 7.
Examples
Example 1
- Input
- strip = "48284"
- Output
- 1
The strip has exactly five positions, so there is one pick, and the digits 4, 8, 2, 8, 4 it reads are unchanged the other way round.
Example 2
- Input
- strip = "222222"
- Output
- 6
Any five of the six positions read 22222, and there are six ways to leave one position unmarked, so six different position sets qualify.
Example 3
- Input
- strip = "1027301"
- Output
- 3
Positions 0, 1, 5 and 6 carry 1, 0, 0 and 1, and marking any one of positions 2, 3 or 4 alongside them reads 10201, 10701 and 10301.
Constraints
- 1 <= strip.length <= 10^4
- strip consists of digit characters only
- Return the count modulo 10^9 + 7
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_mirror_picks(strip: str) -> int:public int countMirrorPicks(String strip)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 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