Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There are N houses (numbered from 0 to N-1) along a street. In each of them, recyclable trash (plastic, glass, metal) is collected into
There are N houses (numbered from 0 to N-1) along a street. In each of them, recyclable trash (plastic, glass, metal) is collected into separate bags. There are three trucks that collect the trash. Each of them collects a separate type of trash (the first collects plastic, the second, glass and the third, metal). All the trucks begin and end their jobs at the starting end of the street. Passing from the starting point to house number 0 takes D[0] minutes. Passing between houses number K-1 and K (for K in the range 1 to N-1) takes D[K] minutes. Loading one bag onto the truck takes one minute. For example, D = [2, 5] means that passing between the starting point and house number 0 takes 2 minutes and passing between houses number 0 and 1 takes 5 minutes. Each of the houses has already collected some bags (or possibly no bags) of recyclable trash. The number of bags that house number K has collected is recorded in string T[K], composed of letters 'P' (plastic), 'G' (glass) and 'M' (metal). For example, T[1] = "GMG" means that house number 1 has collected two bags of glass and one bag of metal. Each house may collect more than one bag of each type. All of the trucks start their jobs simultaneously. Each finishes its job after collecting all of the bags of the given type of trash and returning back to the starting point. What is the minimum number of minutes that will pass before all the trucks finish all the jobs? Write a function: class Solution public int solution (int [] D, String [] T); } that, given array D of N integers and array T of N strings, returns the minimum number of minutes needed by the trucks to finish I the jobs. Examples: 1. Given D= [2, 5], T = ["PGP", "M"], the function should return 15. The truck collecting plastic needs to go to house number 0, collect two bags and go back, which takes 2+1 +1 +2 = 6 minutes. The truck collecting glass needs 5 minutes: 2 minutes to go to house number 0, 1 minute to collect a bag and 2 minutes to return to the starting point. The truck collecting metal will go straight to house number 1, collect a bag and go back in 7 + 1 + 7 = 15 minutes. After 15 minutes all of the trash will have been collected and all trucks will have returned to the starting point. start PGP
Step by Step Solution
There are 3 Steps involved in it
Step: 1
There are N houses numbered from 0 to N1 along a street In each of them recyclable trash plastic glass metal is collected into separate bags There are ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started