This file contains 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
# delayed scheduler | |
""" | |
write a function schedule(task, delay) to schedule a task that will be run after some delay | |
(1) first normal version | |
(2) thread safe version | |
""" | |
import heapq | |
import time | |
class Task: | |
def __init__(self, name): |
This file contains 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
""" | |
windowed k, v map | |
""" | |
import time | |
class Node: | |
def __init__(self, time=0, val=0, key=0): | |
self.time = time | |
self.val = val | |
self.key = key |
This file contains 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
""" | |
windowed k, v map | |
first version with t for debug | |
""" | |
class Node: | |
def __init__(self, time=0, val=0, key=0): | |
self.time = time | |
self.val = val | |
self.key = key | |
self.next = None |
This file contains 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
# variadic function call | |
""" | |
Note: | |
If a function is marked as isVariadic=true, then the last argument can occur one or more number of times. | |
Example: | |
FuncA: [String, Integer, Integer]; isVariadic = false | |
FuncB: [String, Integer]; isVariadic = true | |
FuncC: [Integer]; isVariadic = true | |
FuncD: [Integer, Integer]; isVariadic = true | |
FuncE: [Integer, Integer, Integer]; isVariadic = false |
This file contains 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
# data modeling {word: {doc_id: {positions}}} | |
from collections import defaultdict | |
def build_index(sentences): | |
index = defaultdict(lambda: defaultdict(set)) | |
for docid, sentence in enumerate(sentences): | |
wordlist = sentence.split(' ') | |
for pos, word in enumerate(wordlist): | |
index[word][docid].add(pos) | |
return index |
This file contains 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
from enum import ENUM | |
class LockerSize(ENUM): | |
# for example.. not necessarily a cube | |
SMALL = (1, 1, 1) | |
MEDIUM = (2, 2, 2) | |
LARGE = (3, 3, 3) | |
class Locker: | |
def __init__(self, id, size, **kwargs): |
This file contains 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
""" | |
implemnet linux find command as an api ,the api willl support finding files that has given size requirements and a file with a certain format like | |
find all file >5mb | |
find all xml | |
Assume file class | |
{ | |
get name() | |
directorylistfile() | |
getFile() |
This file contains 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
""" | |
OO Design: design data types for Amazon locker and packages | |
Requirement: Design an optimized algorithm to fit the package in the right locker | |
""" | |
import bisect | |
class Locker: | |
def __init__(self, x, y , z, **kwargs): | |
self.length = x | |
self.width = y | |
self.height = z |
This file contains 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
""" | |
Input: String="oidbcaf", Pattern="abc" | |
Output: true | |
Explanation: The string contains "bca" which is a permutation of the given pattern. | |
""" | |
""" | |
general pattern: | |
make a dict for pattern string | |
iterate over the right end of the window |
This file contains 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
# leetcode 30. | |
def find_word_concatenation(s, words): | |
result_indices = [] | |
worddict = dict() | |
wordlen = len(words[0]) | |
i, j = 0, 0 | |
total = 0 | |
for word in words: | |
if word not in worddict: | |
worddict[word] = 0 |
NewerOlder