#C11773. Longest Substring with K Distinct Characters

    ID: 41126 Type: Default 1000ms 256MiB

Longest Substring with K Distinct Characters

Longest Substring with K Distinct Characters

Given a string \( s \) and an integer \( k \), find the longest contiguous substring of \( s \) that contains exactly \( k \) distinct characters. The answer should be the starting and ending indices (0-indexed) of this substring. If no valid substring exists, output \( -1 \) for both indices.

Note: A substring is a contiguous sequence of characters within the string. The solution should be efficient, using techniques such as the sliding window method.

inputFormat

The input is taken from standard input (stdin) and consists of two lines. The first line contains the string \( s \) and the second line contains the integer \( k \).

outputFormat

Output the starting and ending indices of the longest contiguous substring with exactly \( k \) distinct characters separated by a space. If no valid substring exists, output \( -1 \) twice.

## sample
eceba
2
0 2