![]() |
VOOZH | about |
Given a 2D array arr[][3] consisting of information of N trains where arr[i][0] is the train number, arr[i][1] is the arrival time, and arr[i][2] is the duration of stoppage time. Given another integer F representing the train number, the task is to find the platform number on which the train with train number F arrives according to the following rules:
Examples:
Input: arr[] = {{112567, 1, 2}, {112563, 3, 3}, {112569, 4, 7}, {112560, 9, 3}}, F = 112569
Output: 1
Explanation:
Below is the order of the arrival of trains:
Train Platform Leaving Time
112567 1 4
112563 2 7
112569 1 12
112560 2 13Therefore, the train with train number 112569 arrives at platform number 1.
Input: arr[] = {{112567, 2, 1}, {112563, 5, 5}, {112569, 7, 3}, {112560, 3, 7}}, F = 112569
Output: 3
Approach: The given problem can be solved by using the priority queue. Follow the steps below to solve this problem:
Below is the implementation of the above approach:
3
Time Complexity: O(N * log N)
Auxiliary Space: O(N)