Skip to content

Instantly share code, notes, and snippets.

@Obayanju
Obayanju / input-template.py
Last active February 16, 2021 22:38
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()
main()
# 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.
Example:
$ 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
bills.reverse()
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.
https://leetcode.com/problems/koko-eating-bananas/
@Obayanju
Obayanju / The Technical Interview Cheat Sheet.md
Created February 7, 2019 13:09 — forked from tsiege/The Technical Interview Cheat Sheet.md
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.

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.
function Planet() {
// ....
}
// create a new prototype object
Planet.prototype = {/* .. */};
let mars = new Planet();
mars.constructor === Planet; // false
mars.constructor === Object; // true
function Planet() {
// ....
}
Planet.prototype.constructor === Planet; // true
let mars = new Planet();
mars.constructor === Planet; // true
function Planet() {
// ....
}
let mars = new Planet();