Two- Heap Pattern ✅✔️💯
This is a new Pattern (Two- Heap Pattern.Min heap and Max Heap Pattern)\n\n215. Kth Largest Element in an Array same pattern\n451. Sort Characters By Frequency\
This is a new Pattern (Two- Heap Pattern.Min heap and Max Heap Pattern)\n\n[215. Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/solutions/5195848/k-pattern-heaps-peiority/) same pattern\n451. Sort Characters By Frequency\n[703. Kth Largest Element in a Stream](https://leetcode.com/problems/kth-largest-element-in-a-stream/solutions/5198578/k-pattern/)\n[767. Reorganize String](https://leetcode.com/problems/reorganize-string/solutions/5196813/k-pattern/)\nRearrange String k Distance Apart -- Q & A below\n[1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows/solutions/5198589/k-pattern/)\n[373. Find K Pairs with Smallest Sums](https://leetcode.com/problems/find-k-pairs-with-smallest-sums/solutions/5197679/the-k-pattern/)\n[378. Kth Smallest Element in a Sorted Matrix](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/solutions/5197755/the-k-pattern/)\n[719. Find K-th Smallest Pair Distance]()\n[2040. Kth Smallest Product of Two Sorted Arrays]()\n[264. Ugly Number II](https://leetcode.com/problems/ugly-number-ii/solutions/5198107/nthuglynumber/)\n[263. Ugly Number](https://leetcode.com/problems/ugly-number/solutions/5198605/the-ugly-number/)\n[502. IPO](https://leetcode.com/problems/ipo/solutions/5198438/priorityqueue-pattern/)\n\n# Code\n```\nclass Solution {\n    public int findMaximizedCapital(int k, int w, int[] profits, int[] capital) {\n        // Min-heap for projects based on capital requirements\n        PriorityQueue<Project> minCapitalHeap = new PriorityQueue<>((a, b) -> a.capital - b.capital);\n        // Max-heap for available projects based on profits\n        PriorityQueue<Project> maxProfitHeap = new PriorityQueue<>((a, b) -> b.profit - a.profit);\n\n        // Populate the min-heap with initial projects\n        for (int i = 0; i < profits.length; i++) {\n            minCapitalHeap.offer(new Project(capital[i], profits[i]));\n        }\n\n        // Iterate k times to pick k projects\n        for (int i = 0; i < k; i++) {\n            // Move all projects we can afford to the max-heap\n            while (!minCapitalHeap.isEmpty() && minCapitalHeap.peek().capital <= w) {\n                maxProfitHeap.offer(minCapitalHeap.poll());\n            }\n\n            // If there are no affordable projects, break\n            if (maxProfitHeap.isEmpty()) {\n                break;\n            }\n\n            // Pick the most profitable project\n            w += maxProfitHeap.poll().profit;\n        }\n\n        return w;\n    }\n\n    // Helper class to represent a project with capital and profit\n    static class Project {\n        int capital;\n        int profit;\n\n        Project(int capital, int profit) {\n            this.capital = capital;\n            this.profit = profit;\n        }\n    }\n}\n\n```
['Greedy', 'Heap (Priority Queue)', 'Java']