Skip to content

Commit 5e9d331

Browse files
committed
Amazon Boomerang D-E-shaw Hike Paytm Walmart labs Zillious
1 parent e67c2b0 commit 5e9d331

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

minNoOfPlatform.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'''
2+
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 waits.
3+
'''
4+
#Complexity O(nlogn)
5+
def findplatform(arr,dep):
6+
n = len(arr)
7+
arr.sort()
8+
dep.sort()
9+
plat_needed = 1
10+
res = 1
11+
i = 1
12+
j = 0
13+
while i < n and j < n:
14+
if arr[i] < dep[j]:
15+
plat_needed += 1
16+
i += 1
17+
if plat_needed > res:
18+
res = plat_needed
19+
else:
20+
plat_needed -= 1
21+
j += 1
22+
return res
23+
24+
arr = [900,940,950,1100,1500,1800]
25+
dep = [910, 1200, 1120, 1130, 1900, 2000]
26+
27+
print findplatform(arr,dep)

0 commit comments

Comments
 (0)