In this lesson, Alvin explores the strategy to solving the following interview problem:
Write a function sum_numbers_recursive that takes in an array of numbers and returns the sum of all the numbers in the array. All elements will be integers. Solve this recursively.
sum_numbers_recursive([5, 2, 9, 10]); # -> 26
sum_numbers_recursive([1, -1, 1, -1, 1, -1, 1]); # -> 1
sum_numbers_recursive([]); # -> 0
sum_numbers_recursive([1000, 0, 0, 0, 0, 0, 1]); # -> 1001
If you need additional support taking these DSA skills and actually applying them, take Alvin's complete data structures and algorithms course on Structy. You can try out the concepts yourself in their interactive code editor and learn advanced DSA patterns like stack exhaustive recursion.
Use this link to get 20% off the entire Structy DSA learning experience.
Follow Alvin on LinkedIn: https://www.linkedin.com/in/alvin-zablan-b73a92117/