Design a greedy algorithm which takes as input the number of kids n, and the n lists of intervals [ai, bi], and outputs the maximum number of kids m that Santa can talk to. You are expected to write the pseudocode of your algorithm.
On the Christmas eve, Santa Claus will start working to deliver gifts to the lovely kids. Different from previous years that he secretly delivered the gifts, this year, he indeed wants to openly deliver the gifts to the kids and wish them a merry Christmas when delivering the gifts.
However, the kids each have very different sleep schedules. Kid i is awake only in a single closed time interval [ai, bi]. Santa doesn’t want to disturb the sleeping kids, so each time he will find an awake kid, give the gift to the kid, wish the kid a merry Christmas, and talk with the kid until he/she falls asleep. However, Santa does want to meet and talk with as many kids as possible.
Design a greedy
Step by step
Solved in 2 steps