#K56107. First Character Occurring K Times
First Character Occurring K Times
First Character Occurring K Times
Given a string S of length N and an integer K, find the first character in S that reaches exactly K occurrences when scanning the string from left to right. If no such character exists, output '#' (the hash symbol).
Formally, let S = s₁s₂...sₙ. Find the minimum index i such that the count of sᵢ in s₁, s₂, ..., sᵢ is equal to (K). If there is no such index, output '#'.
inputFormat
The input is read from standard input (stdin) and consists of two lines. The first line contains two integers N and K separated by a space. The second line contains the string S of length N.
outputFormat
Output to standard output (stdout) a single character — the first character in the string that reaches K occurrences. If no character reaches K occurrences, output '#' (without quotes).## sample
8 2
abbabcad
b