Double Sort and Two Pointer. Lots of comments. Beats 100%
\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n^2)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\n# Code\n\n# @p
\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n^2)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\n# @param {Integer[]} difficulty\n# @param {Integer[]} profit\n# @param {Integer[]} worker\n# @return {Integer}\ndef max_profit_assignment(difficulty, profit, worker)\n    # Sort workers\n    worker.sort_by!{|a| -a}\n    max_diff = worker[0]\n\n    # Create diff profit array where we pair difficulty with profit.\n    diff_profit = []\n    i = 0\n    while i < difficulty.size\n        if max_diff >= difficulty[i]\n            diff_profit << [difficulty[i], profit[i]]\n        end\n        i += 1\n    end\n\n    # Sort by highest profit.\n    diff_profit.sort_by!{|a| -a[1]}\n\n    # n^2 time complexity\n    # We reduce this by using a pointer to account for when a worker\n    # runs into a job which is of higher difficulty than what the worker \n    # can profit. When this happens we increase a pointer(diff_profit_i)\n    # so when the next worker is assigned a job, it starts from the same position\n    # in diff_profit as the last worker. This removes the traversal of going through jobs\n    # which are too hard for the worker and saves a ton of time.\n    profit = 0\n    diff_profit_i = 0\n    worker.each do |worker_diff|\n        diff_profit[diff_profit_i..-1].each do |job|\n            if job[0] <= worker_diff\n                profit += job[1]\n                break\n            else\n                diff_profit_i += 1\n            end \n        end\n    end\n\n    profit\nend\n```
['Ruby']