#K63842. Maximum Length Subarray with Limited Plant Types

    ID: 31843 Type: Default 1000ms 256MiB

Maximum Length Subarray with Limited Plant Types

Maximum Length Subarray with Limited Plant Types

You are given a garden represented as a string of length \(N\) where each character represents a type of plant. In one contiguous subarray, you must determine the maximum length such that there are at most \(X\) different types of plants.

Problem Statement

Given an integer \(N\) denoting the length of the string, an integer \(X\) representing the maximum number of distinct plant types allowed, and a string of plants, find the length of the longest contiguous subarray that contains at most \(X\) distinct characters.

Example

Input: N = 7, X = 2, plants = "abaacba"
Output: 4

Explanation: The longest subarray with at most 2 distinct characters is "baac" with length 4.

</p>

inputFormat

The first line contains an integer \(T\) denoting the number of test cases. Each test case consists of the following:

  • A line containing two integers: \(N\) and \(X\).
  • A line containing the string of plants of length \(N\).

All input is read from standard input (stdin).

outputFormat

For each test case, output a single integer which is the length of the longest contiguous subarray that contains at most \(X\) distinct types of plants. Each result should be printed on a new line to standard output (stdout).

## sample
2
7 2
abaacba
5 3
bbcaa
4

5

</p>