This file contains hidden or 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
| # 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 |
This file contains hidden or 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 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 |