sebnukem
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
def strcat(a,b) { a+b }
def cost(ss) {
def c = 0;
println "${ss.size()} $c $ss"
while (ss.size() > 1) {
ss.sort{ it.size() }
def a = ss.remove(0)
def b = ss.remove(0)
c += a.size() + b.size()
ss += strcat(a,b)
println "${ss.size()} $c $ss"
}
c
}
def ss = ['a', 'bb', 'mmmmmm', 'ddd', 'sssssssss', 'ggggg', 'z']
cost(ss)
7 0 [a, bb, mmmmmm, ddd, sssssssss, ggggg, z]
6 2 [bb, ddd, ggggg, mmmmmm, sssssssss, az]
5 6 [ddd, ggggg, mmmmmm, sssssssss, bbaz]
4 13 [ggggg, mmmmmm, sssssssss, dddbbaz]
3 24 [dddbbaz, sssssssss, gggggmmmmmm]
2 40 [gggggmmmmmm, dddbbazsssssssss]
1 67 [gggggmmmmmmdddbbazsssssssss]
Result: 67
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
- sebnukem March 24, 2015