AmazonOA #30
Count Valid Splits
Estimated MediumJudge-ready
Topics (AI-labelled)HashingStringsPrefix & Ranges
Split a lowercase string into two non-empty contiguous parts. The split is valid if the number of distinct characters that appear in both parts is strictly greater than m. Find the number of valid splits.
Input
The first line contains the string (length 1..100000), and the second line contains m (0..26).
Output
Output a single integer, the answer.
Example 1
Input:
abbcac
1
Output:
2
Example 2
Input:
a
0
Output:
0
Example 3
Input:
aaaa
0
Output:
3
Example notes
Example 1: splitting as ab|bcac and abbc|ac gives the intersections {a,b} and {a,c}, each with 2 characters, so the answer is 2. Example 2: the string cannot be split into two non-empty parts, so the answer is 0. Example 3: at all three split points both sides contain a, which exceeds the threshold 0, so the answer is 3.
Editorial
Loading solution…