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
def sort_nuts_and_bolts(nuts, bolts): | |
"""Sort nuts and bolts in O(N log N) time""" | |
def sort(nuts, bolts): | |
if len(nuts) == 0: | |
return [] | |
lnuts, rnuts, lbolts, rbolts = [], [], [], [] | |
nut = nuts.pop() | |
bolt = None | |
for b in bolts: | |
if b == nut and not bolt: |
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
#!/usr/bin/env python | |
from collections import defaultdict | |
class BaseStream(object): | |
""" | |
A utility base class that we'll use to make sure that our | |
streams' respective popNext() methods make use of Python's | |
__iter__ magic method | |
""" |
NewerOlder