Meeting Rooms

I never expect that the solution for this problem would be this easy so here it goes.

class Solution {
    fun canAttendMeetings(intervals: Array<IntArray>): Boolean {
        intervals.sortBy {it.first()}
        (0 until intervals.size - 1).forEach {
            if(intervals[it].last() > intervals[it + 1].first()) return false    
        }
        
        return true
    }
}
Runtime: 224 ms, faster than 36.36% of Kotlin online submissions for Meeting Rooms.
Memory Usage: 39 MB, less than 100.00% of Kotlin online submissions for Meeting Rooms.

The idea is that no two items should have their intervals overlap each other which means, first we have to sort the list according to the start time and for each item, the end time should not be greater than the next intervals start time.

comments powered by Disqus