#K95152. Unique Substring Transformation
Unique Substring Transformation
Unique Substring Transformation
Given a string \( s \) and an integer \( k \), partition \( s \) into consecutive substrings (segments) of length \( k \) (except possibly the last segment, which may be shorter). For each segment, remove duplicate characters while preserving their first occurrence order and print the resulting substring on a new line.
Example:
Input: aabbbccccd 3 Output: ab bc c d
More examples are provided in the input/output description below.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains the string \( s \), which may consist of lowercase or uppercase letters.
- The second line contains an integer \( k \) which specifies the size of each segment.
outputFormat
For each segment obtained by dividing the string \( s \) into consecutive chunks of size \( k \) (the final chunk may be shorter), output a line with the transformed substring. The transformation is performed by retaining only the first occurrence of each character in the segment.
## sampleaabbbccccd
3
ab
bc
c
d
</p>