Answer to Question #233874 in Python for srikanth

Question #233874
Minimum Platforms

You are given arrival and departure times of all trains that reach a railway station. Find the minimum number of platforms required for the railway station so that no train is kept wait

Input

The first line contains space-separated integers that represent the arrival time of the trains.

The second line contains space-separated integers represent the corresponding end time of the trains.

Output

The output should have an integer that represents the number of platforms needed to arrange the commute of all the trains.

Explanation: The arrival times of 5 trains are

0900 0940 0950 1100 1500. The departure times of 5 trains are 0910 1200 1120 1130 1900.The first platform will be used to run the trains that arrive at

0900 0940 1500. The second platform will be used to run the trains that arrive at 0950.

Sample Input 1
0900 1100 1235
1000 1200 1240
Sample Output 1
1

Sample Input 2
0900 0940 0950 1100 1500
0910 1200 1120 1130 1900
Sample Output 2
3

please provide correct output.
1
Expert's answer
2021-09-06T07:05:48-0400


def minimumPlatforms(arr, depa):


	
	arr.sort()


	
	depa.sort()


	
	countSum = 0




	platformRequired = 0


	
	x = y = 0


	
	while x < len(arr):


		
		if arr[x] < depa[y]:


			
			countSum = countSum + 1
			platformRequired = max(platformRequired, countSum)


			
			x = x + 1


		
		else:
			countSum = countSum - 1
			y = y + 1


	return platformRequired




if __name__ == '__main__':


	print("Sample Input 1")
	arrival = [900, 940, 950, 1100, 1500]
	departure = [910, 1200, 1120, 1130, 1900]
	print(arrival)
	print(departure)
	print("Sample Ouput 1")


	print( minimumPlatforms(arrival, departure))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS