I am doing a leetcode exercise
https://leetcode.com/problems/remove-duplicate-letters/
The question is:
# Given a string which contains only lowe
The smallest lexicographical order is an order relation where string s is smaller than t, given the first character of s (s1) is smaller than the first character of t (t1), or in case they are equivalent, the second character, etc.
So aaabbb
is smaller than aaac
because although the first three characters are equal, the fourth character b
is smaller than the fourth character c
.
For cbacdcbc
, there are several options, since b
and c
are duplicates, you can decided which duplicates to remove. This results in:
cbacdcbc = adbccbacdcbc= adcbcbacdcbc = badccbacdcbc= badc ...
since adbc
< adcb
, you cannot thus simply answer with the first answer that pops into your mind.