My friend asked me a question about heaps, and I was dumbfounded. Had no idea to answer. To fix my lack of knowledge... I WORKED ON HEAPS!!!
😀😀😀
Notes:
- finding the kth largest element can be done with one line using heapq tools.
- heapq is how you build min heaps, heappop, heaptop, heappush
- if the question asks for a log(something) solution, its some form of binary search
- there are no terniary operators in python, just one liner if else statements
- you can set values to infinity and -infinity: float("infinity") or float("-infinity")
-pretty handy for edge cases in lists
No comments:
Post a Comment