Skip to content

Instantly share code, notes, and snippets.

View neilljordan's full-sized avatar
🎯
Focusing

neilljordan

🎯
Focusing
View GitHub Profile
@neilljordan
neilljordan / daily-coding-problem-21.rb
Created July 8, 2019 16:52 — forked from woodRock/daily-coding-problem-21.rb
Given an array of time intervals (start, end) for classroom lectures (possibly overlapping), find the minimum number of rooms required. For example, given [(30, 75), (0, 50), (60, 150)], you should return 2.
# Sort jobs by finish times so that f1<=f2<=..<=fn
# 𝐴 ← βˆ…, π‘™π‘Žπ‘ π‘‘ ← 0
# for 𝑗 ← 1 to 𝑛
# if 𝑠𝑗 β‰₯ π‘™π‘Žπ‘ π‘‘ then 𝐴 ← 𝐴 βˆͺ {𝑗}, π‘™π‘Žπ‘ π‘‘ ← 𝑓𝑗
# return οΏ½
require('set')
def minimum_room_no(times)
times = times.sort {|a,b| a[1] <=> b[1]}