Skip to content

Instantly share code, notes, and snippets.

@ktransier
ktransier / apple_stock.rb
Last active August 29, 2015 14:14
apple_stock.rb
# I have an array stockPricesYesterday where:
# The indices are the time, as a number of minutes past trade opening time, which was 9:30am local time.
# The values are the price of Apple stock at that time, in dollars.
# For example, the stock cost $500 at 10:30am, so stockPricesYesterday[60] = 500.
# Write an efficient algorithm for computing the best profit I could have made from 1 purchase and 1 sale of 1 Apple stock yesterday. For this problem, we won't allow "shorting"—you must buy before you sell.
def best_profit(stock_prices_yesterday)
best_buy_time = 0
@ktransier
ktransier / getProductsOfAllIntsExceptAtIndex.js
Last active August 29, 2015 14:14
getProductsOfAllIntsExceptAtIndex
// You have an array of integers, and for each index you want to find the
// product of every integer except the integer at that index.
// Write a function get_products_of_all_ints_except_at_index() that takes
// an array of integers and returns an array of the products.
function getProductsOfAllIntsExceptAtIndex(arrayOfIntegers) {
var totalProduct = 1;
var arrayOfProducts = [];
// Find total product of all integers