MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / MyCalendar

Class MyCalendar

myCalendar1.java:1–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class MyCalendar {
2 TreeMap<Integer,Integer> map;
3 public MyCalendar() {
4 map = new TreeMap<>();
5 }
6
7 public boolean book(int start, int end) {
8 Integer prevVal = map.lowerKey(end);
9 if(prevVal!=null && start <= map.get(prevVal)-1){
10 return false;
11 }
12 map.put(start,end);
13 return true;
14 }
15}
16
17/**
18 * Your MyCalendar object will be instantiated and called as such:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected