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
import unittest | |
class _Node(object): | |
''' | |
Represents a node in a BST. | |
value is any object that implements __lt__(), enough for | |
sorting in python 3. | |
''' |
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
var server = nodeOauth2Server({ | |
model: modelHandlers, | |
grants: ['password', 'refresh_token'], | |
debug: false, | |
refreshTokenLifetime: null, // never expire refresh token | |
passthroughErrors: true | |
}); | |
module.exports = { | |
grantWrap: function oauthGrantWrap(req, res, next) { |
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
import unittest | |
def bsearch_left(items, v): | |
''' | |
Binary search, finds left-most position. | |
Returns (bool, insertion-point after which | |
element should be inserted to maintain an invariant). | |
''' | |
if v is None: | |
raise ValueError('v must be set') |
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
import array | |
import tracemalloc | |
from contextlib import contextmanager | |
@contextmanager | |
def tracemem(msg): | |
tracemalloc.start() | |
snapshot1 = tracemalloc.take_snapshot() | |
yield | |
snapshot2 = tracemalloc.take_snapshot() |
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
from wsgiref.simple_server import make_server | |
from wsgiref.util import setup_testing_defaults | |
import random | |
import threading | |
import dozer | |
def run_dozer(): | |
# taken from wsgiref documentation | |
def simple_app(environ, start_response): |
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
# coding: utf-8 | |
''' | |
Given a list of integers, your task is to write a program to output an integer-valued list of equal length such that the output element at index 'i' is the product of all input elements except for the input element at 'i'. | |
In other words, let inputArray by an integer array of length 'n'. The solution,computed into outputArray, would be: | |
for each j from 1 to n-2: | |
outputArr[ j ] = inputArray[0] * inputArray[1] * inputArray[2] * ... * inputArray[j-1] * inputArray[j+1] * inputArray[j+2] *...* inputArray[n-1] | |
for j = 0 |
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
# coding: utf-8 | |
''' | |
Frequency Counting of Words / Top N words in a document. | |
Given N terms, your task is to find the k most frequent terms from given N terms. | |
Input format : | |
First line of input contains N, denoting the number of terms to add. |
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
# coding: utf-8 | |
''' | |
Implement a circular buffer of size N. Allow the caller to append, remove and list the contents of the buffer. Implement the buffer to achieve maximum performance for each of the operations. | |
The new items are appended to the end and the order is retained i.e elements are placed in increasing order of their insertion time. When the number of elements in the list elements exceeds the defined size, the older elements are overwritten. | |
There are four types of commands. | |
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
# coding: utf-8 | |
''' | |
Given an unordered list of N elements, write a function to find the top four elements of the given list. Make sure your function runs in linear time O(N). | |
Input format : | |
First line of input contains N , number of elements in list. | |
Next N line , each contains a element. | |
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 | |
# coding: utf-8 | |
import itertools | |
def find_min_skill_difference(skills): | |
n = len(skills) | |
if n == 2: | |
return abs(skills[0] - skills[1]) | |
skills.sort() |
NewerOlder