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

 

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

Write a method that accepts an array of integers that represents a square 4 by 4 array of integers, and an integer to use as a target. Return true if it is possible to reach the target, false otherwise. How do you reach the target? Simple! The target is "reached" if it is possible to select any one number from each row and have the selected numbers add up to the target. Each row must provide a number. For example, with the following square array there are many targets that could be reached. 3 5 2 4 8 1 4 7 5 9 1 6 2 0 4 3 For example, 3+8+5+2=18 so if 18 was the target, the method would return true. Here are some other examples that would return true for the above matrix: 3+1+1+0=5. 4+7+9+4=24. 2+8+5+4=19.


canReachTarget([4, 2, 1, 7, 3, 0, 5, 6, 1, 8, 8, 2, 6, 7, 0, 0], 18) → true
canReachTarget([1, 2, 1, 3, 7, 6, 8, 9, 4, 3, 5, 2, 6, 7, 8, 9], 24) → true
canReachTarget([1, 2, 1, 3, 7, 6, 8, 9, 4, 3, 5, 2, 6, 7, 8, 9], 27) → false

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

public boolean canReachTarget(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: 260

Copyright Nick Parlante 2017 - privacy