Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8b84002

Browse files
author
Amogh Singhal
authored
Create getMinPlatforms.py
1 parent 191da07 commit 8b84002

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

‎getMinPlatforms.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def getMinPlatforms(arr, dep):
2+
if len(arr) != len(dep):
3+
print("Wrong inputs given...")
4+
return
5+
else:
6+
sorted_arr = sorted(arr + dep)
7+
8+
minPlatform = 0
9+
trainsAtPlatform = 0
10+
11+
for i in sorted_arr:
12+
if i in arr:
13+
trainsAtPlatform += 1
14+
if i in dep:
15+
trainsAtPlatform -= 1
16+
minPlatform = max(minPlatform, trainsAtPlatform)
17+
18+
return minPlatform
19+
20+
arrivalArr = [900, 940, 950, 1100, 1500, 1800]
21+
departureArr = [910, 1200, 1120, 1130, 1900, 2000]
22+
23+
result = getMinPlatforms(arrivalArr, departureArr)
24+
25+
print("Minimum no. of platforms for given time table are: ", result)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /