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

2

u/arocketman May 08 '15

This is how I solved the first 4 problems in Java. Fifth one is ... not that easy really :/ .

https://gist.github.com/arocketman/8c4bb3415aec97176e48

1

u/jpapon May 08 '15

The fifth one isn't too hard, just think of it as a graph. Each edge can be either "connect", +, or -. Starting with 1, you build a graph with the integers as nodes, and each node having all three edge possibilities connecting it to a node with the next integer.

Finding all possible paths in the graph that sum to 100 is easy using an exhaustive recursive search. The full graph is a tree with ~30k nodes, which isn't that bad really, especially since it's a very wide tree - the max path length is just 9.

→ More replies (4)