Monday, July 22, 2013

Optimize the cost of concatenation of all these strings into one big string.

You have n strings with their lengths. You are given an add(string s1,string s2) which would concatenate the string s2 with s1 and return s3. Optimize the cost of concatenation of all these strings into one big string.
Eg: 1,5,2 are the lengths of given strings.
1+5=6
6+2=8
total cost=14 can you Optimize this total cost?

Source : Sent by a reader named rahul.

No comments :