Kotlin 2 pointers
Intuition\nSort both the workers (descending) and the jobs by profit (descending). Start from the first job (most profitable) and try to assign it to as many ca
# Intuition\nSort both the workers (descending) and the jobs by profit (descending). Start from the first job (most profitable) and try to assign it to as many capable workers as you can.\n\nSince the workers array is decendengly sorted by difficulty, the most capable worker is the one at hand. If that worker can not handle the job at hand, then no other worker will. We can safley discard the job in that case and pickup the next job in line.\n\nKeep matching jobs with workers as long as we still have jobs and workers remaining.\n\n# Code\n```\nclass Solution {\n\n    data class Job(val difficulty: Int, val profit: Int)\n\n    fun maxProfitAssignment(difficulty: IntArray, profit: IntArray, worker: IntArray): Int {\n       // Most capable worker is the first.\n       worker.sortDescending()\n\n       val jobs = mutableListOf<Job>()\n       for(i in difficulty.indices) {\n           jobs.add(Job(difficulty[i], profit[i]))\n       }\n       // Most profitable job is the first.\n       // Try to assign it to as many workers as we can.\n       jobs.sortWith(Comparator { x, y -> y.profit.compareTo(x.profit) })\n\n       var w = 0\n       var j = 0\n       var sum = 0\n       // We still have workers and jobs left.\n       while(w < worker.size && j < jobs.size) {\n           // The most profitable job can be handled by the most capable worker.\n           if(jobs[j].difficulty <= worker[w]) \n               sum += jobs[j].profit\n               // Assign the job to the worker and pickup the next worker in line. \n               // We\'ll keep the same job since it is the most profitable so far.\n               // We\'ll try to assign it to the next worker in the next iteration.\n               w += 1\n           } else {\n               // The most capable worker so far can not handle this job. No one else can.\n               // Discard the job and pickup the next one in line.\n               j += 1\n           }\n       }\n\n       return sum\n    }\n}\n```
['Kotlin']