MCPcopy Index your code
hub / github.com/Tiwarishashwat/InterviewCodes / book

Method book

MyCallendar2.java:10–29  ·  view source on GitHub ↗
(int start, int end)

Source from the content-addressed store, hash-verified

8 }
9
10 public boolean book(int start, int end) {
11 //if event is present in overlapped then return false
12 Integer prevVal = overlappedMap.lowerKey(end);
13 if(prevVal!=null && start <= overlappedMap.get(prevVal)-1){
14 return false;
15 }
16 // insert into bookings and if it is overalapping with
17 // any booking then insert into overlapped map
18 for(int booking[] : bookings){
19 // booking[0], start
20 // booking[1], end
21 int commStart = Math.max(booking[0],start);
22 int commEnd = Math.min(booking[1],end);
23 if(commStart<commEnd){
24 overlappedMap.put(commStart,commEnd);
25 }
26 }
27 bookings.add(new int[]{start,end});
28 return true;
29 }
30}
31
32/**

Callers

nothing calls this directly

Calls 2

getValueMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected