AlgoUniversity
  • Go Back
Discussion
Second Most Frequent Character :

Author

Gigaliths

Difficulty Level : Easy

Submissions : 672

Asked In : Amazon Qualcomm

Marks :10

: 3 | : 0

Given a non-empty string, find out the character that has second-highest frequency of occurrence in the string.

If there are no such characters, print -1

If there are multiple such characters, print the lexicographically smallest of them. ( As per their ASCII value)

Input

First line contains a single integer corresponding to integer N. ( Size of string )

Second line contains N-sized string.

Constraints

$$$ 1 \le N \le 1000000 $$$

The characters in the string could be any valid ASCII character.

Output

A single character having the second-highest frequency and lexicographically smallest if there are multiple characters of the same frequency.

Examples

Input
aaaaaa
Output
-1
Input
nkslanfaaboutcec
Output
c
Input
`SgkEBzNnH
Output
-1

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.