Carey Brown wrote:I don't see why you've turned this into a recursive problem
Carey Brown wrote:On line 42 you don't do anything with the newCount that is being returned.
Carey Brown wrote:The return at line 28 only unwinds the recursive calls one level and you eventually get back to a call you made on line 32, which, after the loops are exhausted will end up at the return at the very end.
Carey Brown wrote:I think you've got the gist of it now.
You can try
Piet Souris wrote:Indeed, nice and very readable. Here are two other ways that are O(n):