addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

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

Solution to last nights topcoder challenge

Daniel H.
user 11568757
New York, NY
Post #: 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:­

def string="RRRRRR"
def string0="BBBYYYYYY"
def string1="RGGBBBRYYB"

def helper (a)

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)
sum += helper(seqLen)
seqLen = 1
prevChar = charArr

sum += helper(seqLen)

assert meetup(string)==3
assert meetup(string0)==4
assert meetup(string1)==3
A former member
Post #: 5
Awesome! Thx Daniel and Konstantin.
Powered by mvnForum

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy