algorithm - Beautiful String -


got question here. runtime of algorithm figure out bad. here question:

string s called unique if characters of s different. string s2 producible string s1, if can remove characters of s1 obtain s2.

string s1 more beautiful string s2 if length of s1 more length of s2 or have equal length , s1 lexicographically greater s2.

given string s have find beautiful unique string producible s.

input: first line of input comes string s having no more 1,000,000(10^6) characters. characters of s lowercase english letters.

output: print beautiful unique string producable s

sample input: babab

sample output: ba

what did this:

  1. take string , remove equal adjacent characters single one. example: input: "bbbbbab" output: "bab", output of step. becomes input next steps.
  2. now build array each unique character in string. array have indexes of occurrence in given input array.
  3. note first occurence of each element. find min , max of occurences. using iterate on possible strings can formed words ending @ index max. take lexicographically greatest.
  4. repeat above moving max.

i want correct , efficient algorithm can scale when input string big.

here set of implementations if inefficient, fork repo , make them more efficient.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -