python - a string that for every character in it, there exists all the characters which are alphabetically smaller than it before it -
how check string every character in it, there exists characters alphabetically smaller before e.g aab correct while aacb not, because second case, have 'c' 'b' not present before it. aac not correct not have 'b' before 'c'.
a pseudocode. works cases abac
too.
max = 'a' - 1 // character before 'a' char in string if char > max + 1 // bad string, stop algorithm end if char > max max = char end end
the idea need check character preceding current 1 alphabetically has occurred before. if have character e
, d
has occurred before, c
, b
, a
did too.
Comments
Post a Comment