cswork / OAOpen practice workspace

YahooOA #1

Modify the String

Estimated MediumJudge-ready

Topics (AI-labelled)Stacks & HeapsGreedy

Delete repeated characters until all characters are distinct, and return the lexicographically largest order-preserving result.

See "Input" for the standard input/output conventions and constraints added by this site.

Input

A lowercase string of length 1..100000.

Output

Output the largest deduplicated subsequence.

Example 1

Input:

aabcb

Output:

acb

Example 2

Input:

bcabc

Output:

cab

Example 3

Input:

aaaa

Output:

a

Example 4

Input:

cbacdcbc

Output:

cbad

Editorial

Loading solution…