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 | |
""" |
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 | |
""" | |
A script that generates all possible words that can be formed from | |
the characters in a provided string. | |
Matches are case-insensitive and the wordlist used is obtained from: | |
https://raw.githubusercontent.com/mattt/mobius/master/data/english-wordlist | |
Usage: |
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 | |
""" | |
This is my solution to the Simple Database problem posted on: | |
http://www.thumbtack.com/challenges/software-engineer | |
Candidate: David Morton | |
Email: [email protected] | |
Usage: |
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 | |
""" | |
Given the start word and end word find one of the | |
shortest possible paths from one word to the other | |
that can be achieved by substituting a single | |
character (where each word in the path is a valid | |
English word) | |
Usage: |
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 | |
""" | |
A script to serialize and deserialize Binary Trees in Python | |
""" | |
class Node(object): | |
def __init__(self, val, left=None, right=None): | |
self.val = val | |
self.left = left |
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 | |
""" | |
encrypt and descript lowercase strings without using | |
but lowercase strings | |
""" | |
from string import lowercase | |
from random import choice | |
MAX_GARBAGE_LENGTH = 5 |
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 | |
""" | |
Python's OrderedDict is an ideal data structure | |
to create an LRU cache | |
""" | |
from collections import OrderedDict | |
class LRUCache(object): |
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 | |
""" | |
Find the right sibling in a Binary Tree that's not fully populated | |
e.g. | |
1 | |
/ \ | |
2 6 | |
/ \ \ |
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 | |
""" | |
Create a superset from the integers provided | |
e.g. ./superset.py 1 2 3 | |
[set([]), set([1]), set([2]), set([3]), set([1, 2]), | |
set([1, 3]), set([2, 3]), set([1, 2, 3])] | |
""" | |
import sys |
OlderNewer