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:

  1. 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\).
  2. 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\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
16 votes
Tags:
AlgorithmsString SearchingString Algorithms
Points:20
3 votes
Tags:
String AlgorithmsReal worldAlgorithmsString Searching
Points:30
70 votes
Tags:
ReadyMathematicsMedium