A strongest string
Practice
2.9 (15 votes)
Algorithms
String manipulation
String manipulation
Problem
88% Success 1510 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a string \(S\) that consists of \(N\) lowercase letters of the Latin alphabet.
In one step, you can remove any letter in the string. You are required to determine the maximum lexicographic sentence of words you can leave so that all letters are different.
The lexicographical order on the set of all these finite words orders the words in the following manner:
- You are given two different words of the same length, for example, \(a = a_1,\ a_2,\ ..., a_k\) and \(b = b_1,\ b_2,\ ...,\ b_k\). The order of these two words depends on the alphabetic order of the symbols on the first place \(i\) where the two words are different (counting from the beginning of the words), \(a < b\) if and only if \(a_i < b_i\) in the underlying order of alphabet \(A\).
- If two words have different lengths, then the usual lexicographical order pads the shorter one with 'blanks' (a special symbol that is treated as smaller than every element of \(A\)) until the words are made of the same length. Now, the words are compared as in the previous case.
Input format
- The first line contains \(T\) denoting the number of test cases.
- The first line of each test case contains \(N\) denoting the length of string \(S\).
- The second line of each test case contains string \(S\).
Output format
For each test case, print the answer.
Constraints
\(1 ≤ T ≤ 10\\ 1 ≤ N ≤ 10^5\\ |S| = N\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
42 votes
Tags:
Data StructuresEasySortingString Manipulationapproved
Points:20
8 votes
Tags:
StringBrute ForceAlgorithmsString SearchingBinary SearchString Algorithms
Points:20
24 votes
Tags:
ApprovedEasyString Manipulation
Editorial