r/programming • • May 08 '15

Five programming problems every Software Engineer should be able to solve in less than 1 hour

https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
2.5k Upvotes

2.1k comments sorted by

View all comments

334

u/vital_chaos May 08 '15

Yeah I write Fibonacci sequences all the time. It's my hobby. /s Why do people think that writing short test functions in an interview has anything to do with actually delivering products? Sure some ditch digger might fail at these, but does it tell you anything about how well they build actual apps?

204

u/mughinn May 08 '15

While I never interviewed anyone, time and time again people who do, write blogs and posts about how only 1 in 200 persons who apply for programming jobs can solve those kind of programs (like fizzbuzz).

I have no idea how true that is, but if it is anywhere close to that, then yeah, if they CAN'T solve those problems it shows a lot about the ability to write apps, mainly that they can't.

66

u/CaptainStack May 08 '15

Why don't I ever get asked FizzBuzz? I feel like all the problems I get in interviews are really really hard.

37

u/eythian May 08 '15

I had one interview where the coding section was first implement fizz-buzz, then write an algorithm to find cycles in graphs.

The first was clearly "can you code, or are we wasting our time", the second was "did you actually learn anything in your computer science course."

13

u/CaptainStack May 08 '15

I don't think I've ever had a first round that wasn't an order of magnitude harder than FizzBuzz.

21

u/[deleted] May 08 '15

A friend of mine was recently asked to implement a spreadsheet application at one interview, and a space invaders game on the other. I think it's about time to start invoicing the interviewers for your time on test assignments.

8

u/SirNarwhal May 08 '15

Exactly. Spent fuckin 2 days making some ridiculous over-engineered game of Rock Paper Scissors in Angular for one test just to have them not respond for 2 weeks in which time I found a job elsewhere. Multiply that by like 30-40 interviews when you're looking and it's more work than a full time job.

→ More replies (1)

39

u/nitiger May 08 '15

the second was "did you actually learn anything in your computer science course."

Oh, sure. Let me just recall something from 2 years ago that I learned as a Sophomore, no biggie.

33

u/NecroDaddy May 08 '15

Two years ago bud? Try 15 for me. I had one week to relearn everything from college.

→ More replies (1)
→ More replies (9)
→ More replies (5)

0

u/[deleted] May 08 '15

[deleted]

12

u/cles30 May 08 '15

I guess you could do that but oh god why?

10

u/zarazek May 08 '15

That's standard queue implementation in functional languages (this data structure is persistent).

8

u/cles30 May 08 '15

ooh you said the magic f word. I must now find out all about this!

→ More replies (1)

6

u/[deleted] May 08 '15

Hey you can do it, it'll just take O(N) to do a push operation. That's the type of out of the box thinking we need. /s

→ More replies (5)
→ More replies (11)
→ More replies (2)

22

u/jakdak May 08 '15

Back when C was the primary development language, I used to ask folks to reimplement the standard library string compare function.

All I was really looking for was a loop and some indication that the applicant knew that strings were basically character arrays.

A very depressing number of folks either couldn't or wouldn't do it.

→ More replies (34)

9

u/joequin May 08 '15

I've was told at several of my first job interviews that I was the first person to successfully solve fizz buzz.

→ More replies (3)
→ More replies (146)

79

u/[deleted] May 08 '15

How do they interview chefs? Apparently, they first ask them to do something really simple, like fry an egg and watch how they do it.

I've auditioned musicians - I start by getting them to play a few scales. Scales are trivial but it's amazing what you can learn about someone by how well they play scales.

I've interviewed literally hundreds of programmers and you learn a great deal about someone by getting them to do simple programs.

8

u/s73v3r May 08 '15

Depending on the type of musician you're interviewing, wouldn't they be playing some scales to warm up?

30

u/AD6 May 08 '15

Drummer here, in my experiences with musicians it's all about chemistry. I've played with people who are very technically skilled, but have no idea how to actually jam with other musicians. Little off track from OP, but just wanted to add my 2 cents.

→ More replies (7)
→ More replies (4)

19

u/RICHUNCLEPENNYBAGS May 08 '15

I think the point is that they're necessary, not sufficient.

→ More replies (1)

0

u/[deleted] May 08 '15

[deleted]

11

u/creepy_doll May 08 '15

Based on the descriptions of the other problems I doubt that the provided list would be so large as to cause issues with a naive recursive function

5

u/lengau May 08 '15

I think what Lawtonfogle means is along these lines:

There are two (well, far more than two, but let's only discuss these two) ways to write the Fibonacci function. One is to write a helper function that naïvely recursively calculates the nth Fibonacci number. In Python, something like this:

def fib(n):
    if n == 0 or n == 1:
        return n
    return fib(n-1) + fib(n-2)

and then write a function that loops from 0 to 99, running the helper function on the looped number.

This method works, but is exceedingly slow. I wrote a quick script that counted the number of calls based on the input n and ran it in a loop for the first 35 Fibonacci numbers:

fib calls for 0: 1
fib calls for 1: 1
fib calls for 2: 3
fib calls for 3: 5
fib calls for 4: 9
fib calls for 5: 15
fib calls for 6: 25
fib calls for 7: 41
fib calls for 8: 67
fib calls for 9: 109
fib calls for 10: 177
fib calls for 11: 287
fib calls for 12: 465
fib calls for 13: 753
fib calls for 14: 1219
fib calls for 15: 1973
fib calls for 16: 3193
fib calls for 17: 5167
fib calls for 18: 8361
fib calls for 19: 13529
fib calls for 20: 21891
fib calls for 21: 35421
fib calls for 22: 57313
fib calls for 23: 92735
fib calls for 24: 150049
fib calls for 25: 242785
fib calls for 26: 392835
fib calls for 27: 635621
fib calls for 28: 1028457
fib calls for 29: 1664079
fib calls for 30: 2692537
fib calls for 31: 4356617
fib calls for 32: 7049155
fib calls for 33: 11405773
fib calls for 34: 18454929
fib calls for 35: 29860703

Obviously, 30 billion function calls is, shall we say, less than ideal for a problem like this. Especially when a 5-line function that builds a list of (or simply prints) the first n Fibonacci numbers uses no recursion (just a single loop) takes orders of magnitude longer to fire up Python than it does to run the function (and even then, the slowest part is running print a hundred times rather than putting it in a string and printing that once).

→ More replies (4)
→ More replies (8)
→ More replies (1)
→ More replies (67)