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

584

u/__Cyber_Dildonics__ May 08 '15

The fifth question doesn't seem nearly as easy as the rest (the fourth question is not that hard guys).

186

u/orclev May 08 '15

That fifth one honestly has me a bit stumped... I can see how to brute force it, but there's got to be a simple solution. All the others are pretty simple and shouldn't require too much thought even if you've never seen them before.

90

u/__Cyber_Dildonics__ May 08 '15

Other people have mentioned brute forcing it, and if I was in an interview that's what I would do in that situation.

80

u/mccoyn May 08 '15

It will take longer to write a more complicated solution than to run the brute force algorithm, so brute forcing is the fastest solution.

11

u/jason_rootid May 08 '15

Given the nature of the problem I think brute forcing it is the only solution. There isn't exactly a known formula to calculate that kind of thing, and given the constraints of the operations I doubt there is one.

3

u/R3PTILIA May 09 '15

There is a better way, dynamic programming

2

u/comp-sci-fi May 09 '15

Hi I've never managed to get clear on the definition of "dynamic programming", can you elaborate to help me, please? (below is what I think).

(Apart from your sib comment) I think it's a way of recording intermediate results, and when the same one appears again, effectively merge them, instead of recalculating.

But here, I think the only dynamic programming we can do is only a slight implementation improvement on raw brute force, and reusing earlier calculations. It falls naturally out of a DFS: given first choice (12 or 1+2 or 1-2) you calculate that, and use it as the starting point for the next choice. Do the same thing recursively.

→ More replies (2)