Split String
Practice
2.5 (4 votes)
Basics of greedy algorithms
Algorithms
Greedy algorithms
Problem
57% Success 937 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code
You are given a string \(S\). A string is called a split string if it follows both the conditions defined below:
- It can be divided into \(K\) contiguous substrings such that the first letter of these substrings is the same for all the substrings.
- It can be divided into \(K\) contiguous substrings such that the first letter of these substrings is distinct for all the substrings.
Print YES if \(S\) is a split string otherwise print NO.
Input Format:
- The first line contains an integer \(T\), denoting the number of test cases.
- The first line of each test case contains two integers \(N\) and \(K\).
- The second line of each test case contains a string \(S\), which consists of \(N\) lowercase English letters.
Output Format:
For each test case, print YES if \(S\) is a split string otherwise print NO.
Constraints:
\(1 <= T <= 10\)
\(1 <= K <= N <= 10^5\)
\(S\) consists of \(N\) lowercase English letters.
Submissions
Please login to view your submissions
Similar Problems
Points:20
17 votes
Tags:
Data StructuresEasyGreedy Algorithmsapproved
Points:20
74 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:20
90 votes
Tags:
AlgorithmsGreedy Algorithms
Editorial