5 ms·
OK am I the only one who thinks this question is on the same lines as hose brainteasers from Google and Microsoft like why are manholes covers round, or how man
by yashg 13y ago
OK am I the only one who thinks this question is on the same lines as hose brainteasers from Google and Microsoft like why are manholes covers round, or how many crows are there in Manhattan?
Honestly, can anyone tell me exactly in what kind of a programming scenario do you have to write a function where f(f(n)) comes out to -n? This is more a math question than a programming one and unless you are expected to do a lot of complex math in your job I don't think such a question is appropriate for a programmer's interview.
- narsil 13y agoDefinitely a brainteaser if a valid solution is a hacky one like at http://stackoverflow.com/a/732049/827437 http://stackoverflow.com/a/732049/827437 : def f(x): if isinstance(x,int): return (lambda: -x) else: return x()
- viraptor 13y agoIs it a hacky solution? Where's the line between a hacky one and a normal one?
- agravier 13y agoI think that the leakage of abstraction is mathematically impure, in his view.
- bsaul 13y agowell, n is supposed to be a 32 bits integer int. Not a lambda. if f(n) returns a lambda, it can't be composed with f again, according to the strict definition of "n".
- viraptor 13y agoAnd it is. The question is: f(f(n)) == -n Where n is a 32 bit signed integer It's `f(n)` that is not a signed integer. Both `n` and `f(f(n))` are ints, so the answer is within the constraints. There's nothing said about the signature of the function.
- bsaul 13y agothat seems a bit far fetched. the way i understand n, it means " f input ", as "the parameter that f takes as input, whose type is an integer". Anyway, that's probably just one way of reading the question. Really depends on what the interviewer's intention was.
- petercooper 13y agoTherein lies a lesson for the interviewer, "your spec is too vague" :-)
- est 13y agoIt's useful for rotation on an imaginary plane. In Python: >>> f=lambda x:x*1j >>> f(1) 1j >>> f(f(1)) (-1+0j) >>> f(f(1)) == -1 True >>>
- shin_lao 13y agoI would probably walk away from an interview (if I ever have to do one again) with such questions. I would not be interested to work in an environment using that kind of filter to let people in.
- aaron695 13y agoAnd I'd guess the work place wins by far out of that deal. A professional person knows for starters the interview is not necessarily the job, especial the kinda person who bases it on one question is not something you'd want to touch with a 10 foot pole. In many companies HR will be doing the interview, or even one level of it. You have no idea what the team might be like. Even all that said it's a fun question that I'd like to try, it say a lot about people who won't attempt something fun and unusual.
- shin_lao 13y agoTo me, it says more about the company, and I wouldn't like to work in that kind of company. Basically these questions are made to make the interviewer look clever while not assessing any relevant skill. I've been far more often an interviewer than and interviewee and I never ask that kind of question.
- aaron695 13y agoBut what do you ask? You can't do fuzzbuzz for an hour. I'm sure I can show you a study that shows some of your questions are wrong. It's one question, at the end of the day every question can probably in isolation be said to be wrong. While they are answering a question like this you see many things, how the handle stress, how they handle something they don't know, how they communicate the solution or ask questions. We all know this question is not meant to be solved right? That bit's not rocket science. It's about how people tackle hard/impossible stuff they don't know. If you answer a question you don't know the solution to by walking out of the room, that to me is a fail and a good test. If they try and get defensive that to me means they are not good team players and won't ever ask for help. How else does one see if they are a team play in an interview? It's easy to bag the questions but people aren't really coming up with supposed solutions.
- viraptor 13y agoI don't think this is a brainteaser. This question actually checks some real skills - can you deal with tricky number processing either at bit or math level, do you know that there are more negative than positive number representations in 2-complement. I agree this may not be the greatest question and some people would fail to find asolution for reasons unrelated to their usual programming skills, but if that's not the only question... I don't see a big issue here.