We are given N jobs, and their starting and ending times. We can do two jobs simultaneously at a particular moment. If one job ends at the same moment some other show starts then we can’t do them. We need to check if it is possible to complete all the jobs or not.
Input : Start and End times of Jobs 1 2 2 3 4 5 Output : Yes By the time third job starts, both jobs are finished. So we can schedule third job. Input : Start and End times of Jobs 1 5 2 4 2 6 1 7 Output : No All 4 jobs needs to be scheduled at time 3 which is not possible.
We first sort the jobs according to their starting time. Then we start two jobs simultaneously and check if the starting time of third job and so on is greater than the ending time of and of the previous two jobs.
The implementation the above idea is given below.
An alternate solution is to find maximum number of jobs that needs to be scheduled at any time. If this count is more than 2, return false. Else return true.
This article is contributed by Sarthak Kohli. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find minimum time to finish all jobs with given constraints
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- Program for Shortest Job First (SJF) scheduling | Set 2 (Preemptive)
- Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
- Schedule jobs so that each server gets equal load
- Maximize jobs that can be completed under given constraint
- Minimum time taken by each job to be completed given by a Directed Acyclic Graph
- Scheduling priority tasks in limited time and minimizing loss
- Longest Remaining Time First (LRTF) CPU Scheduling Program
- Minimize the sum of product of two arrays with permutations allowed
- Minimum cost to reach a point N from 0 with two different operations allowed
- Check if a destination is reachable from source with two movements allowed | Set 2
- Job Sequencing Problem | Set 2 (Using Disjoint Set)
- Job Sequencing Problem - Loss Minimization
- Job Sequencing Problem
- Job Selection Problem - Loss Minimization Strategy | Set 2
- Minimum Cost Path with Left, Right, Bottom and Up moves allowed
- Minimum cost for acquiring all coins with k extra coins allowed with every coin
- Minimize Cost with Replacement with other allowed
- Maximum sum of values in a given range of an Array for Q queries when shuffling is allowed