"If you were to start on Monday, what do you feel most confident about, and where will you need help?"
Ask HN: What are the best interview questions you've been asked?
51–60 of 63 posts
Re: Ask HN: What are the best interview questions you've been asked?
#52Re: Ask HN: What are the best interview questions you've been asked?
#53one 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.
"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 g…
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...
Re: Ask HN: What are the best interview questions you've been asked?
#54Contracting 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...
Re: Ask HN: What are the best interview questions you've been asked?
#55Earlier quoted context omitted.
"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 g…
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 kno…
Re: Ask HN: What are the best interview questions you've been asked?
#56one 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.
"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 g…
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.
Re: Ask HN: What are the best interview questions you've been asked?
#57Earlier quoted context omitted.
"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 g…
> 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 t…
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.
Re: Ask HN: What are the best interview questions you've been asked?
#58Earlier quoted context omitted.
> 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 t…
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…
i like the idea of subtracting from either the head or the tail of a virtual list too; that's clever :)
Re: Ask HN: What are the best interview questions you've been asked?
#59A 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 manipu…
Re: Ask HN: What are the best interview questions you've been asked?
#60Earlier quoted context omitted.
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.
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.