Last active
April 29, 2017 19:07
-
-
Save riceball1/cca930e582db3b739629760492719325 to your computer and use it in GitHub Desktop.
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
/** Search | |
1) The share price for a company over a week's trading is as follows: [128, 97, 121, 123, 98, 97, 105]. | |
If you had to buy shares in the company on one day, and sell the shares on one of the following days, | |
write an algorithm to work out what the maximum profit you could make would be. | |
2) Imagine that you wanted to find what the highest floor of a 100 story building you could | |
drop an egg was, without the egg breaking. But you only have two eggs. Write an algorithm to | |
work out which floors you should drop the eggs from to find this out in the most efficient way. | |
3) Imagine you are looking for a book in a library with a Dewey Decimal index. How would you go | |
about it? Can you express this process as a searching algorithm? | |
**/ | |
// 2 -- provides a O(2n) | |
function eggLimit(egg1, egg2) { | |
const buildingHeight = 100; // stories | |
// test 2 eggs by dropping them from the middle, and then move one higher and one lower | |
for(let i = 0; i < buildingHeight; i++) { | |
// test egg1 by moving higher; | |
for(let j = 0; j < builidingHeight; j++) { | |
// test egg2 by moving lower; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment