Skip to content

Instantly share code, notes, and snippets.

Obayanju /
Last active Feb 16, 2021
Useful for getting input in competitive programming questions.
def getInt():
return int(input())
def getListOfInts():
return list(map(int, input().split(' ')))
def main():
t = getInt()
# Space comp = O(n) where n = number of numbers
class ProductList:
def __init__(self):
self.prefixProd = []
# Time Comp = O(1)
def add(self, n):
prefixProd = self.prefixProd
if n == 0:
self.prefixProd = []
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.
$ snapshot = [
{ sym: ‘GME’, cost: 280 },
{ sym: ‘PYPL’, cost: 234 },
{ sym: ‘AMZN’, cost: 3206 },
{ sym: ‘AMZN’, cost: 3213 },
{ sym: ‘GME’, cost: 325 }
def count_bills(bills, amount):
result = 0
for bill in bills:
result += amount//bill
amount %= bill
return result
def count_bills2(bills, amount):
dp = [0] + [float('inf')]*amount
Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i] bananas. The guards have gone and will come back in H hours.
Koko can decide her bananas-per-hour eating speed of K. Each hour, she chooses some pile of bananas, and eats K bananas from that pile. If the pile has less than K bananas, she eats all of them instead, and won't eat any more bananas during this hour.
Koko likes to eat slowly, but still wants to finish eating all the bananas before the guards come back.
Return the minimum integer K such that she can eat all the bananas within H hours.
Obayanju / The Technical Interview Cheat
Created Feb 7, 2019 — forked from TSiege/The Technical Interview Cheat
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.
View The Technical Interview Cheat

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
View constructor-confusion-2.js
function Planet() {
// ....
// create a new prototype object
Planet.prototype = {/* .. */};
let mars = new Planet();
mars.constructor === Planet; // false
mars.constructor === Object; // true
View constructor-confusion.js
function Planet() {
// ....
Planet.prototype.constructor === Planet; // true
let mars = new Planet();
mars.constructor === Planet; // true
View class-mimic.js
function Planet() {
// ....
let mars = new Planet();