Failed fibonacci question

I just failed a technical interview where they asked me to print and solve the fibonacci series.

Im a fresh graduate. How fucked am i? Not only regarding this interview but getting a programming job in general.

Could an average graduate who hasnt done a fib function in 2-3 years be able to implement a solution on the spot?

Attached: 1547136569080.jpg (750x741, 42K)

Other urls found in this thread:

wolframalpha.com/input/?i=[[4,4,1,0],[1,4,2,0],[2,1,0,0],[1,1,0,0]] * [[3],[2],[1],[1]]
twitter.com/NSFWRedditVideo

why did you fail it? couldn't you just look that up online?

it was from a dishwasher position

there was no internet in the restaurant

Onsite, whiteboard interview

>implying you can get a dishwasher interview without a degree, industry work and 10 years experience with Angular

Attached: 0b7b209f2d27afce50a56a1749461de84d85ae235f21e803838d1a9782a5a4af.png (4760x4986, 2.61M)

Bump.

so they wanted an infinite loop?

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.

desu you're pretty fucked user, recursive algorithms like this were part of my freshman curriculum

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.

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?

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.

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.

>It's babbys first recursive loop
Fib is rather inefficient and very slow as recursion

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

forgot the actual link:
wolframalpha.com/input/?i=[[4,4,1,0],[1,4,2,0],[2,1,0,0],[1,1,0,0]] * [[3],[2],[1],[1]]

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...

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

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

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.

nigger, how would you possibly construct a program that needs 13000 moves for fib(20)

fib is literally o(n)

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.

read more cs books, giving up is for pussies. it's a different skill set than just writing a program

>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.

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.)

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.

fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)

add some memoisation if you feel lucky punk

>literally 1+1+2...
Did you not prepare for the interview?

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

iterative is faster lots of the time

Ever heard of a generator, coroutine, closure, lazy evaluation, etc?

mmm ok. thanks guy

it's more elegant and just as efficient if your languages implementation has tail call optimisation

yeah most of what I do (not by choice) is in MATLAB which is possibly the least elegant and orthogonal language of all time

read recursive is faster and started to question that a bit later and reread your post

to be fair it does vary by language, i concede

in addition i will argue iterative for fib and recursive for trees

sounds about right

for future reference
new Array(1000).fill().reduce((a)=>[a[0]+a[1],...a],[1,0]).reverse()

terrible

kekekek

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';
}

it prints a meaningless string forever in addition to never updating three

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
}

I don't think you understand how a loop works.

>while i < 1
>do something forever, never stopping because you never change i

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.

LMAO GET FUCKT PAJEET

>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;

matrix m(2, 2), fib(2,2);
m(0,0) = m(1,0) = m(0,1) = 1;
m(1,1) = 0;
fib = m;
while(n--){
std::cout

BOOST NIGGAS

Attached: gangsterpartyline.jpg (650x460, 68K)

Behold the power of a CS major.

Just solve the recurrence and give them the closed form solution
All I can remember is it has a sqrt 5 in it.

>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.

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.

Recursive fibonacci is dogshit, it has some massive exponential blowup around n=47 if I recall correctly.

Literally 2 lines in Matlab

F=[1,1; 1,0]^(n-1);
return F(1,1)

*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.)

Do they not teach dynamic programming in yank CS courses? Is everyone just retarded over there?

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.

WRONG
recursive fibonacci is not tail recursive get the fuck out

Have you seen CS degrees? You're lucky if you even see Algorithms and Job Interviews in your 4th year.

Attached: typical cs degree.png (574x839, 55K)

>and it's exponential

Actually it's double exponential in the bit length of n. The smart way is repeated squaring that makes it O(n) aka O(log |n|).

>Fall 1
>Fall 2
>Fall 3
>Fall 4
oh gott

>falling for obvious bait
ishygddt.jpg

That's what most places call their Aug to Dec semester.

They've really dumbed things down over the decade.

Attached: 531A5B0C-06AE-4712-95A5-4BA86746C5C2.jpg (640x480, 55K)

```
fib = lambda n: ((1 + np.sqrt(5))**n - (1 - np.sqrt(5))** n )) / (2**n * np.sqrt(5))
```

>using numpy for sqrt
>using floats

rude and retarded, back to school kid

fib n
| n == 0 = 0
| otherwise = fib (n - 1) 1 0
where fib n a b
| n == 0 = a
| otherwise = fib (n - 1) (a + b) a

>Could an average graduate who hasnt done a fib function in 2-3 years be able to implement a solution on the spot?

Considering the Fibonacci sequence is just the sum of the two previous numbers, yes.

Simple loop function, probably one of the easiest things you'll ever be asked.

Who taught you how to program? This is like first year CS shit

>recursive fibonacci
that must explain why everything is so bloated these days

Really make me happy about my choice of uni.

I got asked the size of a char at an interview once