Skip to content

Instantly share code, notes, and snippets.

View les-peters's full-sized avatar

Les Peters les-peters

View GitHub Profile
@les-peters
les-peters / 2020-12-21.py
Created December 21, 2020 13:20
Story Publisher
import datetime
question = """
You are building stories into an app. Your inputs are an object with the
structure { username, postedAt }, and a date in the future. Each story lives for
24 hours. Write a function that outputs the stories that are visible for the
inputted time.
"""
@les-peters
les-peters / 2020-12-28.py
Created December 28, 2020 15:05
Find 2020
import re
question = """
You’re given a string of characters that are only 2s and 0s. Return the index of
the first occurrence of “2020” without using the indexOf (or similar) function,
and -1 if it’s not found in the string.
Example:
$ find2020(‘2220000202220020200’)
@les-peters
les-peters / 2021-01-04.py
Created January 4, 2021 16:41
Turn on the light!
import math
question = """
You’re trying to build an IoT mesh network. Signals can only travel the maximum of 5 units.
You’re given coordinates for the switch, the light, and the mesh hubs (which capture and forward
signals). Return true if the switch can successfully toggle the light.
Example:
let network = { switch: [0,1], hub: [[2,1], [2,5]], light: [1,6] }
@les-peters
les-peters / 2021-01-11.py
Created January 15, 2021 13:38
Binary Squares
from itertools import product
question = """
Given a n x m binary matrix filled with 0s and 1s, find the largest rectangle
containing only 1s and return its area.
Example:
$ matrix =
['1','0','1','0','0'],
@les-peters
les-peters / 2021-01-18.py
Created January 18, 2021 15:06
Hash without Hashes
import os.path
from os import path
import csv
question = """
Design a hashmap without using any built-in libraries. You should include the following functions:
- put(key, value): Insert a (key, value) pair into the hashmap. If the value
already exists, update the value.
@les-peters
les-peters / 2021-01-25.py
Created January 26, 2021 00:40
Rotate square array
question = """
Given an n x n array, rotate it 90 degrees without making a new array.
Example:
$ rotate90([[1,2,3],[4,5,6],[7,8,9]])
$ [[7,4,1],[8,5,2],[9,6,3]]
"""
@les-peters
les-peters / 2021-02-01.py
Created February 1, 2021 16:43
Latest price
question = """
You are given a snapshot of a queue of stocks that have changing prices coming in from a stream. Remove the outdated stocks from the queue.
Example:
$ snapshot = [
{ sym: ‘GME’, cost: 280 },
{ sym: ‘PYPL’, cost: 234 },
{ sym: ‘AMZN’, cost: 3206 },
{ sym: ‘AMZN’, cost: 3213 },
@les-peters
les-peters / 2021-02-08.py
Created February 8, 2021 14:37
Product List
from functools import reduce
question = """
This week’s question:
Implement a ProductList class that has two methods,
add(n) (which pushes the value n to the back of the list) and
product(m) (which returns the product of the last m numbers in the list).
David made an awesome template for submitting your solutions, if you’d like to use it!
@les-peters
les-peters / 2021-02-15.py
Created February 15, 2021 17:30
Sentence Search
question = """
Given a string str and a dictionary dict containing a list of non-empty words, add spaces in
str to construct a “sentence” where each word is a valid word in dict. Return all possible
sentences. You are allowed to reuse the words in dict.
Example:
str = “penpineapplepenapple”
dict = [“apple”, “pen”, “applepen”, “pine”, “pineapple”]
$ makeSentence(str, dict) $ [ “pen pine apple pen apple”, “pen pineapple pen apple”,
@les-peters
les-peters / 2021-02-22.py
Created February 22, 2021 13:52
Every Other
import re
question = """
Given a string str containing only the characters x and y, change
it into a string such that there are no matching adjacent characters.
You’re allowed to delete zero or more characters in the string.
Find the minimum number of required deletions.
Example: