seq. Cut it into three non-empty consecutive pieces A, B and C, so that A + B + C == seq.
A cut is good if at least one of these holds:
- A is a prefix of B;
- B is a prefix of C.
A piece counts as a prefix of itself. Return the number of good cuts.seq=[5, 1, 5, 1, 5] → 2
Two cuts work: [5, 1] | [5, 1] | [5], where the first piece starts the second, and [5] | [1, 5] | [1, 5], where the second piece starts the third.
seq=[3, 3, 3] → 1
There is only one cut, [3] | [3] | [3], and it works.
seq=[4, 7, 9] → 0
The only cut, [4] | [7] | [9], fails: all pieces differ.
seq=[5, 1, 5, 1, 5]
2
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.