Task Scheduling

Sort by

recency

|

47 Discussions

|

  • + 0 comments

    Check mobile phone prices qatar for more information.

    int taskScheduling(int d, int m) { // Read d task descriptions vector> tasks; for (int i = 0; i < d; i++) { int duration, deadline; cin >> duration >> deadline; tasks.push_back({duration, deadline}); }

    // Sort tasks by deadline (Earliest Deadline First)
    sort(tasks.begin(), tasks.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
        return a.second < b.second;
    });
    
    int currentTime = 0;
    int maxLateness = 0;
    
    // Schedule each task and compute maximum lateness
    for (auto& task : tasks) {
        int duration = task.first;
        int deadline = task.second;
        currentTime += duration;
        int lateness = max(0, currentTime - deadline);
        maxLateness = max(maxLateness, lateness);
    }
    
    return maxLateness;
    

    }

  • + 0 comments

    I like your task scheduling code. Can I integerate this algorithm on my website which is related account deletion

  • + 0 comments

    Here is my solution in java, javascript, python, C, C++, Csharp HackerRank Task Scheduling Problem Solution

  • + 0 comments

    My C++ solution:

    map<int,int> mp = {{0,0}};                  //d->exceed
    map<int,int>::iterator maxdif = mp.begin();   //iterator to mp item with most exceed
    
    
    map<int,int>::iterator getIterator(int d) {
        if (d<=maxdif->first) return maxdif;
        auto iv = mp.insert({d,0});
        auto it =iv.first;
        if (iv.second) {    //new d;
            auto previt = it;
            previt--;
            it->second = previt->second+previt->first-it->first;
        }
        return it;
    }
    
    int taskScheduling(int d, int m) {
        map<int,int>::iterator it = getIterator(d);
        while (it!=mp.end()) {
            it->second += m;
            if (it->second > maxdif->second) {
                maxdif=it;
            }
            it++;
        }
        return maxdif->second;
    }
    
  • + 0 comments

    Here is the solution of Task Scheduling Click Here