I assume so yes. It's an easy problem and the only hard part is figuring out what the question "means", as the word "fibonacci" itself is a useless thing to ask someone, but if they said "fibbonacci is where......" and then asked you to do it, you should be able to. It's babbys first recursive loop.
Anyway since you failed it, learn it now so you can do it easily if it's ever asked again, practice it and things like it every day until you can get it right without even thinking, and learn how you can make it better than the default top google answer.
Jordan Wilson
desu you're pretty fucked user, recursive algorithms like this were part of my freshman curriculum
Jaxson Hill
If you didn't know the definition, but can program, then you should repeat the basics (page 59-60 in my copy of CLRS). It's a simple example that shows that you don't needlessly use recursion (well, without memoization) but can use a loop to compute the Fibonacci numbers more efficiently. You could also talk about one of the closed formulas and the advantages and disadvantages to use it instead of the loop.
Kevin James
probably you just suck at interviews. good news is that you can practice that.
the first thing out of your mouth should be
>"Sure"
then you if you know what you're doing you ask a bunch of questions to make sure what you have in mind is actually what they want.
if you don't know what you're doing you can say shit like
>It's been a while, the Fibonacci sequence was one of those increasing integer sequences, right? It goes like 1, 2, 4, 6..
then they usually stop you and say shit like
> na, 1, 1, 2, 3, 5
and then you say
>"ah, I remember, the pattern is you add this and the previous number to get the next one, right?"
at which stage did you fail?
Lucas Carter
You will instantly fail if you don't know how to write a recursive loop. That's why it's an interview question. It's not the type of thing someone will generally arrive at on their own without knowing about it already.
Justin Sanchez
recursive fibonacci is dumb, unless you have to print a reverse sequence, then maybe. still dumb.
but yeah, I assumed OP just blanked, seeing how he has a degree in CS.
Daniel Lewis
>It's babbys first recursive loop Fib is rather inefficient and very slow as recursion
Juan Scott
here's a matrix you can multiply 4 fibonacci numbers by to get the next 4 what's cool is the elements are powers of two, so you can bit shift
I failed immediately basically. I blanked out and had no idea what parameters to take or how to start the function at all.
All i could say was i know its solved recursively and i said a base case is needed and the final statement would be the recursive call.
They gave me clues and advice but i just couldn't figure out how to start it.
Fuck...
Michael Sullivan
did you ask them to remind you what the fibonacci series was? dont be afraid to ask so you can prove the knowledge you have
Landon Cook
Which is why you should consider things like caching or just using maths where possible to make it better, which is what I was pointing at in the last part of the post.
With caching you cut down from like 13,000~ moves to just 37 for fib(20), while keeping the super clean code that recursion gives
Charles Jackson
Yeah pretty much. I failed nothing at uni and graduated at 22 playing league of legends most of the day, was an addict. Did the bare minimum before exams and assignments.
I felt incredibly stupid trying to solve it. I couldnt start it at all and i had no idea how to set up a function/data members to print the fib sequence. They gave me plenty of clues but i just couldnt think of a solution on the spot.
Starting to think i might not be cut out for programming but I'm going to study a lot and again if/when i get another interview.
Owen Ramirez
nigger, how would you possibly construct a program that needs 13000 moves for fib(20)
fib is literally o(n)
Chase Gray
They told me the about the formula and showed me the first eight numbers. I haven't done any programming since graduating around july of last year, had 0 clue at all how to make a program to solve the problem and essentially did nothing.
Who knows when i will get another interview. This job isnt exactly prestigious and the salary is low. Might have fucked up my last chance at getting a CS job.
Juan Taylor
read more cs books, giving up is for pussies. it's a different skill set than just writing a program
Brody Green
>fesh graduate and can't even write a recursive function What the hell did you spend four years and $60,000 on, exactly? Even high schoolers can do that.
Oliver Hernandez
Can you solve it now, after the fact? If you're still struggling and getting it working feels like an achievement, then I'm afraid you should find a different field. Apparently a lot of people who are still able to get into CS find recursion hard (I honestly can't fathom how) but fib is even trivial to get iteratively. On the other hand if you're able to figure it out now, in the comfort of your home, then you just suck at interviews. I can fire off like five-six sort algorithms including a few parallelised ones off the top of my head right now, but put me in front of a group of HR personnel and roll out the whiteboard and I'll have to think extra hard just to get quicksort written down and not blank. (I could still do fibonacci, though.)
Kayden Hill
What do you mean?
The first solution you will be taught and expected to know is where you call fib(n-1) + fib(n-2) and it's exponential, so you end up with thousands of calls.
Brandon Torres
fib 0 = 0 fib 1 = 1 fib n = fib (n-1) + fib (n-2)
add some memoisation if you feel lucky punk
Christopher Wilson
>literally 1+1+2... Did you not prepare for the interview?
Easton Perry
Can anyone explain to me why the fuck people keep saying you need to write a recursive function for this? I'm an engineer but why wouldn't you just
function [ sum ] = sumFib( n_fib )
n_minus_1 = 0; n = 1; sum = 0;
for i = 1:n_fib sum = sum + n; n_plus_1 = n + n_minus_1; n_minus_1 = n; n = n_plus_1; end
end
Jeremiah Carter
iterative is faster lots of the time
Adrian Thomas
Ever heard of a generator, coroutine, closure, lazy evaluation, etc?
Charles Hughes
mmm ok. thanks guy
Andrew Hughes
it's more elegant and just as efficient if your languages implementation has tail call optimisation
Ayden Martin
yeah most of what I do (not by choice) is in MATLAB which is possibly the least elegant and orthogonal language of all time
Dylan Cooper
read recursive is faster and started to question that a bit later and reread your post
Kayden Morales
to be fair it does vary by language, i concede
James Stewart
in addition i will argue iterative for fib and recursive for trees
Gavin Clark
sounds about right
Charles Fisher
for future reference new Array(1000).fill().reduce((a)=>[a[0]+a[1],...a],[1,0]).reverse()
Ryder Brown
terrible
Carson Anderson
kekekek
Ayden Jackson
I haven't programmed anything in 5 years
is there anything stopping this from working? Ignoring syntax int one = 0; int two = 1; int three = one + two; int i = 0
while ( i < 1 ) { int one = int two int two = int three
Print 'one + two = three'; }
Adrian Morales
it prints a meaningless string forever in addition to never updating three
Jace Nelson
Will it work now int one = 0; int two = 1; int three = one + two; int i = 0
while ( i < 1 ) { int one = int two int two = int three int three = one + two Print int three }
Austin Evans
I don't think you understand how a loop works.
>while i < 1 >do something forever, never stopping because you never change i
Carter Jones
looks like someone trying to learn german and capitalizing every second word because they don't know what a noun is.
you don't even know what a declaration is. maybe stick to python.
Luis Watson
LMAO GET FUCKT PAJEET
Evan Hughes
>I just failed a technical interview where they asked me to print and solve the fibonacci series. Take 45 seconds to write: #include #include #include #include
void fibonacci(uint64_t n) { using namespace boost::numeric::ublas; using namespace boost::multiprecision;
Just solve the recurrence and give them the closed form solution All I can remember is it has a sqrt 5 in it.
Luke Davis
>The first solution you will be taught and expected to know is where you call fib(n-1) + fib(n-2) and it's exponential,
Nobody is taught that. You're taught to carry around 2 variables.
Brody Cox
Only technically yes, besides the first two numbers of the sequence. # Copy user, not rewriting for betterness. x = 0 y = 1
print("0\n1") while True: z = x + y x = y y = z print(z) # Print the Fibonacci sequence infinitely.
Carson Collins
Recursive fibonacci is dogshit, it has some massive exponential blowup around n=47 if I recall correctly.
Zachary Brown
Literally 2 lines in Matlab
F=[1,1; 1,0]^(n-1); return F(1,1)
Gavin Allen
*I mean missing first 3 since his z = x + y is below y = z. (Also that was completely pointless to reply to. I'm bored af.)
Justin White
Do they not teach dynamic programming in yank CS courses? Is everyone just retarded over there?
Cooper Cooper
If spent 4 years and wasted a lot of money on a degree and still can't solve fizzbuzz tier questions like that then you should prepare to start washing dishes.
Hudson Parker
WRONG recursive fibonacci is not tail recursive get the fuck out
Gabriel Nguyen
Have you seen CS degrees? You're lucky if you even see Algorithms and Job Interviews in your 4th year.