Decent examples. I'd like to toss another in that, years ago, a colleague gave a candidate. He thought of the question that morning in the shower.
Morse Code. All letters are combinations of one or more dashes and/or dots. Here is a sentence of Morse Code where the spaces are stripped. Decode it to get the original ASCII sentence.
He gave it and failed the candidate. Sounding like an interesting problem, some of us in the office tried it. Turns out that it is a very hard problem. You have to make a tree of possibilities and it is easy to accidentally make your solution O(n!).
Moral of the story is never give out a coding question that have not personally solved. Second moral: be open to out of the box solutions.
I think that these kinds of interview quizzes are a generally terrible practice. I prefer to bring people in and have them pair with people on real things, that are really happening, that are entirely representative of the real work and the real team dynamics. All parties involved get a much, much better SNR out of arrangements like that. A bunch of contrived nonsense representative of nothing used as a measuring stick for hiring has always seemed nonsensical to me.
In any case, if one were resolute to pursue a practice like this, such as your colleague, then what they should have done is pick a problem they definitely don't know the answer to and then sit down and work it out actively in cooperation with the candidate. That would have been about a thousand times more useful as an interviewing activity.
Knowing the answer ahead of time makes the dynamic worse. Things will seem obvious that aren't when you already know the answer. It sounds like your colleague made things a degree worse by both not knowing the answer, but assuming that they did somehow intuitively.
> I prefer to bring people in and have them pair with people on real things, that are really happening, that are entirely representative of the real work and the real team dynamics.
That should be the most important test, but most of the daily realistic work is really a matter of practice. By testing it you really test how much practice with that particular toolchain and workflow the person had, not how smart or good programmer they are. Brainteasers are unrealistic and relying just on them is stupid, but they give you some insight in how good in quick thinking someone really is. If I was looking for a newbie to train, I'd always prefer someone who can't finish the real world test, but knows how to think technically, to the opposite.
Even if they don't know the tools or languages, which in our case they're almost certainly not going to (Rust, Agda, TLA+, etc.), you get to see how they interact with a situation where they need to be able to direct some of their own learning by seeing if they ask questions, if they can synthesize insights despite lack of deep familiarity, how they react to having naivety exposed, etc.
Most of the challenging work is collaborative problem solving, not exam proctoring, and it's important to see how a person interacts with that. You'll see how much direction they're likely to need, if they can navigate and contribute positively to team dynamics, and so on.
We don't work on cryptocurrencies. Right now we work on automated testing & verification tools for "cyber-physical systems". Our target markets & customers often have safety-critical considerations.
We use Agda to create proofs for some of the components of our platform.
protip from someone in the trenches: until you have given the problem to many people in interviews and evaluated their responses to calibrate your judgement, problems like these serve only one purpose in an interview that is satisfying interviewers ego about how smart he is.
I've proposed (and been rejected) where I work that we have both high and underperformers go through mock interviews for their roles, to see if our interview questions could distinguish who was who.
I understand that this is going to be awkward, especially for the low performers, but at the moment I don't think our interview practices are based on anything. We ask questions and then later have a conversation about how and whether or not our questions revealed the presence of the attributes we were supposed to be assessing for and it feels very made up and make believe. Plus, people could be given incentives for going through the process and bonuses for passing the mock interviews to encourage them to try
If we could get people where we already knew how good or bad they were to rerun the interview process then we could start to figure out which questions and which evaluation methods were useful in separating good candidates from poor ones.
just make everyone in the company do it IMO, and let the managers distinguish who was an over/underperformer later on
Of course, you'll just find out that there's practically no correlation.. Some of the least useful teammates I ever had ended up at Google, and one of the best programmers I've ever met makes $10/hour at a fucking call center out in the middle of nowhere
It's not good enough to test only the people who have already passed a similar test. It's easy to get a nonsense negative correlation, like more experienced people performing worse in their job, because the people with less experience that nonetheless got hired must have had some other factor that made up for it. That can result in a negative correlation in the already-hired pool even if there's a positive correlation in the potential-hire pool.
This is the same problem you see with people claiming that GPA or GRE scores have no or negative correlation with academic success.
I've come up with a few interview questions, and reviewed a few more. In my experience there's a ~decent rule of thumb for gauging difficulty and time required to solve a given problem.
A person in your company, after having read the problem and glancing at the rough description figures out a clean solution in time X. That's without the interview stress, knowledge of the problem domain, with the pacing of the problem laid out in writing. A well-performing candidate coming in cold, stressed from the interview setup and under time pressure will take 3X time to solve it.
So if it takes much more than 10 minutes for someone at your company solve your proposed interview question reasonably well, it's almost certainly too difficult.
I wrote a solution to this some time back: https://github.com/paulhankin/morse-decoder . It finds the most likely sentence based on n-gram frequencies and a dictionary, and runs a relatively fast dynamic program (it's been a while since I looked at the code, but I think linear if word lengths are bounded). Word list and n-gram frequencies aren't provided in the repo, although they're easy to find online.
This one's easy. Insert spaces between every blip and you've got a sequence of E and T. This should demonstrate to the proctor that the problem is ill-posed. Now the proctor is under examination: if they admit that the problem is garbage, they pass and you should stick out the interview. Otherwise, just walk away.
A sibling comment discussed most probable message; on further reflection, I suspect there's a dynamic programming algorithm for the shortest possible message... this problem could have some nifty angles to explore if done right. But only if you know that you're testing on how people work in the face of ambiguity!
O(n!) is wrong. For an string of length n, there are n-1 gaps in it, and each gap could or could not hold a space, which gives you 2^(n-1) possibilities. The algorithm is at worst basically O(n*2^n). Exponential for sure, but not factorial.
As for solving it, back-tracking recursive descent does the job, though obviously there's not always a single correct answer.
This is not really a "trick question", this is just a regular programming challenge :)
On the surface it feels relatively easy. Until you realize you can't tell one letter from another.
Is it "D" or is it "T" followed by the start of the next letter? "D" is equal to "TEE". But it could be "NE" also. One letter in and we are exploding. This is not counting nonsensical combinations like this being the start of "NL", but if that is a word boundary, then maybe it is ok.
Yeah, ok, though I'm not sure what that will prove. As I said, it's really just a case of writing a backtracking recursive thing. Here it is in prolog:
Prolog is obviously excellent for this kind of thing since the backtracking comes built in, but it's not massively more complicated in other languages.
For "_.._", it gives you the following answers (I added some line-breaks):
?- string_to_list("_.._", L),
findall(English, morse(L, English), Answers).
L = [95, 46, 46, 95],
Answers = [[d, t],
[n, a],
[n, e, t],
[t, e, a],
[t, e, e, t],
[t, i, t],
[t, u],
[x]].
I wasn't saying that it's not a good little problem. It's a lovely little problem, which you solve with recursive back-tracking! I wouldn't say it's a "trick question" though, it's just a regular programming challenge.
EDIT: Oh, I see what you're saying, do you mean "It's a trick question because there isn't necessarily just one answer"?
If so, then I misunderstood, I figured the challenge was "find all valid interpretations" of a certain morse code string. The fact that there could be more than one seemed fairly obvious to me.
My gut feeling is that you can solve this with dynamic programming faster than this.
There will be lots of ways to split any given prefix into letters. But all of them leave the same suffix. You don't need to repeat the analysis of the suffix.
You could avoid repeating the analysis by memoising the result. But when you're memoising results from leaves of a search tree, that's a hint that you're close to a dynamic programming approach.
It depends a little bit on what the acceptable answer is. If it's "stream/generate a list of possible strings", then the length of that list is probably O(2^n), so the fact that my recursive descent thing is exponential doesn't actually matter that much asymptotically. If you memoized it, the memo structure caching the suffixes would become massive and you'd spend just almost as much time looping the results from it as you would just walking down the tree, so you might as well save yourself the memory and just walk down the tree. Like, the length of the cached answer is more or less the same as the runtime of just doing the recursion, so you're not actually saving much of anything by memoization, and you're wasting a whole lot of memory.
I guess you could instead return some kind of fancy "prefix DAG" containing all possible strings, and that would be faster. But then you're just making the caller walk that tree instead of you doing it yourself, so you're really just shuffling the runtime around, not really saving much.
However, if the answer is "count the solutions", then yeah, memoizing would speed it up MASSIVELY. That's a good little Project Euler style problem, actually (though not a terribly tricky one), because you could make the input large enough that naive recursive descent wouldn't work. I haven't quite thought through what going full-on DP and turning the recursion upside down would do, but I assume it would work just fine.
But given that the number of possible solutions is a massive O(2^n) (probably, anyway), that puts a floor on the runtime you can't algorithm your way out of. Might as well go with the cheap recursive descent. I think, anyway :)
Too late. It's an interesting problem, he'll have talked about it with his colleagues and they'll have come to the same conclusions, it's a tough nut. They will conclude correctly that the company is full of arrogant assholes that have no idea what they are talking about.
Exactly, an apology!
It almost sounds like the goal was to find something that a candidate doesn't know. How about finding the things the candidate knows and basing the further discussion on top of that.
All this obsession with coding tricks in the interviews is just awful.
A lot of the dev interview process relies on luck. Sometimes you just get a crappy interviewer (inexperienced, naive, or just malicious), and things won’t go well regardless of your own abilities.
In fact, beyond a certain level of competence, interview results are mostly about luck. Sometimes you get a nice set of interviews, sometimes you don’t. Some companies will at least not reject you out of hand for one bad interview slot, but most companies are just so overwhelmed with unreliable signal that they’ll tank you for any kind of hint at incompetence.
I’ve been given offers from Google, been rejected by random web shops, and everything in between, all within the same year.
The Dunning-Kruger effect is put on steroids during tech interviews.
There’s this pretense that the interviewer is smarter than the interviewee, and an expectation that the interviewee will abide by that pretense as a show of respect.
That pretense leads interviewers to being unnecessarily ambiguous, and especially leads them to asking overly complicated questions. If you’re an insecure engineer, this allows you to impress your coworkers in the meeting afterward with your complicated question. You can act as if it would have been easy for you, the other engineers in the room won’t disagree because they want people to think they’re smart too, and one thing will be made very clear to everyone: You are smarter than the candidate, and the company is very lucky to have you.
It also leads interviewees to fake equivocating and feigning ignorance, and is overall a strong recipe for unconscious or deliberate bias based on the personal and professional insecurities of both parties.
From the other side of the table, when you’re the one interviewing candidates, you spend an absolute minimum of 90% of your time screening and interviewing people who are so bad that it literally hurts on an emotional level to interact with them. You develop compassion fatigue, like a nurse in an ER, and it’s very easy to find yourself in a place where you assume the worst of every candidate and don’t even care anymore if they fail.
The results of these interviews are influenced far more heavily by the interviewers than by the person being interviewed, in my opinion. And most companies (nearly all in fact) have literally no mechanism by which they grade the quality or subjectivity of their interviewers.
This sounds about right. At some level, LeetCode can filter out the completely inept bottom fairly quickly, but then it becomes really useless, it is really not much better than fizbuzz in that regard.
I know its not the point but think the right answer is to ask questions to better understand the use case. what language is being used?, what is the nature of the message?, who is sending it? Is there a format? do we have a log of manually decoded messages?
I could see not hiring someone if they didnt try to ask stuff like that.
As a way to weed out people who just fill requirements without questioning if the requirement actually solves the problem.
While a global solution is NP complete since Morse code is not prefix free, there's probably a decent heuristic approach that maximizes matching of existing english words.
If, in addition to the Morse Code associations with letters, you have a dictionary of permitted words, this becomes a fairly straightforward DP, does it not?
I think this is a great problem to give someone, but the output you measure is the approach they take to it - are they methodical, logical, insightful, etc - not whether they solve it. Evaluating someone on the latter is indeed deeply incompetent.
After which the CEO personally and profusely apologized to the candidate. And offered a hefty per-diem consulting fee in compensation for this cynical (if not outright juvenile) waste of their precious, irreplaceable time.
I don't see why the CEO needs to be involved. Why not have the recruiter apologize to the candidate and offer another interview?
Candidates know that there is always a chance they will be rejected for reasons outside their control (e.g. there was only 1 opening and a better candidate applied), so if the candidate agreed to the interview without a consulting fee, I don't think it's necessary to give one.
In my view the CEO is for major business decisions and company direction. I don't see a single interview with a too-hard question being that. Any large company will be conducting hundreds of interviews with too-hard questions every day. I've seen many blog posts about them on HN.
I see it as mostly ignorance on the part of a single interviewer. Every large company has lots of ignorance. People aren't perfect.
The arrogance here seems to be from misjudging the difficulty of the question. That is, it seems largely rooted in ignorance.
As for reckless, there's a wide variety of how much time people will spend preparing a question before an interview. Some people will spend days preparing a question. Others will just pick something off a list and ask it. I don't think everyone would agree that just thinking of a question is reckless. We also don't know how much time sethammons's coworker was given to prepare. Maybe he was told about the interview Monday evening, and had to conduct it Tuesday morning.
The arrogance here seems to be from misjudging the difficulty of the question.
I see it as coming from a mindset that says it's OK to pull some "nifty" problem out of his head at the last minute -- in this case, literally between lathering his toe jam and rinsing his buttcrack -- and feed it to candidates without having it properly vetted first.
Or even, for that matter, sitting down and thinking about it for a couple of seconds. To me at least -- right off the bat, the core assumption they made about this problem was highly suspect, just from the fundamentals.
In short - they didn't just make a mistake; they were throwing caution to the wind. On the basis of an apparent view that candidates are a dime a bushel, and their time is more or less infinitely expendable.
That is - the mindset that so many companies following the current penchant for on-the-spot technical interviewing seem deeply beholden to.
Surely "decoding" means returning the text that was encoded. You can't trivially decode it, you can provide a candidate solution, that's entirely different; the point of sharing this was it's not possible to decode because there's no unique solution.
...---...
you can guess it's EEETTTEEE, but the decoding is SOS, that was the plaintext I started with.
SOS is an interesting case, because it is a Morse "prosign", which means it is sent as one continuous stream of dits and dahs without any pauses between the letters we use to represent it.
In other words, SOS is sent exactly the way you wrote it, as if it were one long character:
...---...
It is not sent as three separate letters like this:
... --- ...
To indicate this special treatment, prosigns are normally typeset with a bar over the connected letters, something like this:
___
SOS
(I used underscores above the letters here; if they render as separate underscores, imagine that they all run together.)
Yes, and even a simple string like "...---..." has 200 possible solutions, including "VTTIE", "3NI", and "SMB". Especially for longer inputs, there's no way to guess which one is right.
I think “problem solving” questions are pretty much useless. Engineers need to solve problems, but they don’t have to do it in under an hour and under stress. Plus, solving tricky problems is not something you do everyday, or maybe even every week.
What I care about when I do interviews is how they organize their code. I want to see what people’s instincts and habits are, because that’s what’s going to determine the quality of 99% of the code they write.
I’d rather have someone who can come up with objectively good abstractions instead of writing one giant, unintelligible block of code than someone who can come up with something very clever on the spot to a totally esoteric problem.
Will not reverse languages that are right-to-left by default, such as Arabic or Hebrew.
Will not reverse composed ligatures, e.g. ﷺ is synonymous to صَلَّىٰ ٱللَّٰهُ عَلَيْهِ وَسَلَّمَ, but صَلَّىٰ ٱللَّٰهُ عَلَيْهِ وَسَلَّمَ with a LTR directional override is صَلَّىٰ ٱللَّٰهُ عَلَيْهِ وَسَلَّمَ while ﷺ remains as ﷺ.
Hangul is phonetic, but with letters arranged into syllabic symbols. In Spanish there's a gibberish construction where you reverse syllables ("al vesre", meaning, "al revés", which means "backwards"). Reversing text makes little sense except as an interview trick question, I guess, but if you must make sense of it, then reversing syllables makes more sense than going further.
BTW, you can reverse Unicode (in any UTF), so long as you don't really care about the semantics of the result -- if all you want to do is reverse the codepoints, you could. After all, it is an interesting programming interview trick question, though admittedly then "you can't really" answer is more fun because you get to talk about glyphs and ligatures and so on, and natural language, thus demonstrating your mastery to the person who was trying to trick you.
Yes, while 겁 is made out of ㄱ ㅓ ㅂ, native Korean speakers would expect a string reversing function to operate on precomposed syllable codepoints rather than breaking them into the components.
I do agree with the overall point; just thought this specific example was a bit odd.
Your point is well-taken with Hangul, but what about, say, English?
Does the string-reversing function receive "English" and output "hsilgnE" or "lishEng"? What if the string matches no known words (e.g. alphanumeric passphrase)? What if the string represents a single syllable (e.g. "was")?
Thinking of strings as connected to vocalized syllables only makes sense with strings meant to represent syllables, sure, but even that can lead to counterintuitive results.
I know you weren't defending the idea of a string-reversing function, but your objection is not exactly grounded in principle, either. That is, when you ask
> Why would reversing 겁 into 벅 make sense?
one could easily say, why wouldn't that literal reversal of the phoneme make sense? I understand it doesn't, but that's the problem with Unicode reversing-functions.
Just so I understand, the original question has no answer because there is not a 1-1 correspondence between code points and glyphs? If there were, it would be trivial to solve.
But instead Unicode has formatting and control code points and that complicates everything?
Really, the problem is the question itself. A more specific requirement such as "make all the glyphs appear in reverse order" makes it a much easier problem (still tricky and full of edge cases, but conceptually simple).
"Reverse" is just too ambiguous when dealing with Unicode.
Makes me wonder if we should not have tried to make a single "unicode" and instead had distinct types for each language like EnglishString ArabicString etc. and programmers can handle each case as needed.
No. If that's how it worked, how many programs would have Arabic support at all? Everyone would use EnglishString for everything (because that was the example code they copied from StackOverflow) and the whole thing comes crashing down if I enter even just an umlaut.
No, I was thinking of something a little more sophisticated than that. Classes of strings would be sub-classed from others like English would have multiple sub-classes like American, British etc. Each class could have it's own parameters like whether it supports being reversed. You would not necessarily implement just for English. If you were making a palindrome finding app for example, you would only care if the class passed in supports reversing for example. Eventually you could have a language DB library, not so different that the time zone database that can be periodically updated with new rules.
That’s a lot of types, regardless of how you define them.
Is AAVE a separate “language” from “standard English”? How about Creole? Is that French, English, or a distinct language?
Is Pennsylvania Dutch/“Low German” German or English?
What about Yiddish? Modern Yiddish is an entirely different beast from historical Yiddish.
Who is going to be defining the type for Greek? What region and point in history will they be using for a reference?
Does GermanString contain Eszett? If so, is it a separate code point or interchangeable with “ss”? Is there logic that defines when “ss” should be represented as an Eszett and when it should be rendered as “ss”?
No, I think Unicode is the right approach. You get all the code points you might need and logic for processing them as glyphs. Leave everything else up to the application.
It's a fancy calligraphy version of "Peace Be Upon Him" used specifically when referring to the prophet Muhammad. There are a handful similar phrases, mostly religious in nature. The most notable one would be ﷽ "In the name of Allah the merciful and compassionate" AKA the widest single codepoint in all of Unicode.
Since these are ligatures (though really complex ones) most software consider these as one "character" (try selecting part of the ligature; you can't).
#1 got me and I had a good laugh. I wonder if there's a faster method for #2 using AVX and bit tiddling, or if the optimizer is smart enough to find the most efficient code for a particular architecture.
Hmm, I can't think of a way to use the mathematical structure of those numbers to speed up checking.
However, the reason I said AVX is because it can be used for checking equality of 5 (well, 8) numbers simultaneously. This solution requires AVX2 and is probably faster than the optimized reference code.
// Copy x to all 8 elements.
__m256i a = _mm256_set1_epi32(x);
// Duplicate 6 because we need to fill all 8 elements.
__m256i b = _mm256_set_epi32(6, 28, 496, 8128, 33550336, 6, 6, 6);
// Check for element-wise equality.
__m256i c = _mm256_cmpeq_epi32(a, b);
// Check if any bytes are nonzero.
return _mm256_movemask_epi8(c) != 0;
I have a hunch that the actually fastest version is to change all those "||" to "|" in the original version. Short-circuiting and adding branches probably just slows the whole thing down compared to just running the comparisons, which will probably pipeline really well.
Interestingly the compiler doesn't do this optimization, even though it could. So maybe I'm wrong. No real way to know without benchmarking, though.
Seems to be faster, did a crappy shell benchmark. It takes 5.7 seconds to run that SIMD function INT_MAX times, compared to 6.6 seconds for the original. MacBook Air, late 2014, clang, -O3 -mavx2
One things that comes to mind: popcnt(x^(x>>1))==2 for all 5 numbers. Maybe the checking function could start with that condition, then fall back to the slower one-by-one check when that evaluates to two. For most numbers the popcnt check would fail.
edit: Not to mention that all 5 numbers are even, so a parity check could also help for odd number inputs (but it makes it slower for even numbers). I do not think that AVX has anything to offer here though.
Assuming arguments will be uniformly picked an extra check would speed things up on many architectures:
return (x & 0xFE0000001 == 0) &&
(x == 6 || x == 28 || x == 496 || x == 8128 || x == 33550336):
The original code does about 5 comparisons in each call. The improvement always does a binary ‘and’ and 1 comparison, and only does the original 5 in 1/256 of the calls.
Got me to laugh too! I thought I was clever with my O(n) solution. Let A be the original array and let B be the sorted array. Just loop through A and assign B[A[i]] = A[i].
I like these a lot! I'm seeing them less as "interview questions", which they'd be terrible as, but as "annoy your friends questions" after you've all had a couple drinks.
One I heard a while back: "You have a list consisting of every college student in the US. What's the fastest way to sort them by age in years?"
Almost all of the students are going to be somewhere between 17 and 23 years old, so you first do one pass as a bucket sort for each of those seven values. Then sort the remaining students however you want. While it's technically still O(n log n), almost everyone is sorted in that first pass, so it's practically indistinguishable from O(n).
That is actually a decent optimization. If you know the final cardinality, you just create that many buckets, and drop records in it. Not unlike how histograms work.
Are other professionals subjected to the same scepticism during interviews?
Are lawyers given tough questions and expected to come up with a clever response on the spot? Doctors given a list of symptoms? Teachers given a difficult student and told to teach them some concept from physics?
Serious question (albeit a bit facetious in my examples).
Lawyers, doctors, and teachers are all positions that have some form of certification. Potential employers can be guaranteed that all potential employees meet the basic knowledge and skills requirements.
Nothing of the sort exists in the programming field. That, coupled with the high salaries, means fraud is a real problem when trying to hire programmers.
I'm of the opinion that the only valid type of coding question in an interview is one that tests the candidate's ability to perform the actual type of work they are being hired to do.
If you were trying to hire a mechanic, would you first give them a sudoku puzzle to measure his "cleverness" (and then use that as a predictor of their car repair abilities)?
Aren’t these really just the same thing as the brain teasers that have already been disavowed by most companies? Anyways, even many Leetcode questions involve “tricks” that we just have to deal with.
why not? they are trivial. not “trick” in the sense of poor questions which are easy enough once you’ve studied the problem for 20 years and know some trivia that is rare knowledge, but are otherwise insanely difficult.
i think these are good. TELL the candidate they are trick questions. again, they are trivial. i was actually disappointed.
Better questions are those that more closely simulate a work sample, being aware that an interview is high stress and time boxed and thus not actually like work. I like an hour or more pair programming in a language the candidate is comfortable with on a simplified problem with some relevance to work.
For more senior candidates, you definitely wouldn't want to waste everyone's time with brain teasers because if the high risk of a hasty rejection - a deeper probing into systems they've built and and designed in the past, with an angle on relevant problems for the business, along with the pair programming.
Q: Given V (the number of vertices), E (the number of edges) and L (a list of the edges) for a connected undirected graph, determine whether the graph is a tree.
----
A: It can be done in O(1) by:
return V == E + 1
The number of vertices in a tree is always one more than the number of edges. We also know that the graph is connected, so it has to be a tree.
This is what I can't understand about hiring interviews, and I thank 1/2 of my interviews haven't involved such trickery. Sure - it's "easy" to say "Oh you've solved this great puzzle, you'd be perfect since you are smart on your feet", but you can be great at writing UI's, but struggle on the backend.
This culture needs to end. I don't spend my time at work solving puzzles, I spend time at work meeting with stakeholders, organizing meetings, discussing options and timelines. I spend my time coding and iterating, not wasting my time at puzzles.
I hate puzzles, because I like to do work that actually produces results (and isn't a measure of how smart one might be). Puzzles are a waste of time in my opinion, a much better proof of pudding would be a programming portfolio of things you've written (ie. Github).
Interview questions should be trivial examples so you can see if the candidate know what programming is or how to program on the language, not what libraries he/she knows. Ideally nothing that depends on any particular OS std libraries as well. Of course this does not apply if you are hiring someone for a position where knowledge on a particular library is a requirement, but in my experience that is usually not the case for either junior nor senior positions, maybe only for in-between.
If you need anything more advanced you should do an assignment to allow time for proper design and reasoning, otherwise you'll never be able to fully evaluate what the candidate really can do and how he/she approaches problems.
I've tried trick programming questions when I started interviewing coders, the SNR was simply awful and it was frustrating for me and the candidates.
Any evaluation system have to be calibrated on a large enough pool of candidates, when you're building a company and start interviewing you don't really have the luxury of wasting the first dozens applications.
Today I tend to completely avoid programming questions, except to reject complete newbies.
Since I work from home, I haven't had to do interviews in a long time, but back when I did, I did always ask one programming question, but it would be only one step harder than trivial.
I'd say use whatever language you want, even make one up, so long as you can explain parts where I might have questions. I didn't care about syntax, or performance, or cleverness -- just does it work. If they can't do that, you don't want them for a coding position.
Regarding reversing Unicode strings: This is simple, just render the string in a purposefully crafted mono-space font using distinct, non-overlapping bit patterns for glyphs (this will be a rather huge font, we may suggest a 0xFFFF x 0xFFFF matrix for glyphs to be on the safe side), slice the resulting bitmap image, detect and recompose. ;-)
I know next to nothing about unicode. If I took the bits and arranged them in reverse order would I be asked to leave the building? It didn't state the output should also be unicode.
While I know it is common practice to dismiss problem solving questions, a good problem solution can be the difference between intractable NP complete or worse, and a solution that is O(lg N). Additionally, a good solution is elegant and easily maintainable, while a bad solution is bloated and has large code debt.
I dunno, these aren't very interesting to me. Question one is good.
Question two relies on the answerer knowing specific details about the distribution of perfect numbers, which isn't a "trick" in any meaningful sense. Either you know it or you don't. Contrast with "Are the arguments to memcmp() declared const in ISO C99?". Is that a "trick" question?
And question three is just senseless pedantry. It says that unicode symbols don't make "real" strings if you reverse their orders. Which is true, but not really what the question was asking. ASCII strings aren't "real" if you reverse their order either, because "real" is a human distinction that doesn't live at the data layer. It is certainly true that a reversed unicode string containing ligatures and combining characters is a VALID string per the unicode standard, which seems to meet the phrasing of the question as asked.
Experience. You "should" have been able to get the first one, I think the other two are pretty debatable as they require knowledge you might have to research first if you didn't already know about perfect numbers or at least some of the complexities of unicode.
As far as the first one goes, you could go through some of the questions on https://codesignal.com/ . They're geared towards interview practice, but ignoring that they provide reasonable problems, a decent environment to write code in and after you get your solution accepted you'll be able to access other solutions to get new ideas. The aim here is just to learn how to think through a problem and allow your brain start to make connections that it wasn't making before.
For the perfect number question, you can always just argue that precomputing a 512 MiB bit array that has 1 in position n if n is a perfect number, then indexing into that bit array is O(1). Because the range is constrained, you don't need to know anything about perfect numbers to come up with this.
Realistically, this is for fun and games. Nobody should actually be asking you trick questions in a real scenario. It's okay not to be able to catch the trick.
For #1, it really depends on what you mean by "array" and what you need to use it for. Sounds like an XY problem.
If you take it to mean a more abstract concept of a list of things that can be iterated and accessed by index, then the fastest implementation is O(1): build no data structure at all - just implement the iterator and index functions.
If you take it to mean physically manipulating atoms on a chip to be in a certain state, then you'll actually have to do something :)
The array is length N, and it says it contains the integers 1 through N inclusive, as in, all of them. If there were any repeats, then you'd have an array of length greater than N.
Seems like somewhat ambiguous semantic garbage to me. Especially when there is a much clearer three letter word to use (all) that would actually communicate the the point of the question.
They’re trick questions, so I think it’s fair to be pedantic. It’s asking for fastest method not the one with least complexity. I would argue the fastest method would be to pick a random location in memory and get lucky.
I like that its impossible to do "string reversal" until "string" and "reversal" are defined. Oh you want me to sort an array... how do you define "sort" and "array".
Concerning Unicode reversal, the author's statements "This has not been done", "there is no genuine real-world need", "The algorithm doesn't exist" are wrong (see UAX #29 §6.4), "suitable metadata might need to be added" has already been done, and "what a 'string' is considered to be" is well-defined and requires no deliberation or reinterpretation. His text is surprising to me because I know the author programs in Perl, JS, Python, so he should really be knowledgeable about this topic. With the following code samples, all the edge cases written about in the article are taken care of.
Rust deserve special mention because the language implementers did the correct thing and put it in the language: https://doc.rust-lang.org/1.3.0/std/str/struct.Graphemes.htm... … only to take it out again for no good reason, thus rendering the programming language not Unicode compliant in the process. Talk about snatching defeat from the jaws of victory! m-(
Other languages: try to find a binding for libpcre or libicu.
Here's a similar one: What's the best possible time complexity of a program that plays perfect chess, assuming we could write such a program?
Answer: O(1), since it could be written as one big lookup table from game state to optimal move. To get a nontrivial complexity class, you have to have some parameter that can vary, so e.g. the question "what's the time complexity of a program that plays perfect chess on an n-by-n board?" (assuming a suitable generalization of the chess rules is given) is much harder to answer.
I think that works only if n-by-n can vary to infinity. Otherwise I'll just have a lut for every possible board size.
By the same method, you can sort any finite sequence in O(1).. but then you don't really sort infinite sequences, do you? So I'm not sure this is a good trick question.
Morse Code. All letters are combinations of one or more dashes and/or dots. Here is a sentence of Morse Code where the spaces are stripped. Decode it to get the original ASCII sentence.
He gave it and failed the candidate. Sounding like an interesting problem, some of us in the office tried it. Turns out that it is a very hard problem. You have to make a tree of possibilities and it is easy to accidentally make your solution O(n!).
Moral of the story is never give out a coding question that have not personally solved. Second moral: be open to out of the box solutions.