Simple | Easy to understand | JAVA
Intuition\n Describe your first thoughts on how to solve this problem. \nSort the difficulty along side storing the profit of that difficulty.\nAlso sort the ar
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the difficulty along side storing the profit of that difficulty.\nAlso sort the array of worker\'s ability.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nNow change the profit to maximum profit for that difficulty.\nThen iterate through the worker\'s ability along side with the difficulty max for max profits.\nI stored all the profits in tc\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int maxProfitAssignment(int[] d, int[] p, int[] w) {\n        Map<Integer,Integer> m=new TreeMap<>();\n        Arrays.sort(w);\n        int c=0;int tc=0;\n        for(int i=0;i<d.length;i++)\n        {\n            m.put(d[i],Math.max(p[i],m.getOrDefault(d[i],0)));\n        }\n        int j=0;\n        Arrays.sort(d);\n        for(int i:m.keySet())\n        {\n            c=(c>m.get(i))?c:m.get(i);\n            m.put(i,c);\n        }\n        for(int i=0;i<d.length;i++)\n        {\n            p[i]=m.get(d[i]);\n        }\n        j=0;\n        for(int i=0;i<w.length;i++)\n        {\n            if(w[i]<d[j])\n            {\n                continue;\n            }\n            if(w[i]==d[j])\n            {\n                tc+=p[j];\n                continue;\n            }\n            while(j<d.length)\n            {\n                if(d[j]<=w[i])\n                {\n                    j++;\n                }\n                else\n                {\n                    break;\n                }\n            }\n            j--;\n            tc+=p[j];\n        }\n        return tc;\n    }\n}\n```
['Java']