about | help | code help+videos | done | prefs |
This method MUST be done recursively. This is an example of BACKTRACK recursion. Write a method that returns the closest value you can get to 'target' WITHOUT GOING OVER, by adding numbers in the 'opts' array. For example, if opts={5,10,25} and target=34, the closest you can come without going over is 30, so you would return 30. Note: You cannot use numbers multiple times UNLESS those numbers appear in the array multiple times. I suggest making a helper method! test2021_02_25_BONUS_closeTarget([241, 49, 157, 75423, 421, 643, 685, 9852, 257, 864, 3258, 346, 768, 253, 5488, 362], 12000) → 12000 test2021_02_25_BONUS_closeTarget([3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27], 38) → 38 test2021_02_25_BONUS_closeTarget([2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24], 33) → 32 ...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: 430
Copyright Nick Parlante 2017 - privacy