PLEASE HELP ME IN PERIODIC

Let's define a periodic infinite sequence S (0-indexed) with period K using the formula Si=(i%K)+1.

Chef has found a sequence of positive integers A with length N buried underground. He suspects that it is a contiguous subsequence of some periodic sequence. Unfortunately, some elements of A are unreadable. Can you tell Chef the longest possible period K of an infinite periodic sequence which contains A (after suitably filling in the unreadable elements) as a contiguous subsequence?

Example Input
3
3
-1 -1 -1
5
1 -1 -1 4 1
4
4 6 7 -1
Example Output
inf
4
impossible
.
Last edited on
This guy's account needs to be deleted.
Topic archived. No new replies allowed.