'Functionality similar to Java TreeSet.floor() in Python 3
I am trying to solve a problem wherein I am given a bunch of days and some jobs to do within those days. Each job has a day deadline before which it has to be finished. As such, when I am assigning jobs to days I can assign the particular job to any day on or before its deadline. I can do this by maintaining an array of days and checking which day is available from deadline going back to day 1 (will have to do this for each job). Hence this method would take up O(N^2) time. However if I can use something like a TreeSet in Java which returns the floor value of a searched day (so if I search for day 5 but it already has a job assigned to it and the next free day is day 3, TreeSet.floor(5) returns 3), that would take up only log N time for the search part reducing it to an O(N log N) operation.
Is there any data structure available in Python3 wherein I can directly use this (without having to implement a TreeSet altogether)?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
