|
FamDav posted:There is no known linear time algorithm for Fibonacci that doesn't assume a machine that we cannot build. There are no non-constant time terminating algorithms that don't assume a machine that we cannot build.
|
# ¿ Apr 16, 2016 23:06 |
|
|
# ¿ May 10, 2024 02:48 |
|
Centripetal Horse posted:Wouldn't this do the job? Aside from not working for negative values, yeah, this works. If I were giving this as an interview question, it'd be as the first stage of a multistep problem, though. How would you make this faster?
|
# ¿ Jun 19, 2016 12:13 |
|
hobbesmaster posted:You can use it anywhere technically, https://isocpp.org/wiki/faq/freestore-mgmt#delete-this It's illegal in a constructor for a type with non-trivial destructor, and in destructors always: 3.8.1 posted:The lifetime of an object of type T begins when: 3.8.5 posted:Before the lifetime of an object has started but after the storage which the object will occupy has been 12.4.15 posted:Once a destructor is invoked for an object, the object no longer exists; the behavior is undefined if the
|
# ¿ Aug 23, 2016 18:37 |
|
hobbesmaster posted:Then thats #define class struct code:
|
# ¿ Aug 23, 2016 18:56 |
|
hobbesmaster posted:Unions are also classes if we're talking about C++ trivia. More fun trivia: typedef is a storage class.
|
# ¿ Aug 23, 2016 21:01 |
|
|
# ¿ May 10, 2024 02:48 |
|
Hammerite posted:I think if a valid answer to a question is "I don't know, why the hell would you do that in the first place" (as in the case of the "#define class struct" thing) then it is not a suitable interview question. I mean, if it's never going to come up with a sane team writing sane code then why do you care whether the candidate can work out on the spot what would happen? I think the examples of questions you gave in your post are solid, with the possible exception of the faulty machines one. You should never do #define class struct, but you should be able to reason about what it would do, because you know the difference between a class and a struct.
|
# ¿ Aug 24, 2016 00:53 |