java sol 💤🔋✅ Good morning vibes ❤️
\n# Code\n\nclass Solution {\n    public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n        int maxDifficulty = 0;\n        for (i
\n# Code\n```\nclass Solution {\n    public int maxProfitAssignment(int[] difficulty, int[] profit, int[] worker) {\n        int maxDifficulty = 0;\n        for (int d : difficulty) {\n            maxDifficulty = Math.max(maxDifficulty, d);\n        }\n\n        int[] maxProfitUpToDifficulty = new int[maxDifficulty + 1];\n        for (int i = 0; i < difficulty.length; i++) {\n            maxProfitUpToDifficulty[difficulty[i]] = Math.max(maxProfitUpToDifficulty[difficulty[i]], profit[i]);\n        }\n\n        for (int i = 1; i <= maxDifficulty; i++) {\n            maxProfitUpToDifficulty[i] = Math.max(maxProfitUpToDifficulty[i], maxProfitUpToDifficulty[i - 1]);\n        }\n\n        int totalProfit = 0;\n        for (int ability : worker) {\n            if (ability > maxDifficulty) {\n                totalProfit += maxProfitUpToDifficulty[maxDifficulty];\n            } else {\n                totalProfit += maxProfitUpToDifficulty[ability];\n            }\n        }\n\n        return totalProfit;\n    }\n}\n\n```
['Java']