This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# UnionFind is defined in https://gist.github.com/siavashk/fef678f9f2ef17fdc6cff917922bf4ba | |
# Augment the union function to return True for new connections | |
def kruskal(edges: list[tuple[int, int, int]]): | |
""" | |
Edges: list of edge in (weight, start, end]) format | |
""" | |
edges.sort() | |
uf = UnionFind() | |
for _, x, y in edges: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://leetcode.com/discuss/post/2371234/an-opinionated-guide-to-binary-search-co-1yfw/ | |
def minimization(arr, condition): | |
""" | |
Find the first time a condition is True. | |
[F, F, F, (T), T, T, T] | |
(T) is the first time the conditions is True. | |
r is the True answer (always T) | |
l is always invalid (always F) | |
""" | |
l, r = -1, len(arr) - 1 # if len(arr) is a candidate |
OlderNewer