can anyone help with solution in python or java ? 2. Busy intersection There is a busy
Fantastic news! We've Found the answer you've been seeking!
Question:
can anyone help with solution in python or java ?
Transcribed Image Text:
2. Busy intersection There is a busy intersection between two one-way streets: Main Street and 1st Avenue. Cars passing through the intersection can only pass through one at a time. When multiple cars arrive at the intersection at the same time, two queues can build up -- one for each street. Cars are added to the queue in the order at which they arrive. Unfortunately, there is no traffic light to help control traffic when multiple cars arrive at the same time. So, the local residents have devised their own system for determining which car has priority to pass through the intersection: If in the previous second, no car passed through the intersection, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on 1st Avenue, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on Main Street, then the first car in the queue for Main Street goest first. Passing through the intersection takes 1 second. For each car, find the time when they will pass through the intersection. Function Description Complete the function getResult in the editor below. getResult has the following parameters: int arrival[n]: an array of n integers where the value at index/is the time in seconds when the th car arrives at the intersection. If arrival[i] = arrival[j] and i<j, then car i arrives before car j. int street[n]: an array of n integers where the value at index/is the street on which the th car is traveling: 0 for Main Street and 1 for 1st Avenue. Returns: int[n]: an array of n integers where the value at index/is the time when the th car will pass through the intersection Constraints 1sns105 Os arrival[i] ≤ 109 for Osisn-1 2. Busy intersection There is a busy intersection between two one-way streets: Main Street and 1st Avenue. Cars passing through the intersection can only pass through one at a time. When multiple cars arrive at the intersection at the same time, two queues can build up -- one for each street. Cars are added to the queue in the order at which they arrive. Unfortunately, there is no traffic light to help control traffic when multiple cars arrive at the same time. So, the local residents have devised their own system for determining which car has priority to pass through the intersection: If in the previous second, no car passed through the intersection, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on 1st Avenue, then the first car in the queue for 1st Avenue goes first. • If in the previous second, a car passed through the intersection on Main Street, then the first car in the queue for Main Street goest first. Passing through the intersection takes 1 second. For each car, find the time when they will pass through the intersection. Function Description Complete the function getResult in the editor below. getResult has the following parameters: int arrival[n]: an array of n integers where the value at index/is the time in seconds when the th car arrives at the intersection. If arrival[i] = arrival[j] and i<j, then car i arrives before car j. int street[n]: an array of n integers where the value at index/is the street on which the th car is traveling: 0 for Main Street and 1 for 1st Avenue. Returns: int[n]: an array of n integers where the value at index/is the time when the th car will pass through the intersection Constraints 1sns105 Os arrival[i] ≤ 109 for Osisn-1
Expert Answer:
Related Book For
Statistical Techniques in Business and Economics
ISBN: 978-1259666360
17th edition
Authors: Douglas A. Lind, William G Marchal
Posted Date:
Students also viewed these programming questions
-
: Write code in the next cell to do the following: 1. Asks the user for their first, middle, and last names and stores each in a new variable. 2. Computes the length of the name not including spaces...
-
Java Help! Convert the following code from Python to Java Python: class Fruit: def __init__(self, name): self.name = name @property def name(self): return self._name @name.setter def name(self,...
-
Can you think of anyone from the 20th or 21st century who has utilized movement as a tool in their efforts to create a loyal following or to impress a movement of the people or to at least organize...
-
P Corporation acquired an 80% interest in S Corporation two years ago at an implied value equal to the book value of S. On January 2, 2017, S sold equipment with a five-year remaining life to P for a...
-
Sentry Company has had 4 years of net income. Due to this success, the market price of its 400,000 shares of $2 par value common stock has increased from $12 per share to $49. During this period,...
-
A force does work on a 50 g particle as the particle moves along the following straight paths in the xy-plane: 25 J from (0 m, 0 m) to (5 m, 0 m); 35 J from (0 m, 0 m) to (0 m, 5 m); 5 J from (5 m, 0...
-
Rule 4 (e) of the Federal Rules of Civil Procedure permits service by any method allowed by the state law in which the district court is sitting. Do a search to determine the service of process rules...
-
Dearborn Manufacturing, Co. completed the following transactions during 2014: Jan. 16 Declared a cash dividend on the 6%, $ 95 par noncumulative preferred stock (1,000 shares outstanding). Declared a...
-
How does international credit management differ from credit management in a single country? Company would any type of international credit management to help their company succeed in other countries....
-
Kia Lopez (SSN 412-34-5670) resides at 101 Poker Street, Apt. 12A, Hickory, FL 34714. Her W-2 shows the following: Wages $ 56,500 Federal withholding 6,100 Social security wages 56,500 Social...
-
The following adjusted trial balance at December 31 of Wilson Trucking Company. Account Title Cash Accounts receivable Office supplies Trucks Accumulated depreciation-Trucks Land Accounts payable...
-
The December 31, 2021, adjusted trial balance of Business Solutions (reflecting its transactions from October through December of 2021) follows. Number 101 196 Account Title Cash Accounts receivable...
-
ACCT Co. had a 20 percent tax rate. Given the following pre-tax amounts, what would be the income tax expense reported on the face of the income statement? Sales revenue $ 1,000,000 Cost of goods...
-
Consider the following flowchart: Start Input y Is y positive? No Output "SET" Set y to 5 Output y Yes Output "FLIP" Multiply y by -1 Stop If the user inputs a value of 4, what is the expected...
-
Consider the following configuration of source charge: ^ d -9 -29 d /2 B A +29 In this diagram, let q = 10nC and the distance d = 1cm. a.) Sketch what you think the electric field at points A and B...
-
Consider your body as an open system. For five days in row record your energy intake as well as your body mass. The measurements of body mass should be done twice a day, in the mornings and evenings...
-
provide your perspective on the radioactive nuclear waste site project in relation to the principles and distribution of power between the federal government and the states. include in-text citation...
-
(a) Explain why the concentration of dissolved oxygen in freshwater is an important indicator of the quality of the water. (b) How is the solubility of oxygen in water affected by increasing...
-
Refer to the previous exercise. Instead of 49, suppose that 64 Americans were surveyed about their weekly expenditures on coffee. Assume the sample mean remained the same. a. What is the 95%...
-
The attendance at the Savannah Colts minor league baseball game last night was 400. A random sample of 50 of those in attendance revealed that the mean number of soft drinks consumed per person was...
-
A data set consists of 145 observations that range from 56 to 490. What size class interval would you recommend?
-
The financial management process is important for auditors because of its role in helping to form expectations about financial statement results. To illustrate this concept, explain how an...
-
Consider Manny Corp., our military outfitting operation from Chapter 10. Its financial data is reprinted here for convenience. a. If you were the auditor assigned to perform substantive analytical...
-
Following are some routine procedures for the audit of payroll (discussed in the Appendix). For each procedure, (1) state whether it is a test of controls or a substantive test, (2) state which...
Study smarter with the SolutionInn App