#K39317. Promotable Book Titles
Promotable Book Titles
Promotable Book Titles
You are given a list of book titles. A book title is said to be promotable if it contains any palindromic substring of length at least 3.
A palindromic substring is defined as a sequence of consecutive characters in the title that reads the same forwards and backwards. For example, in the title "racecar", the entire string is a palindrome, so it is promotable. However, a title like "book" does not contain any palindrome of length 3 or more.
Your task is to determine for each title whether it is promotable. For each title, output YES
if it is promotable, otherwise output NO
.
In mathematical terms, for a string s, you need to check if there exists indices i and j with \(j - i + 1 \ge 3\) such that \[ s[i \ldots j] = s[i \ldots j]^{T} \] where \(s[i \ldots j]^{T}\) denotes the reversal of the substring.
inputFormat
The input is read from stdin and has the following format:
...
The first line contains an integer n
(1 ≤ n ≤ 105), representing the number of book titles. Each of the following n
lines contains a non-empty string representing a book title.
outputFormat
For each book title, print a line to stdout containing YES
if the title is promotable or NO
otherwise.
3
racecar
book
hello
YES
NO
NO
</p>