wronganswer.5's blog

By wronganswer.5, history, 19 months ago, In English

You are given a string s. You are allowed to do following operation any number of times: choose two characters in s say c1 and c2, replace all the occurences of c1 with c2 and all the occurences of c2 with c1. You want to make it lexographically smallest.

eg: s="bbcacad" ans: "aabbccd"

step1: choose a and b, we get -> aacbcbd step2: choose b and, we get -> aabcbcd

eg2: s="bdea" ans: "abde"

How to solve this question?

  • Vote: I like it
  • -9
  • Vote: I do not like it

| Write comment?