Array ( [0] => [1] => questions [2] => Arrays [3] => Min-Platforms- ) Arrays | Min Platforms | THE INQUISITIVE





Min Platforms

LEVEL:Beginner

Description

Given an two array of elements one is arrival and departure. find the minimum number of platforms required for the railway station so that no train waits according to arrival and departure time

Input Format

First line contains the size of the first array. Next line contains the m values i.e, arrival time separated by the spaces. Next line contains the n values i.e, departure time separated by the spaces

Output Format

Print the minimum number of stations required.


Example 1:

Input
6
9 00 9 40 9 50 11 00 15 00 18 00
9 10 12 00 11 20 11 30 19 00 20 00 
Output
3
Example 2:

Input
4
10 00 10 30 11 10 11 10
11 00 11 00 12.00 12.00	
Output
2
Example 3:

Input
4
4 30 6 30 7 10 8 00 
5 30 6 45 7 30 10 00
Output
1

oops

Login to see Discussion




Approach

Approach1:

Step-i) Take both arr time and dep time in two arrays.
Step-ii) Initialize a variable count to 0.
Step-iii) Check whether the next arrival time is in between all intervals.
Step-iv) If it is between all intervals then we need another platform.
Step-v) So now increase the count.
Step-vi) Repeat this process until all the arr elements are checked.
Step-vii) Return count.

Time Complexity: O(n^2)
Space Compexity: O(n)


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution