diff --git a/hotel_rent.java b/hotel_rent.java new file mode 100644 index 0000000..23b3e9b --- /dev/null +++ b/hotel_rent.java @@ -0,0 +1,36 @@ +import java.util.*; +class Solution { + public int solution(String[][] book_time) { + PriorityQueue t_arr = new PriorityQueue<>((o1,o2)->o1[0]-o2[0]); + for(int i=0;i room = new PriorityQueue<>(); + int count = 0; + while(!t_arr.isEmpty()){ + int[] curr = t_arr.poll(); + if(room.isEmpty()){ + room.offer(curr[1]); + count++; + }else{ + int prev = room.peek(); + if(prev <= curr[0]){ + room.remove(prev); + room.offer(curr[1]); + }else{ + room.offer(curr[1]); + count++; + } + } + } + return count; + } +}