GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday 7 June 2022

[Solution] Black and White Stripe Codeforces Solution

D. Black and White Stripe
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a stripe of checkered paper of length n. Each cell is either white or black.

What is the minimum number of cells that must be recolored from white to black in order to have a segment of k consecutive black cells on the stripe?

If the input data is such that a segment of k consecutive black cells already exists, then print 0.

Input

The first line contains an integer t (1t104) — the number of test cases.

Solution Click Below:-  CLICK HERE

Next, descriptions of t test cases follow.

The first line of the input contains two integers n and k (1kn2105). The second line consists of the letters 'W' (white) and 'B' (black). The line length is n.

It is guaranteed that the sum of values n does not exceed 2105.

Output

For each of t test cases print an integer — the minimum number of cells that need to be repainted from white to black in order to have a segment of k consecutive black cells.

No comments:

Post a Comment