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

3

u/Otis_Inf May 08 '15

The fibonacci one is also silly for another reason: if you know the trick (as in: you have seen the code before and remembered how to do it), you know the answer, so it tests on that you know the answer, rather than that you can solve something with recursion (which is the underlying CS element taught by the fibonacci example).

I also found 5 not a trivial question or even 'simple'. (admitted, it's early and I'm on my first coffee, but still). I couldn't immediately see an answer to it other than brute force. Spoj has taught me that brute force is never the answer so I was a bit annoyed that the author claimed they were all ridiculously simple and I didn't see the answer right away...

2

u/ismtrn May 08 '15

The fibonacci one is also silly for another reason: if you know the trick (as in: you have seen the code before and remembered how to do it), you know the answer, so it tests on that you know the answer, rather than that you can solve something with recursion (which is the underlying CS element taught by the fibonacci example).

Are we reading the same question? The "trick" is right there in the question. If you don't know how to generate Fibonacci numbers, you can just read the question:

the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two

Regarding the 5th question, there are 38 = 6561 different possibilities. This can easily be brute forced.

1

u/Otis_Inf May 08 '15

My point was that if you've seen f(n) code and have written the recursive one, it's easy. I admit, not knowing what recursion is is probably going to limit a developer, however it's also not that crucial one should absolutely know about it. I mean, some developers rarely use recursion.

Sure the 5th one has a limited scope, but if brute force is the answer, why bother asking a question like that at all? I mean, anyone can brute force themselves out of a question, isn't the point to ask for something better than the absolute last resort: brute force?

2

u/ismtrn May 08 '15

My point was that if you've seen f(n) code and have written the recursive one, it's easy. I admit, not knowing what recursion is is probably going to limit a developer, however it's also not that crucial one should absolutely know about it. I mean, some developers rarely use recursion.

You don't have to use recursion. I would say that if you can't write a function which generates a list where each element is the sum of the previous two elements(with recursion or otherwise), then you are not very good at programming.

Sure the 5th one has a limited scope, but if brute force is the answer, why bother asking a question like that at all? I mean, anyone can brute force themselves out of a question, isn't the point to ask for something better than the absolute last resort: brute force?

Generating all the possibilities is not at all trivial compared to the other problems in my opinion. How do you represent the list of operations you have to perform on the numbers? How do you generate all combinations? How do you test the combinations?

In general being able to generate all possible combinations of something is usefull, and often the basis on which you build more clever algorithms.

→ More replies (2)