In: Computer Science
PLATFORM INDEPENDENCE
/* Java Program Example - Java Import Packages * package YOUR_CUSTOM_PACKAGE HERE;
(10 points) Given the uncertainty surrounding the outbreak of the Coronavirus disease (COVID-19) pandemic, our federal government has to work tirelessly to ensure the distribution of needed resources such as medical essentials, water, food supply among the states, townships, and counties in the time of crisis.
You are a software engineer from the Right Resource, a company that delivers logistic solutions to local and state entities (schools, institutions, government offices, etc). You are working on a software solution to check that given a set of resources, whether they can be proportioned and distributed equally to k medical facilities. Resources are represented as an array of positive integers. You want to see if these resources can be sub-divided into k facilities, each having the same total sum (of resources) as the other facilities. For example with resources = {1,2,3,4,5,6} we can sub-divide them into k = 3 medical facilities, each having the same total sum of 7: {1,6}, {2,5}, and {3,4}.
STARTER CODE
Write a solution method, canDistribute, that returns whether it is possible (true or false) that a given set of resources divides into k equal-sum facilities. You will solve this problem using a recursion:
public class HomeworkAssignment5_2 { public static void main(String[] args) { // just like any problems, whatever you need here, etc. } } class Solution { // YOUR STYLING DOCUMENTATION GOES HERE public boolean canDistribute(int[] resources, int groups) { // YOUR CODE HERE } }
EXAMPLES
input: {3,4,5,6}, 2
output: true
Explanation: {3,6}, {4,5}
input: {1}, 1
output: true
Explanation: {1}
input: {1, 3, 2, 3, 4, 1, 3, 5, 2, 1}, 5
output: true
Explanation: {3,2}, {4,1}, {5}, {2,3}, {1,3,1}
input: {1}, 4
output: false
Explanation: cannot split further with a value of 1 in resource.
CONSTRAINTS / ASSUMPTIONS
HINT