id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

hobbit5


Write a method that accepts a small array of positive integers and a target value. Return true if it is possible to "reach" the target, or false if it is not possible. Here are the rules for trying to "reach" the target: Start at zero. You can add or subtract any or all of the integers in the array in any order to reach the target. For any of the even integers, you can choose to add or subtract that number, or you can choose to add or subtract half of that number. For example, the array {6, 5, 14, 600, 121} can "reach" quite a few numbers. Here are some of those numbers and how we can reach them: 5 (just by using 5). -5 (just by using the opposite of 5). 11 (by adding 5+6). 297 (by using half of 600 minus half of 6). Look at the test data for further examples. You MIGHT want to write one or more helper-methods.


hobbit5([4, 5, 11, 20, 55], 65) → true
hobbit5([1, 2, 5, 6, 12, 20], 400) → false
hobbit5([7, 20, 17, 18, 44, 2], 33) → true

...Save, Compile, Run (ctrl-enter)

public boolean hobbit5(int[] nums, int target) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 490

Copyright Nick Parlante 2017 - privacy