Minimum Platforms(Greedy Standard Problem)

Revision en1, by tejeshans782k, 2021-06-19 06:51:19

I’ve been trying hard to solve the minimum platforms problem on geeksforgeeks platform . I’ve come up with a solution using priority Queue but my solution is failing for 5 cases(All of length 50000). I just want to know where my solution is failing. Please help me. I’m new to DSA Here’s the problem link :


Here's my code :

struct Interval{

int arrival;
  int departure;
  int platform;    


 bool comp(Interval I1, Interval I2)
    if(I1.arrival == I2.arrival)
        return I1.departure < I2.departure;

        return I1.arrival < I2.arrival;


class Solution{

public: int findPlatform(int arr[], int dep[], int n) {

vector<Interval> I(n);
    priority_queue<int, vector<int>, greater<int>> platforms;
    for(int i = 0; i < n; i++)
        I[i].arrival = arr[i];
        I[i].departure = dep[i];
        I[i].platform = 0;


    sort(I.begin(), I.end(), comp);

    //vector<int> platforms;

    for(int i = 1; i < n; i++)
        int top =;

        if(top < I[i].arrival)


    return platforms.size();


Tags #greedy, #dynamic programing, #cpp, #heap


  Rev. Lang. By When Δ Comment
en1 English tejeshans782k 2021-06-19 06:51:19 1647 Initial revision (published)