1 2 3 Task 2 Java 8 A group of friends is going on holiday together....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1 2 3 Task 2 Java 8 A group of friends is going on holiday together. They have come to a meeting point (the start of the journey) using N cars. There are P[K] people and S[K] seats in the K-th car for K in range [0..N-1]. Some of the seats in the cars may be free, so it is possible for some of the friends to change the car they are in. The friends have decided that, in order to be ecological, they will leave some cars parked at the meeting point and travel with as few cars as possible. Write a function: class Solution { public int solution(int[] P, int[] S); } that, given two arrays P and S, consisting of N integers each, returns the minimum number of cars needed to take all of the friends on holiday. Examples: 1. Given P = [1, 4, 1] and S = [1, 5, 1], the function should return 2. A person from car number 0 can travel in car number 1 instead. This way, car number 0 can be left parked at the meeting point. 2. Given P = [4, 4, 2, 4] and S = [5, 5, 2, 5], the function should return 3. One person from car number 2 can travel in car number 0 and the other person from car number 2 can travel in car number 3. 3. Given P = [2, 3, 4, 2] and S = [2, 5, 7, 2], the function should return 2. Passengers from car number 0 can travel in car number 1 and passengers from car number 3 can travel in car number 2. Write an efficient algorithm for the following assumptions: N is an integer within the range [1..100,000]; each element of arrays P and S is an integer within the range [1..9]; every friend had a seat in the car they came in; that is, P[K] S[K] for each K within the range [0..N-1]. Copyright 2009-2022 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited. Autocomplete is connected | All changes saved Files task2 solution.java test-input.txt Test Output || solution.java x // you can also use imports, for example: // import java.util.*; 1 2 3 4 5 6 7 8 9 10 11 12 // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { } public int solution (int[] P, int[] 5) { // write your code in Java SE 8 To leave editor use Ctrl + M Any problems with the editor? Switch to basic editor ? Run Code Give Feedback | 6:14 PM 1 2 3 Task 2 Java 8 A group of friends is going on holiday together. They have come to a meeting point (the start of the journey) using N cars. There are P[K] people and S[K] seats in the K-th car for K in range [0..N-1]. Some of the seats in the cars may be free, so it is possible for some of the friends to change the car they are in. The friends have decided that, in order to be ecological, they will leave some cars parked at the meeting point and travel with as few cars as possible. Write a function: class Solution { public int solution(int[] P, int[] S); } that, given two arrays P and S, consisting of N integers each, returns the minimum number of cars needed to take all of the friends on holiday. Examples: 1. Given P = [1, 4, 1] and S = [1, 5, 1], the function should return 2. A person from car number 0 can travel in car number 1 instead. This way, car number 0 can be left parked at the meeting point. 2. Given P = [4, 4, 2, 4] and S = [5, 5, 2, 5], the function should return 3. One person from car number 2 can travel in car number 0 and the other person from car number 2 can travel in car number 3. 3. Given P = [2, 3, 4, 2] and S = [2, 5, 7, 2], the function should return 2. Passengers from car number 0 can travel in car number 1 and passengers from car number 3 can travel in car number 2. Write an efficient algorithm for the following assumptions: N is an integer within the range [1..100,000]; each element of arrays P and S is an integer within the range [1..9]; every friend had a seat in the car they came in; that is, P[K] S[K] for each K within the range [0..N-1]. Copyright 2009-2022 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited. Autocomplete is connected | All changes saved Files task2 solution.java test-input.txt Test Output || solution.java x // you can also use imports, for example: // import java.util.*; 1 2 3 4 5 6 7 8 9 10 11 12 // you can write to stdout for debugging purposes, e.g. // System.out.println("this is a debug message"); class Solution { } public int solution (int[] P, int[] 5) { // write your code in Java SE 8 To leave editor use Ctrl + M Any problems with the editor? Switch to basic editor ? Run Code Give Feedback | 6:14 PM
Expert Answer:
Related Book For
Accounting Principles
ISBN: 9781119707110
14th Edition
Authors: Jerry J. Weygandt, Paul D. Kimmel, Jill E. Mitchell
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Part A: The following departments of activities are recorded in the City of Atlantas Comprehensive Annual Financial Report in the appendix to this chapter. Indicate the type of fund that most likely...
-
The Statement of Net Position of South State University, a governmentally owned university, as of the end of its fiscal year June 30, 2016, follows. The following information pertains to the year...
-
Stacey's Piano Rebuilding Company has been operating for one year (2019). At the start of 2020, its statement of earnings accounts had zero balances and the account balances on its statement of...
-
How can a judgment creditor obtain funds in a judgment debtors bank account?
-
Junkyard Arts, Inc., had earnings of $316,000 for 2014. The company had 40,000 shares of common stock outstanding during the year. In addition, the company issued 15,000 shares of $50 par value...
-
The production of the shoes depends on the number of order per bulk of customer of OTTO Manufacturing. Everyday, there is a set of desired output that each production line needs to meet. As per the...
-
Amexicorp, Inc., a producer of security systems, had sales of $400 million, cost of goods sold of $150 million, operating expenses of $100 million, and interest expense of $100 million. Amexicorp...
-
Your employer gives you a stock bonus of $1,000 in your company at the end of each year. You plan to retire in 20 years. The stock has a growth rate of 15 percent per annum. What will the value of...
-
Adieu Company reported the following current assets and current liabilities for two recent years: Dec. 31, 20Y4 Dec. 31, 20Y3 Cash Temporary investments Accounts receivable Inventory Accounts payable...
-
The constraints / limitations of food festival in Malaysia with real-world examples. Explain about the possible hurdles or limitations that needed to face with references. For instance, you could...
-
Suppose that the Australian rate of inflation is 3%, and the German rate of inflation is 2%. If the euro strengthens relative to AUD by 7%, what would be the magnitude of the real appreciation of the...
-
The following you don't need to rearrange using rules, you can just plug into your calculator to get the answer. Round to 3 decimal places: f) 250 g) 1.2 83.7 h) -5 i) 28
-
Consider the seventh excited level of the hydrogen atom. A)What is the energy of this level? B)What is the largest magnitude of the orbital angular momentum? C)What is the largest angle between the...
-
When you have more than one agile team working on a single product, which one of the following should be considered? Select only one answer. All learns need to have similar agile maturity. Teams must...
-
When the Department of Homeland Security created a color-coded system to prepare government officials and the public against terrorist attacks, what did it do right and what did it do wrong?
-
The following are two independent situations. 1 . Gambino Cosmetics acquired 10% of the 200,000 shares of common stock of Nevins Fashion at a total cost of $13 per share on March 18, 2022. On June...
-
Talkington Electronics issues a $400,000, 8%, 15-year mortgage note on December 31, 2021. The proceeds from the note are to be used in financing a new research laboratory. The terms of the note...
-
Cash of $100 received at the time the service was performed was journalized and posted as a debit to Cash $100 and a credit to Accounts Receivable $100. Assuming the incorrect entry is not reversed,...
-
Flow occurs in a rectangular channel of \(6 \mathrm{~m}\) width and has a specific energy of \(3 \mathrm{~m}\). Plot accurately the relation between depth and specific energy. Determine from the...
-
A rectangular channel carries a discharge of \(10 \mathrm{ft}^{3} / \mathrm{s}\) per foot of width. Determine the minimum specific energy possible for this flow. Compute the corresponding flow depth...
-
Flow in the channel of Problem 11.15 has a specific energy of \(4.5 \mathrm{ft}\). Compute the alternate depths for this specific energy. Data From Problem 11.15 11.15 A rectangular channel carries a...
Study smarter with the SolutionInn App