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

 

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

Write a method that determines if the target value can be met using some combination of numbers from an array as a "weighted sum" of those numbers. By "weighted sum" I mean that each number in the array counts as its value times its position in the array, but with the first element in the array counting as position 1 (not 0). For example, the maximum "weighted sum" of {3,10,50} is 173 since 3+20+150=173. In more detail, 1*3+2*10+3*50=173. There are other possible "weighted sums" for this array because you can choose to use or not use each element in the array. So another "weighted sum" for {3,10,50} is 23, because 1*3+2*10=23. Another possibility is 150 since 3*50=150. I highly recommend using a helper method and backtrack recursion. My helper method included an additional parameter indicating the current position in the array to consider. You are NOT required to use a helper method or recursion, but it is HIGHLY recommended.


nov3_2017_HL_weightedTarget([7], 7) → true
nov3_2017_HL_weightedTarget([], 8) → false
nov3_2017_HL_weightedTarget([5, 4, 3, 6, 2], 29) → true

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

public boolean nov3_2017_HL_weightedTarget(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