3 ms·
I remember just after college I applied for a .net job, when I came in for the interview they gave me a paper exam with a bunch of questions on how to do silly
by everyone 5y ago
I remember just after college I applied for a .net job, when I came in for the interview they gave me a paper exam with a bunch of questions on how to do silly little tricks including that one specifically. I didn't take that job.
- code_runner 5y agoI tried to explain to a previous employer how much their little "brainteaser" test was turn off to legitimately talented engineers. I explained that everybody in town knows about the test and basically refuses to even entertain the company because of it. Bear in mind this is a place building relatively simple web apps... standard line of business stuff. The test was questions like "how many words can you unscramble from these letters" etc. A majority of the engineers felt the test meant you "knew you were working with smart people". A majority of the code was unmaintainable sludge. (though a few people were extremely talented) I no longer work there.
- hansvm 5y agoI can't comment on the rest of the interview, but this question in particular wouldn't necessarily be bad for some positions if so many people hadn't memorized a few solutions. A large part of some jobs is applying first-principles reasoning to a set of arbitrary requirements, and predicated on the assumption that a reasonable interviewer thought this was a good question or that they explicitly asked you to do your best to reason through the problem you'd be pretty safe starting with what you know and seeing how far that got you. A sample chain of reasoning might go as follows: - We have to take some first step transforming (X,Y) into (f(X,Y),Y) or (X,f(X,Y)). If one has a solution the other must as well, so assume (X,f(X,Y)). - The function f can't destroy any information since swapping two variables twice ends up where we started. - That immediately requires that f(X,Y) must properly depend on Y or else some information would be destroyed. Moreover, it has to properly depend on X if we're to ever make forward progress in swapping the information content of the two variables. - The problem doesn't specify how big the numbers are, so as a first pass at the problem there should probably exist a solution that works with 1-bit numbers. - There are only 16 two-input functions on bits. Only 2 of them (XOR and XNOR) properly depend on both variables and don't destroy information. - Applying XOR or XNOR a few times you'll easily find a small number of operations that swap two variables. For an alternative formulation you might not bother with or notice the 1-bit simplification. You'll go on to the second operation yielding (g(X,f(X,Y)), f(X,Y)). Again looking for something that makes your life easier you assume g is some kind of partial inverse of f so that you've actually almost completed the swap (i.e., that your partial solution at this point is (Y, f(X,Y))). That suggests some kind of a group-structure and lends itself to the XOR/XNOR we previously discovered, the ADD/SUB people commonly attempt as well (and we live in the real-world, say something to the interviewer about wraparound arithmetic or needing an extra bit if you go that route), and all sorts of other methods. And so on. If you have reason to actually try to _solve_ this problem instead of regurgitating answers you'll find a half-dozen easy methods which should still leave plenty of time for the rest of the interview. Side-note: I recall needing silly tricks like that more in .NET than other platforms. They didn't have an optimized popcount even as recently as the beginning of Covid for God's sake.