Company: Hackerearth_1nov
Difficulty: medium
K Frequency Problem Description You are given a string S made of lowercase English alphabets. Find the character having the K th largest frequency. If there is more than one character that meets the condition, print the smallest one. If there is no character that meets the condition print -1. Input format The first line consists of a single integer, T, denoting the number of test cases. The first line of each test case consists of a single string made of lower case English alphabets. The second line of each test case consists of a single integer denoting K. Output format Print the required answer for each test case in a new line. Examples Example 1: Input: 2 aabcd 3 aabcd 2 Output: b -1 Explanation: In string "aabcd", character having largest frequency is 'a' with frequency 2. and characters having second largest frequency are 'b', 'c' and 'd' with frequency 1. Constraints 1 <= T <= 10 1 <= |S| <= 10 5 1 <= K <= 26 Note Your code must be able to print the sample outpu