460. Binary Audit Log Palindrome Validation
Binary Audit Log Palindrome Validation

An Atlassian Confluence audit log is represented by a string s containing '0', '1', and '?'. Each '?' marks an unresolved event.

Determine whether every '?' can be replaced with '0' or '1' so that the resulting string contains no palindromic substring of length 5 or greater. Existing '0' and '1' characters must remain unchanged.

A substring is a contiguous segment. A palindrome reads the same forward and backward.

Method Signature

String checkPossibility(String s)
  • s: the audit log to validate.
  • Return "POSSIBLE" if at least one valid replacement exists; otherwise, return "IMPOSSIBLE".
  • Return only the status string, even when multiple valid replacements exist.

Constraints

  • 1 ≤ s.length() ≤ 50,000
  • s contains only '0', '1', and '?'.
  • s is never null.

Examples

Example 1

Input: checkPossibility(s = "01??10?1")

Output: "POSSIBLE"

Explanation: One valid replacement is "01011001", which contains no palindromic substring of length 5 or greater.

Example 2

Input: checkPossibility(s = "10?01")

Output: "IMPOSSIBLE"

Explanation: The two replacements, "10001" and "10101", are both palindromes of length 5.

Example 3

Input: checkPossibility(s = "011110")

Output: "IMPOSSIBLE"

Explanation: The entire string is a palindrome of length 6, and no character can be changed.

Example 4

Input: checkPossibility(s = "?0?")

Output: "POSSIBLE"

Explanation: Replacing both unknown events with '0' gives "000". Its length is less than 5, so it is valid.



Please use Laptop/Desktop or any other large screen to add/edit code.