Kth Character

3.3

9 votes
Basic Programming, Basics of Implementation, Easy, Implementation, String Manipulation
Problem

You are given a string S of lowercase alphabets. Now you need to remove all the instances of exactly one type of character such that the new string that is formed is lexicographically smallest across all the other strings that can be formed in a similar way.

For example: Let the string S be "appleap"

  • If you remove all instances of 'a' then the string formed will be : pplep
  • If you remove all isntances of 'p' then the string formed will be : alea
  • If you remove all intsances of 'l' then the string formed will be : appeap
  • If you remove all instances of 'e' then the string formed will be : applap

So among all the newly formed strings , alea is lexicographically smallest string. 

Note : Lexicographically smallest means the string that would appear before all the strings if they were arranged in the order of words appearing in a dictionary.

Input
First line contains a string S as input

Output
Print the lexicographically smallest string that can be formed using the process above

Constraints
1|S|103 where |S| is the length of string
The string S will contain atleast two distinct characters.

Sample Input
appleap
Sample Output
alea
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The sample is explained in the problem statement.

Editor Image

?