# Algorithms and Data Structures

Algorithms and Data Structures Message Board › Solution to last nights topcoder challenge

# Solution to last nights topcoder challenge

 Daniel H. Posted 6/10/10 1:30 PM Link to discussion user 11568757 New York, NYPost #: 1 I wanted to post the solution devised by Konstantin. Konstantin provided the solution and I coded it in Groovy.it is posted below, and here in a pastie:http://www.pastie.org...­def string="RRRRRR"def string0="BBBYYYYYY"def string1="RGGBBBRYYB"def helper (a){ (int)(a/2)}def meetup(str){ charArr = str.toCharArray() if (charArr.length == 0){ return 0 } prevChar = charArr[0] seqLen = 1 sum = 0 for (int i=1; i < charArr.length; i++) { if (charArr == prevChar) seqLen++; else { sum += helper(seqLen) seqLen = 1 } prevChar = charArr } sum += helper(seqLen) sum}assert meetup(string)==3assert meetup(string0)==4assert meetup(string1)==3 A former member Posted 6/13/10 8:58 PM Link to reply Post #: 5 Awesome! Thx Daniel and Konstantin.

### New York, NY

Founded Jan 31, 2010

#### People in this Meetup are also in:

5,853 Haxors

• ##### The New York City Java Meetup Group

10,747 Java enthusiasts

• ##### NYLUG - New York Linux Users Group

5,727 Members

• ##### NY Tech Meetup

58,104 NYC Technologists

• ##### New York Web Performance Group

4,208 web speeders

• ##### nycdevops

2,436 nycdevops