>A building has (input) N floors. One of the floors is the highest floor an egg can be dropped from without breaking. If an egg is dropped from above that floor, it will break. If it is dropped from that floor or below, it will be completely undamaged and you can drop the egg again. >You are given two identical eggs, find the minimal number of drops (output) it will take in the worst case to find out the highest floor from which an egg will not break.
Julian Barnes
2.
Josiah Reyes
O(N / 2)
Drop from middle, if it breaks start from floor 1 and work your way up.
If it doesn't break, start from middle + 1 and work your way up.
Josiah Robinson
Forgive me for being a brainlet but if I were to program this, would the highest floor an egg wouldn't break from be a random int 1 to N or >1 &
Xavier Evans
tard detected If you do that: >let k be the highest floor >for k=49, N=100: >egg breaks at 50 >You now have to test each one floor: starting from 1 and making 50 tests total Now consider checking every, say, 20 (for N=100): >worst case scenario is you need around 25 tests
Bentley Peterson
Or you can do it like an sort of shell sort approach.
Start a 1/4 up, if it breaks, test the lower 1/4.If it doesn't break, try 2/4. If it breaks at 2/4. Test 1/4+1 up to 2/4-1. If it doesn't break, try at 3/4. etc...
Jaxon Bennett
Generalise that in order to show that you're not a mental midget.
Wyatt Sullivan
>k=19, N=100 >egg breaks at 20 (attempts, n=1) >have to test every step i for i in range 1 to n-1 There's gotta be a general solution to finding partitions that's better though.
Isaac Wilson
Don't feel like it You also have to note that it's better to have the tests spaced out somewhat closer together near the end than in the beggining there is, but I'm a lazy tard
Andrew Bailey
>You also have to note that it's better to have the tests spaced out somewhat closer together near the end than in the beggining So step/partitions are a logarithmic function.
Aiden Fisher
If you start at sqrt(N), the maximum number of steps is 2*sqrt(N)-1 when moving through the floors in a naive way. But when you reach the top, you'll want to recurse to sqrt(sqrt(N)). That gets you down to 2*sqrt(N)-2 for sufficiently large value of N. After that, I'm not sure you can optimize further.
Camden Anderson
>If it doesn't break, start from middle + 1 and work your way up. Ahh, you didn't think it through, brainlet. Since the egg isn't broken, you can split the upper amount of floors in half, and do the drop with the first egg, until it breaks.
Then, with the second egg you only do the floors from the second last drop until the last drop.
Isaiah Cook
Just do a binary search, you fucking faggot
log n
Camden Ward
You're not Mr.birb >:o
Asher Hernandez
Theoretical limit is O(sqrt(N)) for 2 eggs, but for specific N, you can find a slightly better solution.
3 eggs is cube-root of N.
William Fisher
not pure log n, since there are two eggs, and you use the second one to find the max floor.
Charles Perez
>Ahh, you didn't think it through, brainlet. >Since the egg isn't broken, you can split the upper amount of floors in half, and do the drop with the first egg, until it breaks. Oh, yeah right.
Sebastian Davis
If a stair has N steps, and you can climb either one or two steps for each step. How many permutations of ways to climb those stairs is there?
I was asked this on an interview for a position at Google (and I nailed it, but didn't get the job because I wasn't a culture fit).
Ian Scott
Create a generating function of a = a-1 + a-2.
Matthew Cooper
Also known as?
Noah Nguyen
The Fibbonacci sequence.
Kevin Martinez
Correctomundo
Parker Clark
Try round(n/2)=a For i
James Gomez
O(log(N)) if you do a binary search
Camden Evans
Binary search doesn't work since you only get two eggs. Worst case scenario is N/2.
Jack Walker
Array(0)=a i=1
Easton Richardson
>Worst case scenario is N/2. See and +
Xavier Sullivan
he meant for binary seearch
Nathan Gomez
That's not technically binary search though. That's just partitioning it into two and searching linearly. You can partition it into 3 or 4 or 5 or whatever, hence the general solution is
Jace Watson
>That's just partitioning it into two and searching linearly. Well, yes, that's my point. Binary search doesn't work and you need a more sophisticated algorithm such as
Charles Brooks
divide and conquer?
Jack Turner
I can do 1000 floors with 44 drops.
Matthew Nelson
The idea is of this problem is to powergame the algorithm so that it is specifically optimized for the worst case (at the expense of the average case). This is why binary search answers are wrong.
Cameron Allen
Enlighten me senpai
James Smith
Please explain
Samuel Stewart
The worst cases should be equal, if they're not you're wasting drops somewhere else that could be used on that worst case. That means the number of first egg drops plus the number of possible floors once it breaks (because must linear search with 2nd egg) should stay at a constant. What is this constant?
Kayden Roberts
A stair that has only one step can only be climbed in one way, by taking one step.
A stair that has two steps can be climbed in two ways, either by taking one+one step or by taking a single two-step step.
A stair with three steps is the sum of the above, you can either climb it one+one+one, or two+one or one+two, giving you three ways to climb it.
So for N steps, the function becomes f(N) = f(N-1) + f(N - 2)
Christopher Clark
>generating function for simple recurrence boi
Hudson James
Every vertex of a graph has at least N neighbors, prove there is a cycle that's at least N+1 long.
Julian Foster
It's 45 drops for 1000 floors you fucking brainlet
Leo Roberts
There was a thread about finding new relevant questions for interviews. This would be dope to test recursion skills.
Asher Harris
>a vagina in a vagina in a vagina in a vagina
Jeremiah Wood
1 because I'm not a retard and know that eggs break when dropped from damn near any height
Ayden Price
They're fucking eggs, they'll break from one story. There has got to be a better way to set up this problem.
Samuel Martinez
It's vaginas all the way down.
Aiden Morales
>inb4 muh titanium eggs
James Howard
O(N/2 + 1).
Start dropping from bottom. Move 2 floors higher. Continue if it doesn't break. When it breaks, move one floor down. If it breaks then, it's the floor. If it doesn't, the right one is higher one.
Benjamin Kelly
You can use only two eggs and if at one point it breaks then you didn't find out the point, the algorithm cant continue etc.
Anthony Sanders
That's the worst solution yet.
Blake Hughes
Do your own homework.
Xavier Carter
I'd rather make an omelet.
Michael Martinez
Start from the middle. If it breaks, move half-way down. If it doesn't, half-way up and so on..
Brayden Torres
>Start from the middle. If it breaks, move half-way down And it breaks there as well. Now you've wasted your two eggs and you didn't find the floor.
James Thompson
...
Henry Smith
>..find the minimal number of drops Please tell me how you plan to find 1/100 floors in two tries. >>>reddit
Jaxson Russell
one egg 1/3 of the way up, the other 1/6. work in quarters or halves from there.
Jack Rodriguez
>Please tell me how you plan to find 1/100 floors in two tries. Not in two tries, but in 2 * sqrt(N) tries.
Luis Lopez
I can do it in 0. It's a fucking egg - it breaks every time.
Jason Diaz
What if the building is on the moon or somewhere else where gravity is reduced?
Or the building is really small?
Or under water, or where air is blowing upwards so the fall is slowed down due to the displacement effect?
Jaxon Nelson
Obviously they're not chicken eggs.
Jonathan Edwards
That adds extra conditions to the problem. If we could just do that then we'd have infinite solutions to every problem.
Isaiah Stewart
must be either directed or undirected with vertexcount > 2 or you can easily disprove by a 2-chain
Joshua Thomas
the egg will always break if dropped from the third floor so 0
Carter Torres
> create army of chickens > wait for them to drop eggs > hav moar egz > drop one egg every floor
ADVANCED ALGORITHMS, BRO
Eli Barnes
>tfw you're a System Administrator(R) Master Race(TM) and you don't have time for this shit. Kill yourselves, code monkeys.
Matthew Davis
It’s undirected. Obviously doesn’t hold for N=1, but I believe it hold for N>1, including 2.
Gavin Wilson
It's pretty apparent no one else is going to answer the original question.
ceiling((sqrt(8 n + 1) - 1) / 2)
Justin Evans
2 drops.
You drop it at the bottom floor, just above the floor. It does not crack. You drop it from the second floor. No egg can survive a two story drop.