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

 

jebbert@volusia.k12.fl.us > finalExam2014Buckets
prev  |  next  |  chance

Write a method that returns 'true' if it is possible to reach the 'target' number of gallons by filling some or all of the buckets in the 'sizes' array. Return 'false' otherwise. For example, if the sizes array is {5,7,12,3} that represents having buckets of 5 gallons, 7 gallons, 12 gallons, and 3 gallons. Note that there are many possible targets that can be reached with these buckets such as: 5, 7, 12, 3, but also 8 (5+3), 10 (7+3), 15 (12+3), 27 (5+7+12+3), and other targets. But notice that it is not possible to have 11 gallons from these buckets (for example). It is also not possible to have any amount greater than 27 gallons since it takes all the buckets to get to 27 gallons. Your solution may use recursion, but it is NOT required. However, if you do decide to write a recursive solution, a helper method could be VERY useful! In fact, this is nicely solved using a single helper method with backtrack recursion.


finalExam2014Buckets([1, 10, 100, 1000], 1111) → true
finalExam2014Buckets([1, 10, 100, 1000], 123) → false
finalExam2014Buckets([5, 7, 20, 50], 32) → true

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

public boolean finalExam2014Buckets(int[] sizes, 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: 420

Copyright Nick Parlante 2017 - privacy