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

Show parent comments

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.

3

u/Paranemec May 08 '15

Sounds like they just wanted an application and a game to me.

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)

6

u/bjarkef May 08 '15

Most probably cannot recall a solution, but you should be able to reason about the problem and discover the solution yourself.

3

u/[deleted] May 09 '15

No, this is just wrong. Either you remember it, in which case it doesn't prove anything, or you're fucked. These kinds of solutions and algorithms were discovered by scientist over many years. They are most certainly not something you "come up with" during an interview.

This is exactly why I really have considerable doubt about the effectiveness of a lot of the interview styles of big corporations. Just have a look at these "The Google interview" style of books. You can / should just memorize the whole lot of assignments for these interviews, giving you a huge edge. I'm willing to bet that the set of people that can actually come up with their own solutions to hard problems and do their best while under the constant stress of having an interviewer stare at your back is quite small. Sure, you can weed out "know-nothings" by asking them to write a fizzbuzz solution on the whiteboard because every software engineer that deserves the title can write that without thinking. But as soon as the problems have some real depth and require real thinking, a whiteboard is not the way to go.

→ More replies (1)

6

u/rabbitlion May 08 '15

There's no need to recall a 2-year-old solution, just figure it out again.

2

u/MisterNetHead May 08 '15

Or just look it up? For such a solved problem you should not be spending any time reinventing the wheel.

→ More replies (4)

5

u/matthieum May 08 '15

did you actually learn anything in your computer science course.

I did, first year of engineering school, if only it wasn't 10 years ago I might even be able to do it off the top of my hat still...

... never working with graphs of any sort in the last 10 years I've just forgot all about those algorithms.

2

u/Bwob 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.

Off topic, but the cycles-in-graphs problem is a REALLY bad interview question. Here's why:

Linked Lists were basically invented ~1955.

The "tortoise and the hare" algorithm for cycle detection was probably invented somewhere ~1967.

In other words, it took the collective body of computer scientists ~12 years to come up with that algorithm from scratch. Expecting someone to have that same insight during a 1-hour interview is lunacy. It's basically just a test of "have you heard of this clever solution before?"

It's an awful interview question, and anyone asking it in a technical interview probably doesn't understand how to interview as well as they think they do.

2

u/nidarus May 09 '15

Is the tortoise and hare the only solution though? Can't you just do a DFS, keep a list of all the ancestor nodes, and if you get to a node that's in the list, you have a cycle?

It's not O(n)/O(1), but nobody said it has to be.

→ More replies (1)

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

5

u/Bobshayd May 08 '15

It's amortized O(1), though.

2

u/[deleted] May 08 '15 edited May 08 '15

Nope, you you have to upload the entire stack and push it to the other one. This has to be done whenever adding an element.

8

u/serados May 08 '15

Maintain a "Queue Stack" and a "Dequeue Stack".

On queue operation:

  • Push element into "Queue Stack"

On dequeue operation:

  • If "Dequeue Stack" is not empty, pop "Dequeue Stack"

  • Else, pop and push every element from the "Queue Stack" into the "Dequeue Stack" - O(N) and pop the "Dequeue Stack"

Informally, every element is at most pushed twice and popped twice over (once each into the "Queue" and "Dequeue" stacks) and pushes and pops are O(1), making queues/dequeues amortized O(1).

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