Golang | Priority Queue
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n- golang implementation
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- golang implementation of official solution https://leetcode.com/problems/ipo/solutions/2959870/ipo/?orderBy=most_votes\n\n\n# Complexity\n- Time complexity: $$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\ntype Project struct {\n    profit, capital int\n}\n\ntype IntHeap []int\nfunc (h IntHeap) Len() int           { return len(h) }\nfunc (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }\nfunc (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }\nfunc (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int)) }\nfunc (h *IntHeap) Pop() interface{} {\n\told := *h\n\tn := len(old)\n\tx := old[n-1]\n\t*h = old[0 : n-1]\n\treturn x\n}\n\nfunc findMaximizedCapital(k int, w int, profits []int, capital []int) int {\n    n := len(profits)\n    projects := make([]Project, n)\n    for i := range profits {\n        projects[i] = Project{profits[i], capital[i]}\n    }\n    sort.Slice(projects, func (i, j int) bool {\n        return projects[i].capital < projects[j].capital\n    })\n    \n    q := &IntHeap{}\n    heap.Init(q)\n\n    ptr := 0\n    for i := 0; i < k; i++ {\n        for ptr < n && projects[ptr].capital <= w {\n            heap.Push(q, projects[ptr].profit)\n            ptr++\n        }\n        if q.Len() == 0 {\n            break\n        }\n        w += heap.Pop(q).(int)\n    }\n    return w\n}\n```
['Go']