Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: What are the best interview questions you've been asked?
52 points by tbanacek on Feb 21, 2017 | hide | past | favorite | 56 comments

A very senior guy comes in the room where I am with a very concentrated look on his face and my resume in his hand. On my resume its mentioned that I have a lot of experience bringing security relevant concepts to inexperienced people.

So he describes a problem hes actually working through when he was "interrupted" to come interview me. He was trying to terminate an SSL connection, modify the stream (for video manipulation) and send it along to the client. I explained public key and how what he wanted to do was called a MitM attack and how he couldn't continue on the stream without the private key of the server. We had a real conversation with me explaining (to a very smart guy) so he could completely understand everything he "needed" to know to solve the problem he was working on.

I got the job. It was the only interview I've had where I really felt they were asking me something relevant to the work and the kind of work I would be required to do. I ended up having to write Symbian OS code, which I had no prior experience in.

TBH most of the comments so far are the interview questions I hate as they have no relevance to anything I care about or will ever be asked to do.

> I got the job. It was the only interview I've had where I really felt they were asking me something relevant to the work and the kind of work I would be required to do.

This is the interview method espoused in Reinventing the Interview:


I was lucky to stumble on this when I was young and it has been very useful in thinking about both being interviewed and interviewing.

Was it for a senior position or a very highly respected company? The companies I've applied to and interviewed with (not all) would ask me questions that were very specifically on my resume (I'm very confident the interviewers didn't even spend 30 seconds looking at the resume).

A very senior dev had to be explained he couldn't do a man-in-the-middle attack on an encrypted stream without the server's private key? With all due respect and I don't know much about security but something seems off, maybe you haven't explained the whole story or maybe I'm getting something wrong.

I think the implication is that the senior dev conducting the interview wasn't really interrupted (hence the quotes around the word) and that it was just how the realistic interview question was presented.

senior means different things in different places. More and more developers are considered "senior" just because of experience building basic web apps, doesn't mean they have a deep understanding of http/s, public/private key cyrpto, etc...

Not a good thing, but thats how it is some places.

This doesn't require a deep knowledge of https or public/private crypto though. It requires a very basic knowledge of how encryption works. Although to be fair, you can go a long way without that knowledge.

For a sys admin, devops, sre or whatever you want to call us this week, I like the following question for senior level people

What has been your biggest screw up to cause a production outage and what did you take from that?

If they say they never caused an outage or give some answer that isn't a screw up, I know one of two things

1) They arent senior level to be put in charge of handling major changes on production

2) They are the type of person that tries to hide screw ups from the rest of the team.

I like this, but I want to follow up by asking what your idea of a "good" answer is, what a "bad" idea is and how you would see through a bullshit answer.

For me a good answer is a story about a human screw up that took down production and then the follow up is talking about steps they took to make sure it never happened again.

The big thing I'm looking for is mistakes are good learning experiences for people and if you make a mistake its time to reflect on the mistake to make sure it never happens again.

So I want to hear how they made sure that mistake or anything like it won't happen again.

Consider two directed acyclic graphs where each node has a hash that depends on its value and its parent's hashes. Suppose you have a slow connection and one of the graphs is remote, how do you figure out as efficiently as possible which nodes both graphs have?

The trick is to sample random nodes from the remote graph. If you get back a node that has the same hash as a node in your graph, you know that local and remote have all the same ancestors of the node too. Otherwise, you know that local doesn't have any of the children (on remote) of that node.

Turns out that is basically what mercurial does [1].

[1] https://www.mercurial-scm.org/repo/hg/file/tip/mercurial/set...

"We're going to build Google Maps using these satellite images. How would you do it?"

This is the sort of open, large architectural question that I love and think really helps to understand a developer's skill set. It's great to be able to start very broad, but focus down into detail like CPU caching and the possible on-disk layout.

Any recommendations on sites where one can read about stuff like this? High Scalability (highscalability.com) is one resource I'm aware of (for people who are familiar with the site - any "must read" posts?). Thanks.

My personal favorite "How much will it take for you to join our team?"

Damn yuppie.

So Yuppie

It is both sad and unsurprising that we bash algo-centric interviews in every other thread (rightly so) and yet so many of the answers here are focused on abstract algorithmic questions. We really do this to ourselves.

Majority of the interview questions for software developers are retarded. It's either too academic (reverse a linked list) or too specific (What is the difference between StringBuffer and StringBuilder in Java?).

To answer your question - none.

Being too specific is only bad unless you have not listed as your experience in the domain.

But being too academic is actually good. The academic questions are constants irrespective of the domain in which the coding is done.

Put it this way - If you ask academic questions to a senior engineer during an interview, you might as well hire a college student. It will cost you less money and the student might even be a better fit, based on your evaluation.

No. That's not the intention. A senior who skill is superset of a college student.

"Here are 4 projects we're currently working on and that you might be involved with if you work here. On a scale from 1-5 how interested would you be to work on them. Briefly explain your reasoning"

Or any variation on "here's a real problem we are actually having. Do you have any ideas about how one might go about solving it?"

and bonus worst question:

"do you have kids/what does your family life look like?"

I'm pretty sure that last question is illegal in the USA

one i really enjoyed solving: given an array of size (n - 1), containing all but one of the numbers between 1 and n, find the missing number in linear time and constant space.

For those curious about the best solution (like myself): http://www.geeksforgeeks.org/find-the-missing-number/

"All the integers between 1 and n should add up to (n(n+1) / 2) so just iterate over the array keeping a running sum, then at the end subtract from (n(n+1) / 2) to see the integer you are missing. It's constant space and requires just a single sum you track.

But hey you know what, actually, fuck these requirements, they're pretty bad.

This is a stupid and wrong solution and the actual correct way to do it (which is guaranteed to work) is to sort the list in-place (or into a copy, if you need the original), then iterate through from the beginning, making sure it starts with one, that every value is in there, and that it is missing one and only one number. On the second missing number or if after sorting it does not start with 1, or if any value is not an integer, or if any value is repeated, then say that the array does not meet the promises, and you can even error with the exact way in which it fails. This is much better and in-place sort is pretty fast. Quicksort, which I will use, requires pointers and is not actually constant space (despite being an in-space sort) but because it's better and we should use it.

So, with all due respect, fuck the requirements, that is going to be our solution. I realize it misses both your linear time and constant space requirements, but I really feel these requirements are stupid and lead to a brittle solution - this solution is better and is the one I stand by. Sorry. :)"

How'd I do? Would I get the job? (Probably NOT.)

If I were looking for a junior dev, probably not. Don't like your attitude, son, and you're probably not a good fit.

But if I'm looking for a senior position, you're probably in. Senior people do push back on bad requirements, and they know when to do so, and why. If I want experience and leadership, what you did is exactly what I'm looking for.

The difference is that the senior person is going to do it when they know that the spec is a bad idea (and know why it's a bad idea), and the junior person is going to do it all the time because they're a show-off know-it-all and a hothead...

thanks :)

> All the integers between 1 and n should add up to (n(n+1) / 2) so just iterate over the array keeping a running sum, then at the end subtract from (n(n+1) / 2) to see the integer you are missing. It's constant space and requires just a single sum you track.

that was my first answer. the interviewer pointed out that even if n fit within an int, there was no guarantee that n^2 would. my immediate second thought was to multiply every even number by -1, but i realised that you could always provide an input that would make that overflow too.

Well, if you don't want to overflow then rather than summing all the numbers first and subtracting a single time from (n(n+1) / 2) at the end, you can subtract numbers one at a time from 1..n and end up with the same result. In order to make sure you don't overflow you have to tend toward zero, subtracting large numbers when your running sum gets large and small ones when it's small.

Here, I coded this for you - http://codepad.org/kdqoLXFA (scroll down for the output! it's not just a pastebin but runs it for you). As you can see my code contains tests at the end to show it's working, but not a robust testing class because it's a brittle piece of shit. I don't even want to know what it would do with input that doesn't meet its promises.

I also Googled this and an alternative (that admittedly I did not think of) given such tight restraints is to keep a running bitwise xor of your elements, and also bitwise xor'ing in (1..n) similar to the above - then you don't need to do it from a head and a tail, at the end rather than a difference you just end up with the missing number. This is probably superior to what I just coded.

But both algorithms are really stupid and really brittle. Sorting is fast and there is no reason not to do it that way.

yeah, the bitwise xor was my next solution, and what the interviewer was looking for. i found it a fun puzzle, satisfying to solve and not really brittle at all (why would you feel it was? it's just a simple loop with an xored accumulator; it cannot overflow or do anything funny).

i like the idea of subtracting from either the head or the tail of a virtual list too; that's clever :)

it's really brittle for the reason that I mentioned originally: by using a more robust, correct solution, (sorting) you can check that the input is proper, and if not, raise the appropriate exception or return the appropriate error, or simply return -1 or 0 or some other signal value. At any rate you will not silently, and in a way that seemingly works, return some arbitrary value which is simply not true. (Which is the worst kind of failure.) This does not have a large cost.

With the xor solution, on the other hand, you don't really have that option -- if the input does not exactly match the input condition, then it WILL return whatever - with no indication that anything is amiss. Even slightly wrong input will give unpredictable, completely wrong output with no indication that anything is wrong.

What's worse is that it's trivial to game: as an exercise try making a malicious generator that takes an n of at least 4 and Target number, and returns (generates) an array (of size n-1) for feeding the XOR solution that shall get the xor solution to output the Target as the missing number. Further, the malicious generator, instead of generating an array with one missing number, actually shall generate a list which is as close to correct as possible, except that it shall (as an extra 'fuck you') in all cases contain the "Target" value -- twice.

btw thanks for the feedback on the sum thing :)

Strict requirements (like linear and constant) give so much away about the nature of the solution.

"What's the best you can do within ..." adds an extra challenge - in particular I don't think I'd often see the constant space solution as perhaps one in logspace.

yeah, i was paraphrasing a bit. how the actual interview went was i was asked to simply find the missing number, i came up with the log space solution pretty quickly, the interviewer then asked if i could do better than that, and it took me a bit of thinking to come up with the constant space answer.

I really enjoyed solving that. It didn't take very long at all (but was very satisfying!). It reminds me of an old story (of which I can't verify) about Gauss while in school solving a summation using a very neat observation.

Enough said!

I tend to ask about the technology and architectural choices candidates made in their projects. If they were not involved in the decision making, what they thought of it. What they could do differently. What's the testing strategy. What challenges they enjoy.

A paid-for ticket to solve from their real codebase. Best interview question for me. No bull, no gotchas, just "Will you be able to do the work?"

One that I've been asked and now use routinely is:

"If you were to start on Monday, what do you feel most confident about, and where will you need help?"

Here are a few questions that I was asked in a Microsoft interview:

Write an interpreter for first order logic.

Define an algorithm for reordering the x87 floating point stack.

Always the non-technical questions. HR is usually staffed with psychologists, and they try to find questionable personalities, "good fit".

I talked with one hiring lady 30 minutes about movies and surfing.

The technical questions are usually superfluous if you have a proper resume and published work online. Nobody needs that crap.

I liked one that involved implementing a graphing library for a memory-mapped bitmap display. It started with drawing a circle of radius R with origin X, Y but involved several iterations of optimization. You can get into a lot of interesting performance areas (caching, reuse, loop unrolling, etc.).

I like to ask people to tell me about good software and how it's made. A surprisingly high number of people have never put any thought into this. I also like to ask about bad software and lastly what makes a good developer. If a candidate blanks on all 3 questions, it is not a good sign.

Final interview - this one with the CEO, Mr. Big runs a $4B company.

I know you've met with the senior leadership team. What questions do you have for me?

It's a brilliant question, both disarming and straight to the point. He's looking for how I think. Can this guy solve my problems?

"What are your bank requisites? We will transfer money upfront."

Contracting job, but still... That was the first "question" I got from the company. I was expecting at least to talk about my past experience, and maybe do some irrelevant CS riddles...

Tell me something that's true that very few people agree with you on.

(I haven't been asked this)

"I have all the time in the world for interviews. Is there anything more you'd like to say, ask or discuss that you've not had the chance to so far?"

This Quora page lists some interesting interview questions: https://www.quora.com/What-are-the-best-programming-intervie...

Find the minimum value in the stack in O(1) both time and space complexity.

I have a novel solution: use a delta ~~queue~~ stack! Instead of pushing straight numbers, push the delta of each new value against the next smaller value currently in the stack. Sadly I can't find a resource for this data structure. I learned about it in university when writing a sleep() function for an OS I was writing. On each tick, you simply decrement the first value (or pop it if it's 0).


push(1) : [1]

push(2) : [1,1]

push(3) : [1,1,1]

push(3) : [1,1,1,0]

pop() : 3, [1,1,1]

pop() : 3, [1,1]

pop() : 2, [1]

pop() : 1 [0]

Have a few questions .. (1) doesn't it seem like this only works for elements that have an ordering as well a binary operation multiplication, subtraction and addition defined on them, making it too specific ? (I'm talking about the whole 2x - minelement) (2) If I have a variable hanging around a stack, is it still a stack? (3) When I pop out the min value in the stack, and want the next min Value, how do I get that,? seems like the previous min value still sticks around? (4) With comparisons and 1 value that hols state, do I really need to transform the values going into the stack?

Do you mean "design a stack where you can find the minimum value in O(1) both time and space complexity"? Because I don't see how you can do O(1) with an arbitrary stack.

Yes thats right, you can come up with any solution. But make sure O(1) is satisfied (both in time and space complexity).

Anyways I had failed to give proper answer and I was rejected in the interview. This was the last question of my last round!

Spoiler: Here is one such solution using a simple but very clever trick: http://www.geeksforgeeks.org/design-a-stack-that-supports-ge...

What field of programming have you implemented that? I'm curios, is it in kernel development, some DB design. Not trolling, just curios where that usecase where this would come in handy and why ask it if it's not a direct relation to what you are doing.

Make another stack with the latest minimum, then when you pop that top value, you also pop it off the minimums stack. Then you have the last minimum before that one.

Is that it?

What if you added values that are greater then the minimum at the top of the minimum stack but less than the next value on the minimum stack?

Your using two stacks now. This is the solution that I had told but your not satisfying the condition w.r.t to space , its O(n) not O(1).

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact