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

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.

3

u/R3PTILIA May 09 '15 edited May 09 '15

yes its basically a way to do brute force without having to go with ALL combinations (because many sub problems are repeatedly calculated), but instead remembering (by storing and re-using) previous calculations. So if you start with {1, 2, 3}, you can store all the possible results for the rest of the numbers, and use those stored numbers for every combination of {1, 2, 3}, instead of having to recalculate all the combinations of {4,5,6,7,8,9} for every combination of {1,2,3}

→ More replies (1)