-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathCount Platforms.cpp
More file actions
86 lines (69 loc) · 1.62 KB
/
Count Platforms.cpp
File metadata and controls
86 lines (69 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
Given two arrays (both of size n), one containing arrival time of trains and other containing the corresponding trains departure time (in the form of an integer) respectively. Return the minimum number of platform required, such that no train waits.
Arrival and departure time of a train can't be same.
Input Format :
Line 1: Integer n, number of elements in arrival and departure array
Line 2: Elements of Arrival Array (separated by spaces).
Line 3: Elements of Departure Array (separated by spaces).
Output Format:
Minimum Number of Platform Needed
Constraints :
1 <= n <= 100
Sample Input 1 :
6
900 940 950 1100 1500 1800
910 1200 1120 1130 1900 2000
Sample Output 1 :
3
Sample Input 2 :
4
1100 1101 1103 1105
1110 1102 1104 1106
Sample Output 2 :
2
*/
#include <bits/stdc++.h>
using namespace std;
int platformsNeeded(int arrival[], int departure[], int n) {
/*
* Don't write main().
* Don't read input, it is passed as function argument.
* Don't print anything just return integer value.
*/
int maxc=1;
int c=1;
int i=0,j=0;
sort(arrival,arrival+n);
sort(departure,departure+n);
while(i<n && j<n){
if(arrival[i]<departure[j]){
i++;
c++;
}
else{
j++;
c--;
maxc=max(maxc,c);
}
}
return maxc;
}
#include<iostream>
using namespace std;
#include"solution.h"
int main()
{
int n;
cin>>n;
int* arr=new int[n];
int* dep=new int[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
cin>>dep[i];
}
cout<< platformsNeeded(arr, dep, n);
}