Garden Trouble
InterviewTime limit1sMemory limit128 MB
Find the longest contiguous segment of the garden that holds at most K chestnut trees.
- Level
Easy3 of 10
- Topics
- Sliding window, Two pointers
- Solved
- No attempts yet
Problem
Mr. Wincenty loves his garden dearly, but he really hates working in it, and above all he hates raking up the leaves that fall every autumn. After several years (and just as many autumns spent raking) Mr. Wincenty decided that enough was enough: his garden is simply too big. So he made up his mind to give part of his land to the neighbors (let them rake the leaves instead).
Mr. Wincenty's garden has an unusual shape. It is a rectangle of size , divided into consecutive cells of size . Each cell holds either grass or a single chestnut tree. Mr. Wincenty wants to keep as large a part of the garden as possible, subject to the following conditions:
- The kept part may contain at most chestnut trees.
- The kept part must be contiguous, that is, it must form a run of consecutive cells.
What is the maximum length of the garden fragment that Mr. Wincenty can keep?
Input
The first line contains the number of tests (). The descriptions of the individual tests follow.
Each test consists of two lines. The first line contains the natural numbers and ().
The second line describes the garden as a string of length . Each character of the string is either 'K' or 'T', depending on whether the corresponding cell holds a chestnut tree ('K') or only grass ('T').
Output
For each test, print on its own line the maximum length of the garden fragment that Mr. Wincenty can keep.