line into non-empty pieces p1, p2, …, pk that read back the original string when written in order, and make the cut a mirror: the first piece equals the last, the second equals the second to last, and so on, so p_i == p_{k - i + 1} for every i. With an odd number of pieces, the middle piece can be anything.
Return the largest possible number of pieces k.line="redbluered" → 3
Cut it as (red)(blue)(red): the first piece equals the last one and the middle piece stands alone. Three is the most possible.
line="abcd" → 1
No prefix matches a suffix of the same length, so the only option is the whole string as one piece.
line="kayak" → 5
(k)(a)(y)(a)(k): every letter becomes its own piece.
line consists of lowercase English lettersline="redbluered"
3
Run checks the first 3 tests in your browser. Submit checks all 184 tests on the server, hidden ones included.