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

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)