Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Recursive Count Expressions Reaching a Target Sum

Given an array of non-negative integers and an integer target, count in how many ways can you create an expression putting either + or - in-front of each number to reach the target expression.

def count_target_expressions(numbers, target):

For exampl count_target_expressions([1, 1, 1, 1, 1], 3) should return 5 and count_target_expressions([2, 3, 5], 0) should return 2.

See also here.