Very Easy 🔥| Java | Python| C| Two Pointer
Approach\nCombine Difficulty and Profit: Pair each job\'s difficulty with its profit, and sort these pairs by difficulty. This allows us to efficiently find the
Approach\nCombine Difficulty and Profit: Pair each job\'s difficulty with its profit, and sort these pairs by difficulty. This allows us to efficiently find the best job a worker can perform.\n\nSort Workers: Sort the worker abilities. This ensures that we can iterate through the workers in increasing order of ability, which helps in assigning the most profitable job they can handle.\n\nTwo-Pointer Technique: Use a two-pointer technique to iterate through the sorted jobs and workers simultaneously:\n\nMaintain a variable to keep track of the maximum profit seen so far (best), since the profit of jobs increases monotonically with difficulty.\nIterate through the workers and for each worker, assign the best possible job they can handle using the precomputed maximum profits.\n```\nclass Solution {\n    public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n        int n = difficulty.length;\n        int[][] jobs = new int[n][2];\n        for (int i = 0; i < n; i++) {\n            jobs[i][0] = difficulty[i];\n            jobs[i][1] = profit[i];\n        }\n        Arrays.sort(jobs, (a, b) -> a[0] - b[0]);\n        Arrays.sort(worker);\n        int maxProfit = 0, i = 0, best = 0;\n        for (int ability : worker) {\n            while (i < n && ability >= jobs[i][0]) {\n                best = Math.max(best, jobs[i][1]);\n                i++;\n            }\n            maxProfit += best;\n        }\n\n        return maxProfit;\n    }\n    }\n\n```\n```\ndef maxProfitAssignment(difficulty, profit, worker):\n    jobs = sorted(zip(difficulty, profit))\n    worker.sort()\n    maxProfit = 0\n    i = 0\n    best = 0\n    for ability in worker:\n        while i < len(jobs) and ability >= jobs[i][0]:\n            best = max(best, jobs[i][1])\n            i += 1\n        maxProfit += best\n    return maxProfit\n\n```\n```\ntypedef struct {\n    int difficulty;\n    int profit;\n} Job;\n\nint compareJobs(const void* a, const void* b) {\n    return ((Job*)a)->difficulty - ((Job*)b)->difficulty;\n}\n\nint compareWorkers(const void* a, const void* b) {\n    return *(int*)a - *(int*)b;\n}\n\nint maxProfitAssignment(int* difficulty, int* profit, int difficultySize, int* worker, int workerSize) {\n    Job* jobs = (Job*)malloc(difficultySize * sizeof(Job));\n    for (int i = 0; i < difficultySize; i++) {\n        jobs[i].difficulty = difficulty[i];\n        jobs[i].profit = profit[i];\n    }\n    qsort(jobs, difficultySize, sizeof(Job), compareJobs);\n    qsort(worker, workerSize, sizeof(int), compareWorkers);\n    int maxProfit = 0;\n    int i = 0;\n    int best = 0;\n    for (int j = 0; j < workerSize; j++) {\n        int ability = worker[j];\n        while (i < difficultySize && ability >= jobs[i].difficulty) {\n            best = best > jobs[i].profit ? best : jobs[i].profit;\n            i++;\n        }\n        maxProfit += best;\n    }\n    free(jobs);\n    return maxProfit;\n}\n\n```
['Two Pointers', 'C', 'Python', 'Java']