Strong Language (SSCRIPT) Solution — Codechef April Long Challenge

Anubhav Mishra
2 min readApr 12, 2021

--

Problem Statement

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

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

Input

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains two space-separated integers N and K.
  • The second line contains a single string S with length N.

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≤10
  • 1≤K≤N≤10⁶
  • S contains only lowercase English letters and characters ‘*’
  • Sum of N over all testcases is atmost 10⁶.

Subtasks

Subtask #1 (30 points): N≤10⁴, Sum of Nover all testcases is atmost 10⁴

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.

Code (Solution)

The code has been implemented in Java

/* package codechef; // don't place package name! */import java.util.*;import java.lang.*;import java.io.*;/* Name of the class has to be "Main" only if the class is public. */class Codechef{public static void main (String[] args) throws java.lang.Exception{Scanner sc = new Scanner(System.in);int t = sc.nextInt();while(t-- > 0){int n = sc.nextInt();int k = sc.nextInt();sc.nextLine();String str = sc.next();int count=0,cnti=0;for(int i=0;i<n;i++){if(str.charAt(i)=='*'){count++;if(count==k){System.out.println("YES");cnti++;break;}}elsecount =0;}if(cnti == 0)System.out.println("NO");}}}

Hope you would have liked the article. Please give 50 claps to this article and follow me for more future programming related blogs.

References

https://www.codechef.com/APRIL21C/problems/SSCRIPT

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Anubhav Mishra
Anubhav Mishra

Written by Anubhav Mishra

Software Engineer , Having my degree B.Tech in Information Technology from BVCOE, New Delhi. Love new Technologies. Electronic Dance Music is love.

No responses yet

Write a response