through the intersection can only pass through one at a time. When multiple cars arrive tersection at the same time, two queues can build up-one for each street. Cars are the queue in the order at which they arrive. Unfortunately, there is no traffic light to trol traffic when multiple cars arrive at the same time. So, the local residents have their own system for determining which car has priority to pass through the on: the previous second, no car passed through the intersection, then the first car in the queue for wenue goes first he previous second, a car passed through the intersection on 1st Avenue, then the first car in queue for 1st Avenue goes first he previous second, a car passed through the intersection on Main Street, then the first carin ueue for Main Street goest first through the intersection takes 7 second. car, find the time when they will pass through the intersection. Description e the function geoResult in the editor below. has the following parameters: 15 16 17 18 19 21 . The function accepts following parameters: 1. INTEGER ARRAY arrival 2. INTEGER ARRAY street def getResult(arrival, street): 23 24 25 > (f

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

SOLVE IN PYTHON3

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 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 iis the time when the car will pass
through the intersection
Constraints
• 1sns105
• Os arrival[i] ≤ 10⁹ for Osisn-1
• arrival[i] s arrival[i+1] for Osisn-2
• 0≤ street[i] ≤ 1 for Osisn-1
▸ Input Format For Custom Testing
▾ Sample Case 0
Sample Input For Custom Testing
STDIN
4
0
Function
arrival[] size n = 4
arrival = [0, 0, 1, 4]
street[] size n = 4
street = [0, 1, 1, 0]
13
14
15
16
17
18
19
#
# The function is expected to return an INTEGER ARRAY.
# The function accepts following parameters:
1. INTEGER ARRAY arrival
# 2. INTEGER ARRAY street
#
def getResult(arrival, street):
20
21
22
23
24
25 > if _name__ == main : -
Test Results
Custom Input
Run Code
Run Tests
Line: 10 Col: 1
Submit
Transcribed Image Text: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 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 iis the time when the car will pass through the intersection Constraints • 1sns105 • Os arrival[i] ≤ 10⁹ for Osisn-1 • arrival[i] s arrival[i+1] for Osisn-2 • 0≤ street[i] ≤ 1 for Osisn-1 ▸ Input Format For Custom Testing ▾ Sample Case 0 Sample Input For Custom Testing STDIN 4 0 Function arrival[] size n = 4 arrival = [0, 0, 1, 4] street[] size n = 4 street = [0, 1, 1, 0] 13 14 15 16 17 18 19 # # The function is expected to return an INTEGER ARRAY. # The function accepts following parameters: 1. INTEGER ARRAY arrival # 2. INTEGER ARRAY street # def getResult(arrival, street): 20 21 22 23 24 25 > if _name__ == main : - Test Results Custom Input Run Code Run Tests Line: 10 Col: 1 Submit
Input Format For Custom Testing
Sample Case 0
Sample Input For Custom Testing
STDIN Function
4
e
0
4
0
1
1
e
NOH+
Sample Output
2
1
arrival [] size n = 4
arrival = [0, 0, 1, 4]
4
street[] size n = 4
street = [0, 1, 1, 0]
Explanation
At time 0, cars 0 and 7 want to pass through the intersection. Car O is traveling on Main Street
and car 1 is traveling on 1st Avenue. Because there was no car passing through the
intersection on the previous second, car 1 has priority.
At time 1, cars 0 and 2 want to pass through the intersection. Car 2 is traveling on 1st Avenue
and at the previous second a car passed through on 1st Avenue, so the car 2 passes through
the intersection.
At time 2, car 0 passes through the intersection.
At time 4, car 3 passes through the intersection.
Sample Case 1
⠀⠀⠀⠀⠀⠀⠀⠀
Transcribed Image Text:Input Format For Custom Testing Sample Case 0 Sample Input For Custom Testing STDIN Function 4 e 0 4 0 1 1 e NOH+ Sample Output 2 1 arrival [] size n = 4 arrival = [0, 0, 1, 4] 4 street[] size n = 4 street = [0, 1, 1, 0] Explanation At time 0, cars 0 and 7 want to pass through the intersection. Car O is traveling on Main Street and car 1 is traveling on 1st Avenue. Because there was no car passing through the intersection on the previous second, car 1 has priority. At time 1, cars 0 and 2 want to pass through the intersection. Car 2 is traveling on 1st Avenue and at the previous second a car passed through on 1st Avenue, so the car 2 passes through the intersection. At time 2, car 0 passes through the intersection. At time 4, car 3 passes through the intersection. Sample Case 1 ⠀⠀⠀⠀⠀⠀⠀⠀
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Lower bounds sorting algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education