I got this code challenge:
You are living in a neighborhood with a lot of potholes. Given a string
strconsisting of:
- 'P' - denoting a pothole.
- '0' - denoting there is no pothole here, and neither at (i-1)st and (i+1)st positions.
- '1' - denoting there is no pothole here, and 1 pothole at either (i-1)st and (i+1)st position.
- '2' - denoting there is no pothole here, and 2 potholes at both (i-1)st and (i+1)st position.
- '?' - denoting that we don't know what is there. It could be '0', '1', '2' or 'P'.
Report the number of possible strings that can be made. In case the given input has conflicting information, report 0.
Use modulo for reporting the answer.
The input has the number of tests T on the first line. Each of the T next lines will have an input string.
Constraints
1 <= T <= 100 1 <= str <= 1e5Example
Input
2 ?01??? PP12Output
4 0
I got this question in an online test and I feel I almost reached the solution, but I'm unable to implement it even after spending lot of time on it. What would be the algorithm for this?