#C1893. Nth Most Frequent Character

    ID: 45148 Type: Default 1000ms 256MiB

Nth Most Frequent Character

Nth Most Frequent Character

You are given a string ( s ) and an integer ( n ). Your task is to determine the ( n )-th most frequent character in the string.

The frequency of a character is the number of times it appears in ( s ). In case of a tie (i.e. multiple characters having the same frequency), the character that appears first in ( s ) (i.e. with the smallest index) should be chosen. If there are fewer than ( n ) distinct characters in ( s ), output an empty string.

Examples:

  • For \( s = "bbaacc" \) and \( n = 1 \), the output is b (since \( b \) appears most frequently).
  • For \( s = "bbaacc" \) and \( n = 4 \), the output is an empty string (because there are only 3 unique characters).

Note: All formulas are provided in ( \LaTeX ) format.

inputFormat

The input is given via standard input (stdin) and consists of two lines. The first line contains the string ( s ) (which may be empty), and the second line contains an integer ( n ).

outputFormat

Output the ( n )-th most frequent character in ( s ) using standard output (stdout). If there is no such character, output an empty string.## sample

bbaacc
1
b