CodeChef: April Long Challenge | Strong Language | SSCRIPT | Solution

Codechef

View on Codechef

A string is said to be using strong language if it contains at least KK consecutive characters ‘*’.

You are given a string SS with length NN. Determine whether it uses strong language or not.

Input

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • The first line of each test case contains two space-separated integers NN and KK.
  • The second line contains a single string SS with length NN.

Output

Print a single line containing the string "YES" if the string contains strong language or "NO" if it does not (without quotes).

You may print each character of each string in uppercase or lowercase (for example, the strings “yEs”, “yes”, “Yes” and “YES” will all be treated as identical).

Constraints

  • 1≤T≤101≤T≤10
  • 1≤K≤N≤1061≤K≤N≤106
  • SS contains only lowercase English letters and characters ‘*’
  • Sum of NN over all testcases is atmost 106106.

Codechef Subtasks

Subtask #1 (30 points): N≤104N≤104, Sum of NN over all testcases is atmost 104104

Subtask #2 (70 points): original constraints

Example Input

3
5 2
*a*b*
5 2
*a**b
5 1
abcde

Example Output

NO
YES
NO

Explanation

Example case 1: Since there are no two consecutive characters ‘*’, the string does not contain strong language.

Example case 2: There are two adjacent characters ‘*’, so the string contains strong language.

Example case 3: Since there are no characters ‘*’ in the string, it does not contain strong language.

#include <iostream>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; i++)
    {
        int n, k;
        cin >> n >> k;
        string str;
        cin >> str;
        int c = 0;
        for (int v = 0; v < n; v++)
        {
            if (str[v] == '*')
            {
                c++;

                if (c >= k)
                {
                    cout << "YES" << endl;
                    break;
                }
            }

            else
            {
                c = 0;
            }
            if (v == n - 1)
            {
                cout << "NO" << endl;
            }
        }
    }
    return 0;
}

See more posts here