Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Solution: Conflicting Appointments
.....
.....
.....
Like the course? Get enrolled and start learning!
A
Anonymous
· 2 years ago
If you want to flex in your Java interview, you can use the comparator like this as well,
Arrays.sort(intervals, Comparator.comparingInt(i->i.start));
A
Anonymous
· 2 years ago
#class Interval: # def __init__(self, start, end): # self.start = start # self.end = end # def print_interval(self): # print("[" + str(self.start) + ", " + str(self.end) + "]", end='') class Solution: def canAttendAllAppointments(self, intervals): def do_overlap(a, b): return b.start < a.end # sort the intervals first to compare the overlapping intervals intervals.sort(key = lambda x: x.start) for i in range(1, len(intervals)): # check the interval and the previous interval for overlapping if do_overlap(intervals[i - 1], intervals[i]): return False return True
A
Anonymous
· 3 years ago
f
Show 1 reply
A
Anonymous
· 3 years ago
In the solution, an interval is implemented as a list of lists. In the problem, an interval is implemented as a class as in 'Merge Intervals'. Therefore, the solution provided does not work.
Reading Progress
0%