It failed when you encounter a string like “aaaaa..aa”. In that case, the running time will be n*n/2, which is not good enough. My guess is that if you can update your code with the linear algorithm, it will be fine.

I am working with it now too. ]]>

I tell about this task and your explanations to my friend and asked him, whether he can create an improved version of the problem at his web-site. He agreed to try.

See, here it is:

http://codeabbey.com/index/task_view/pythagorean-triples

The numbers there would be greater, over million, so that solution could be found only by your method, not by simply iterating over a and b… ðŸ™‚

Wouldn’t you mind mentioning you as a person who gives idea? If so, please check if your name is spelled correctly. Thanks a lot once more!

]]>I’ve tried to implement my solution as I promised – seems, the task is even bit simpler than I thought!

Counters are pointers to next bar which will be eaten by any of players. Also I maintain “time” counters for both of them, to determine whose time is to eat chocolate. It is a kind of greedy algorithm I think.

I’m sorry I do not know how to paste code here. That’s the link to my submission:

]]>– Alice and Bob start consuming from opposite side of the array, not the same side.

– How would you handle partial cases, say at a given moment Alice finishes her’s when Bob is still eating.

– What would be the loop counter?

]]>