Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect solution is getting accepted [Missing TestCase] #3963

Open
ekanshsaxena opened this issue Mar 26, 2025 · 0 comments
Open

Incorrect solution is getting accepted [Missing TestCase] #3963

ekanshsaxena opened this issue Mar 26, 2025 · 0 comments

Comments

@ekanshsaxena
Copy link

ekanshsaxena commented Mar 26, 2025

Test Case:
[(25,579),(218,918),(1281,1307),(623,1320),(685,1353),(1308,1358)]

Problem:
https://neetcode.io/problems/meeting-schedule-ii

Solution getting accepted:

/**
 * Definition of Interval:
 * class Interval {
 * public:
 *     int start, end;
 *     Interval(int start, int end) {
 *         this->start = start;
 *         this->end = end;
 *     }
 * }
 */

class Solution {
public:
    int minMeetingRooms(vector<Interval>& intervals) {
        sort(intervals.begin(), intervals.end(), [](const Interval &a, const Interval &b){
            return a.end < b.end;
        });
        int totalIntervals = intervals.size();
        if(totalIntervals == 0) return 0;
        int daysReq = 1;

        int lastPointer = 0;
        for(int intervalIdx = 1; intervalIdx < totalIntervals; intervalIdx++){
            Interval interval = intervals[intervalIdx];
            if(interval.start < intervals[lastPointer].end){
                daysReq++;
            }else{
                lastPointer++;
            }
        }
        return daysReq;
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant