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

37

u/Drolyt May 08 '15

I think you are over-thinking 4. Just brute force it: find all the possible concatenations and then use the max function your language most likely provides. You can find an efficient way to do it after the hour is up.

13

u/KFCConspiracy May 08 '15

I'd probably question that pretty hard and make the candidate rewrite that in a non-brute force manner.

13

u/conflare May 08 '15

"The requirements placed a priority on time to market, so I optimized for that."

But I would feel dirty.

3

u/hpp3 May 08 '15

In my experience with interviews like this, that bullshit won't fly. If the interviewer has an elegant runtime in mind, s/he's looking for that runtime, and you'll get prompted and prodded ("is there a better solution?") until you give a solution with that runtime or you give up.

The only question here where brute force is acceptable is #5 because 1) there isn't a better way to do it and 2) you are given an explicit bound.

→ More replies (2)

5

u/flukshun May 08 '15

i'd call the police on them for computer abuse

4

u/[deleted] May 08 '15

It's better than all the supposedly clever but incorrect solutions posted here.

→ More replies (1)

2

u/pohatu May 08 '15

But if they used hadoop and map-reduce it would definitely be a hire! Sde3!! Lol

0

u/[deleted] May 08 '15

[deleted]

18

u/[deleted] May 08 '15

20, 2, 2

14

u/__Cyber_Dildonics__ May 08 '15
  1. That doesn't scale.

  2. The method above could be done in one line (but probably should be done in 2 or 3.

51

u/jacenat May 08 '15

That doesn't scale.

It will never run anywhere ... who cares? You can even tell the interviewer that it wouldn't scale, but it would run for most real world examples. If it's really an issue to make it robust enough to run in a specific environment with a as low as possible runtime, 1 hour is probably not enough to optimize it anyway.

14

u/joequin May 08 '15

One hour us more than enough time to use the much better substring algorithm. I don't think you would be dismissed outright for the brute force algorithm, but someone who used the substring method will have that in their favor.

10

u/Atlos May 08 '15

Isn't it one hour total to solve all 5 problems? Given that some have multiple parts, that's less than 12 minutes per problem.

5

u/HighRelevancy May 08 '15

The first three should take about 5-10 minutes all up (if you're bad at getting your thoughts written out).

5

u/[deleted] May 08 '15

You forget the 5-10 minutes per question where you have to guess the thoughts of the guy that has a stick up his ass.

→ More replies (4)

2

u/Dementati May 08 '15

The first three are trivial, though. They should take the time it takes to write the code, basically.

→ More replies (1)
→ More replies (1)
→ More replies (2)

3

u/Guvante May 08 '15

Honestly that is fine as long as you can explain why and work your way towards a better solution. However you are correct that a good developer would ideally see that and shortcut to a better solution.

25

u/Drolyt May 08 '15 edited May 08 '15

However you are correct that a good developer would ideally see that and shortcut to a better solution.

Based on how many people in this thread have given an incorrect solution based on lexicographical sorting I'm not sure that is really all that good an idea. Starting with a simple and correct but inefficient solution seems better to me.

14

u/hvidgaard May 08 '15

A good developer that is about to write a rather complex, but efficient algorithm, will make the trivially easy bruteforce solution as the first thing. Then use that to create and verify the correctness of the complex algorithms edgecases. It baffels my mind how many developers that doesn't do this when they actually have to write an algorithm.

→ More replies (1)

2

u/awj May 08 '15

...was scaling part of the requirements? I've solved more than one real world problem where "here's the answer for what you asked, this totally won't work for 2/3/X times more data" was happily accepted.

1

u/goomyman May 08 '15

i really like this solution honestly, props.

3

u/isarl May 08 '15

It's a bad solution. Brute force is more effective for #5. For 4, a greedy approach will work – always take the next number with the highest leading digit. If you have two numbers starting with, e.g., 9, then recurse on each and take the max.

1

u/skewp May 08 '15

Good point. I immediately thought of brute force for #5 but didn't consider brute force for #4 at all.

→ More replies (7)