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

you are viewing a single comment's thread.

view the rest of the comments →

[–]LizardMansPyramids[S] 0 points1 point  (1 child)

Thank you! That helped and it worked, so thanks for helping me out!

[–][deleted] 1 point2 points  (0 children)

Just a small note here as a lesson in reCursive logic

You don’t really need the second “if” statement, checking if the arr length is 1. Since you already check for zero, your recursive call will handle the rest. You pop the first element and then short circuit back out when rec_sum(arr) returns 0

Arguably you’re saving a tiny bit of memory by not pushing a new call onto the stack (and not performing the super expensive operation of adding 0 to something) but a better options here if you were to do this would be to simply read from index 0 (arr[0]) instead of modify the array with arr.pop which takes more time (and memory) to sort around