Friday, October 23, 2015

MJ [45] Minimum Difference String

Question:
Given two strings s1 and s2. Switch two elements of s2 to maximally decrease the difference of s1 and s2.

Eg., s1 = "abc",
       s2 = "cba".
The difference of s1 and s2 are 2 because s1[0]!=s2[0] and s1[2]!=s2[2]. By switching s2[0] and s2[2], s2 becomes "abc". Then the difference between s1 and s2 is 0. Thus return [0, 2].

If s1 = "abc" and s2 = "cbe", it should also return [0, 2] because after switch s2[0] and s2[2] s2 becomes "ebc" and the difference between s1 and s2 is decreased by 1.

Ref
[1] http://www.mitbbs.com/article_t1/JobHunting/32961687_0_1.html

No comments:

Post a Comment