neetcode-gh/leetcode

Incorrect solution is getting accepted [Missing TestCase]

Closed this issue · 1 comments

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;
    }
};

Thanks for the feedback! The testcase has been added.