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 getInt(): | |
return int(input()) | |
def getListOfInts(): | |
return list(map(int, input().split(' '))) | |
def main(): | |
t = getInt() | |
main() |
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
# 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 = [] |
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
''' | |
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 } |
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 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 |
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
''' | |
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/ |
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.
###Array ####Definition:
- Stores data elements based on an sequential, most commonly 0 based, index.
- Based on tuples from set theory.
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
function Planet() { | |
// .... | |
} | |
// create a new prototype object | |
Planet.prototype = {/* .. */}; | |
let mars = new Planet(); | |
mars.constructor === Planet; // false | |
mars.constructor === Object; // true |
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
function Planet() { | |
// .... | |
} | |
Planet.prototype.constructor === Planet; // true | |
let mars = new Planet(); | |
mars.constructor === Planet; // true |
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
function Planet() { | |
// .... | |
} | |
let mars = new Planet(); |
NewerOlder