about | help | code help+videos | done | prefs |
Write a method that uses recursion to determine if it is possible to reach the target number, starting from 1, then adding or multiplying, or not using each number in the array of integers. For example, for the array {3, 5, 2, 19} it is possible to reach the target of 17 (1*3*5+2) or the target of 4 (1+3), but NOT the target of 13 since there is no way to start at one and get to 13 by adding or multiplying selected numbers from that array. In this problem you are keeping a RUNNING TOTAL as opposed to following the normal order of operations. For example, 1*3+5*2 is handled by completing the operations from LEFT to RIGHT without paying attention to the order of operations. So 1*3+5*2 is REALLY ((1*3)+5)*2). Note that you can choose to add or multiply or ignore each number, but you cannot change the ORDER of the numbers. So you could not do (1+19)*2 to get 40 (for example). You SHOULD use a helper method! reachTarget([2, 2, 2, 2, 2], 7) → true reachTarget([2, 2, 2, 2, 2], 767) → false reachTarget([3, 5, 2, 19], 17) → true ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 450
Copyright Nick Parlante 2017 - privacy