#K33972. Repeated Substring Search
Repeated Substring Search
Repeated Substring Search
Problem Statement: Given a string \( S \) and an integer \( k \), determine whether there exists a substring of length \( k \) that appears at least twice in \( S \). In other words, if there is any contiguous sequence of characters with length \( k \) that occurs two or more times within \( S \), output YES
; otherwise, output NO
.
Example: For \( S = "abcabc" \) and \( k = 3 \), the substring "abc" appears twice, so the answer is YES
.
Note: If \( S \) is empty or its length is less than \( k \), then no such substring exists and the output should be NO
.
inputFormat
Input Format:
- The input is given via
stdin
as two lines. - The first line contains the non-empty string \( S \). The string consists of lowercase English letters and has no spaces.
- The second line contains an integer \( k \) representing the length of the substring to look for.
outputFormat
Output Format:
- Print
YES
tostdout
if there exists a substring of length \( k \) in \( S \) that appears at least twice. - Otherwise, print
NO
.
abcabc
3
YES