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
# TODO We can modularise this function better; too long | |
def longestChain(words): | |
# Initialise a hashtable mapping string length to the words | |
word_dict = {} | |
# List of word lengths in `words` | |
length_list = [] | |
for word in words: | |
if len(word) not in length_list: | |
length_list.append(len(word)) |
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
def friendCircles(friends): | |
# TODO: Could use a hashtable here to find if an element faster | |
seen = [] | |
num_friend_circle = 0 | |
# Let's look at each person's set of relationships | |
for i in xrange(0, len(friends)): | |
if i in seen: | |
continue | |
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
import math | |
primes = [2] | |
def get_primes(n): | |
# Basic input validation | |
assert n >= 0 | |
# Let's check what we have memoised already | |
if len(primes) >= n: |
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
import ast | |
import hashlib | |
from flask import Flask, request | |
app = Flask(__name__) | |
""" | |
I assume this is a stateful service where GET requests are only | |
to be served when a POST has been done on that same message. The | |
"original message" reference is unclear. |
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
import collections | |
import sys | |
""" This program's BigO notation is O(n) """ | |
""" We look at every element in the list at most once """ | |
""" For the three person gift case, the BigO notation is O(n^2) """ | |
def find_closest_pair(products, target): |
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
import sys | |
""" This program's BigO notation is 2^X """ | |
def find_combinations(string): | |
""" | |
Given a string with X as placeholders, replace them and find | |
all combinations with 0s and 1s | |
""" |
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
import java.io.*; | |
import java.util.*; | |
import java.text.*; | |
import java.math.*; | |
import java.util.regex.*; | |
class TreeNode { | |
TreeNode left; | |
TreeNode right; |
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
# Design a garage | |
# Given a schedule for 24 hours | |
# Entry and exit schedule of the garage | |
# API, take a time and return number of buses in the garages | |
# Interface to define the schedule | |
# ID EnterTime ExitTime | |
# 1 00:30 02:30 |
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
Q. Amazon has a portfolio with many buildings and warehouses that it manages for utility monitoring. | |
We have an api provided with a function: Future<AddBuildingResponse> addBuildingToPortfolio(Building building) | |
Implement a function that accepts a list of Buidlings and makes that call to add the buildings to our portfolio. This function should fail if any building fails to add, and return success only if all buildings are added successfully. | |
async getResponse (future) => // wait 3 s if response is present return, if not continue (gets nothing back) | |
You can additionally assume AddBuildingResponse contains a isSuccess flag to check for status | |
@coroutine | |
def addBuildingsToPortfolio(bldgs_requests): | |
''' |
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
# A Blob is a shape in two-dimensional integer coordinate space where all cells have at least one | |
# adjoining cell to the right, left, top, or bottom that is also occupied. Given a 10x10 array of | |
# boolean values that represents a Blob uniformly selected at random from the set of all | |
# possible Blobs that could occupy that array, write a program that will determine the Blob | |
# boundaries. Optimize first for finding the correct result and then for minimizing the number of | |
# cell value reads, balancing minimization against elegance and clarity. | |
# Assumptions: | |
# |