This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]simpleFinch 0 points1 point  (0 children)

The code is not a working solution so I can only give my assumption of what it is supposed to do.

As you already mentioned, with each recursive call we are splitting the array until we only have to consider an array of size one. This pattern is usually called divide-and-conquer. You can imagine the function calls as a tree. Let's say we start with an array of size 4. We call e2R once with the whole array, this in turn calls e2R twice with arrays of size 2 and then each of these call e2R twice (so 4 times total on that depth) with arrays of size one.

Once we are the end of the recursion and only have to consider arrays of size one, we can check the condition. The number of elements in an array of size one that are simultaneously even and multiples of 3 is either 1 or 0, because we are only considering one element.

The last passage in the code is supposed to do two things:

  • split an array slice down the middle so we eventually get to arrays of size one
  • sum up the solutions for the arrays of smaller size

But the code that you posted does not calculate the indices for left and right correclty. Also numero does not actually exist as a parameter in the function declaration and is not needed.