about | help | code help+videos | done | prefs |
Write a method that uses backtrack recursion to determine if it is possible (or not) to reach the target total using any combination of numbers from the integer array being added or subtracted from the total. For example, it IS possible to reach the totals of 0, -2, 2, -38, 38, -40, 40, -42, and 42 from the array {2, 40}, but it is NOT possible to reach any other totals from that array. Look at the test data for further examples. Remember that there are three possibilities for each element in the array. You can ADD that number to the total, SUBTRACT that number from the total, or OMIT that number from the total. I highly recommend making a helper method for two reasons: #1 to prevent the recursive call from having to use the long method name that I used to name this method. #2 to add another parameter to the method call (but I will not tell you WHAT parameter to add) dec18_2017_HL_canReachTotal([500, 50, 5], 545) → true dec18_2017_HL_canReachTotal([500, 50, 5], 542) → false dec18_2017_HL_canReachTotal([235, 123, 546, 12, 675, 35, 241, 75, 325, 1, 2, 36, 7], -1031) → 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: 490
Copyright Nick Parlante 2017 - privacy