25 years of programming reduced to a question.
-
Well, there is this incredibly inefficient solution:
int[] data = new int[] { 1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0 };
int y = 0;
var result = data.OrderBy(d => d == 0 ? int.MaxValue : y++);It works, but ... it's pretty horrible! :laugh:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
Oh you fancy kids and your LINQ statements. ;P It was for a frontend position, so I used JavaScript. There are some LINQ libs for JavaScript actually, but they are slow as dirt and nobody uses them.
Jeremy Falcon
-
A few moments though gave me this:
int[] data = new int[] { 1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0 };
int outp = 0;
for (int inp = 0; inp < data.Length; inp++)
{
int d = data[inp];
if (d != 0)
{
data[outp++] = d;
}
}
while (outp < data.Length)
{
data[outp++] = 0;
}"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
Right... that's the first take, but I used two arrays to pull it off to avoid the second loop.
Jeremy Falcon
-
yep, I was once asked a question of if you can only have two variables how do you switch their values. I was in a peevy mood(due to idiot I was interviewing with) and didn't really think before I answered. But I essentially said never happens in real life and why the heck do you want too and dude it really isn't possible. Once I thought about it for a second(a week later) I understood it was just a theoretical question. But hell. a = 15 b = 5 a= a+b b = a-b a = a-b But would that ever happen in a real life work environment?
To err is human to really mess up you need a computer
rnbergren wrote:
But would that ever happen in a real life work environment?
That's the point. If this was systems programming or device programming I could see that. But for your typical LOB app...
Jeremy Falcon
-
Does anyone else think coding interviews are fundamentally broken? So like, literally I've been doing this (programming) my whole life. We can all go through our accolades I'm sure, but suffice it to say I've done some things over the years to help rebuild departments in large corporations to garner the attention of regional VPs, etc. as we all have. But, I say this because, two days ago, I had an interview with Unnamed Company That Rhymes With Acelook. Don't get me wrong, they were super friendly, and it was a great chat. But I was asked questions like...
Are you comfortable with writing APIs on the backend?
That's a generic question, so of course I say sure. To me this indicates the interviewer doesn't realize the best way to interview. No real probing... just questions like that. Ok, cool. Still was a great, super friendly chat. But, then the tech portion of it came up. I was asked this.../* given an array of random numbers, push all the zero's of a given array to the end of the array
for example, if the given arrays is [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0], it should be changed to [1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0]Example:
Input: [1, 2, 0, 4, 3, 0, 5, 0];
Output: [1, 2, 4, 3, 5, 0, 0];Input: [1, 2, 0, 0, 0, 3, 6];
Output: [1, 2, 3, 6, 0, 0, 0]; */Ok fine... I get how this game works. So, let's get cracking. The first solution I start with used two arrays. Cool, no biggie. But then the interviewer asked for me to do it in-place. Ok, fine. So, I write some code that is like a bubble sort that brute forced it (ie, nested loops). We all know that it sucks to have nested loops. Anyway, the interview was cut short and that was that. I look up the "official" solution online, and it's no better than my first attempt. In fact, my first attempt was quicker due to only one loop. The one I linked to was using two loops that just weren't nested. So, not only did my original solution avoid two loops (using more memory though), but I found a more elegant solution online and I just know if that interview wasn't cut short I could've tried something like this the third go-round...
void moveZeroes(vector& nums) {
for (int lastNonZeroFoundAt = 0, cur = 0; cur < nums.size(); cur++) {
if (nums[cur] != 0) {
swap(nums[lastNonZeroFoundAt++], nums[cur]);
}
}
}But since I didn't try something like this first, I got passed on. D
Jeremy Falcon wrote:
Does anyone else think coding interviews are fundamentally broken?
Perhaps, but of the ones I've partaken in, it may also be me. With three decades under my belt, there's not much I can't do, yet I feel totally inept when asked "How would you solve" questions.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I had a similar experience: take a text and embed it in a string with a '*' at char 1 (counting from 1) and a '*' in char 14 with the text in the middle padded (if necessary) with spaces using a language whose only string function was LENGTH. I wrote a one line solution that took a max of 4 comparisons and was told it was wrong. Why? It did not match the question setters solution (which was 12 lines and always used 12 comparisons). As the interviewer said to me "There are two solutions: my way [i.e. his way] and the wrong way".
-
My "boss" - at the director's level, is great. Works hard and really knows his stuff (DBA). I'd give it better than even money that, were he able to avoid prison he'd exterminate most of his peers (and above). Some do, in fact, earn their way to management. From my observation, whether in private sector or government (and even social organizations) there are those who want to get to the top - and they're the ones who common sense promotes that one least wants to get there. Remember - management is an entire curriculum at most universities. There's little to expect from that since the paradigms are style-driven. Add in some acronyms and made-up words and you have a cult of . . . . well, read Dilbert [^] some more.
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010
-
I had a similar experience: take a text and embed it in a string with a '*' at char 1 (counting from 1) and a '*' in char 14 with the text in the middle padded (if necessary) with spaces using a language whose only string function was LENGTH. I wrote a one line solution that took a max of 4 comparisons and was told it was wrong. Why? It did not match the question setters solution (which was 12 lines and always used 12 comparisons). As the interviewer said to me "There are two solutions: my way [i.e. his way] and the wrong way".
:doh: :doh: :doh: :doh:
Jeremy Falcon
-
Does anyone else think coding interviews are fundamentally broken? So like, literally I've been doing this (programming) my whole life. We can all go through our accolades I'm sure, but suffice it to say I've done some things over the years to help rebuild departments in large corporations to garner the attention of regional VPs, etc. as we all have. But, I say this because, two days ago, I had an interview with Unnamed Company That Rhymes With Acelook. Don't get me wrong, they were super friendly, and it was a great chat. But I was asked questions like...
Are you comfortable with writing APIs on the backend?
That's a generic question, so of course I say sure. To me this indicates the interviewer doesn't realize the best way to interview. No real probing... just questions like that. Ok, cool. Still was a great, super friendly chat. But, then the tech portion of it came up. I was asked this.../* given an array of random numbers, push all the zero's of a given array to the end of the array
for example, if the given arrays is [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0], it should be changed to [1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0]Example:
Input: [1, 2, 0, 4, 3, 0, 5, 0];
Output: [1, 2, 4, 3, 5, 0, 0];Input: [1, 2, 0, 0, 0, 3, 6];
Output: [1, 2, 3, 6, 0, 0, 0]; */Ok fine... I get how this game works. So, let's get cracking. The first solution I start with used two arrays. Cool, no biggie. But then the interviewer asked for me to do it in-place. Ok, fine. So, I write some code that is like a bubble sort that brute forced it (ie, nested loops). We all know that it sucks to have nested loops. Anyway, the interview was cut short and that was that. I look up the "official" solution online, and it's no better than my first attempt. In fact, my first attempt was quicker due to only one loop. The one I linked to was using two loops that just weren't nested. So, not only did my original solution avoid two loops (using more memory though), but I found a more elegant solution online and I just know if that interview wasn't cut short I could've tried something like this the third go-round...
void moveZeroes(vector& nums) {
for (int lastNonZeroFoundAt = 0, cur = 0; cur < nums.size(); cur++) {
if (nums[cur] != 0) {
swap(nums[lastNonZeroFoundAt++], nums[cur]);
}
}
}But since I didn't try something like this first, I got passed on. D
I think after years you become so focused on real problems and real solutions, that such out-of-the-world questions are irritating you so much you not even feel to do a real effort... You take it as an insult to your developer intelligence :laugh:
"The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012
-
Does anyone else think coding interviews are fundamentally broken? So like, literally I've been doing this (programming) my whole life. We can all go through our accolades I'm sure, but suffice it to say I've done some things over the years to help rebuild departments in large corporations to garner the attention of regional VPs, etc. as we all have. But, I say this because, two days ago, I had an interview with Unnamed Company That Rhymes With Acelook. Don't get me wrong, they were super friendly, and it was a great chat. But I was asked questions like...
Are you comfortable with writing APIs on the backend?
That's a generic question, so of course I say sure. To me this indicates the interviewer doesn't realize the best way to interview. No real probing... just questions like that. Ok, cool. Still was a great, super friendly chat. But, then the tech portion of it came up. I was asked this.../* given an array of random numbers, push all the zero's of a given array to the end of the array
for example, if the given arrays is [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0], it should be changed to [1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0]Example:
Input: [1, 2, 0, 4, 3, 0, 5, 0];
Output: [1, 2, 4, 3, 5, 0, 0];Input: [1, 2, 0, 0, 0, 3, 6];
Output: [1, 2, 3, 6, 0, 0, 0]; */Ok fine... I get how this game works. So, let's get cracking. The first solution I start with used two arrays. Cool, no biggie. But then the interviewer asked for me to do it in-place. Ok, fine. So, I write some code that is like a bubble sort that brute forced it (ie, nested loops). We all know that it sucks to have nested loops. Anyway, the interview was cut short and that was that. I look up the "official" solution online, and it's no better than my first attempt. In fact, my first attempt was quicker due to only one loop. The one I linked to was using two loops that just weren't nested. So, not only did my original solution avoid two loops (using more memory though), but I found a more elegant solution online and I just know if that interview wasn't cut short I could've tried something like this the third go-round...
void moveZeroes(vector& nums) {
for (int lastNonZeroFoundAt = 0, cur = 0; cur < nums.size(); cur++) {
if (nums[cur] != 0) {
swap(nums[lastNonZeroFoundAt++], nums[cur]);
}
}
}But since I didn't try something like this first, I got passed on. D
Here's the problem: Most people involved in hiring, (HR and managers), wouldn't recognise talent if the candidate had it tattooed across their forehead. So they resort to 'mechanical' methods of selection. If anywhere needs the help of AI, it's recruitment - because the real stuff isn't in abundance!
-
I think after years you become so focused on real problems and real solutions, that such out-of-the-world questions are irritating you so much you not even feel to do a real effort... You take it as an insult to your developer intelligence :laugh:
"The only place where Success comes before Work is in the dictionary." Vidal Sassoon, 1928 - 2012
I must agree with this sentiment. :thumbsup:
Jeremy Falcon
-
Here's the problem: Most people involved in hiring, (HR and managers), wouldn't recognise talent if the candidate had it tattooed across their forehead. So they resort to 'mechanical' methods of selection. If anywhere needs the help of AI, it's recruitment - because the real stuff isn't in abundance!
This isn't an anti-management or anti-interviewer thing. I've been in management. I've hired people. More developers need to understand the other side of life before casting judgment. Anyway, my recruiter was awesome. The interviewer was great too. Super friendly and knowledgeable. It was a great experience, just broken in the way we go about it.
Jeremy Falcon
-
Here's the problem: Most people involved in hiring, (HR and managers), wouldn't recognise talent if the candidate had it tattooed across their forehead. So they resort to 'mechanical' methods of selection. If anywhere needs the help of AI, it's recruitment - because the real stuff isn't in abundance!
Btw, I do agree that a lot of recruiters and HR only go for the buzzword bingo game... but in this instance the recruiter was fantastic.
Jeremy Falcon
-
I had a similar experience: take a text and embed it in a string with a '*' at char 1 (counting from 1) and a '*' in char 14 with the text in the middle padded (if necessary) with spaces using a language whose only string function was LENGTH. I wrote a one line solution that took a max of 4 comparisons and was told it was wrong. Why? It did not match the question setters solution (which was 12 lines and always used 12 comparisons). As the interviewer said to me "There are two solutions: my way [i.e. his way] and the wrong way".
Oh yeah. Everybody who has more than 25 years in programming knows that there is only ONE SOLUTION to every given problem. That's why our job is so easy. We just look up the right solution in our programmers handbook and off we go.... Sarcastic? Who, me? Nooooooooo! :doh:
Anything that is unrelated to elephants is irrelephant
Anonymous
-----
The problem with quotes on the internet is that you can never tell if they're genuine
Winston Churchill, 1944
-----
Never argue with a fool. Onlookers may not be able to tell the difference.
Mark Twain -
Does anyone else think coding interviews are fundamentally broken? So like, literally I've been doing this (programming) my whole life. We can all go through our accolades I'm sure, but suffice it to say I've done some things over the years to help rebuild departments in large corporations to garner the attention of regional VPs, etc. as we all have. But, I say this because, two days ago, I had an interview with Unnamed Company That Rhymes With Acelook. Don't get me wrong, they were super friendly, and it was a great chat. But I was asked questions like...
Are you comfortable with writing APIs on the backend?
That's a generic question, so of course I say sure. To me this indicates the interviewer doesn't realize the best way to interview. No real probing... just questions like that. Ok, cool. Still was a great, super friendly chat. But, then the tech portion of it came up. I was asked this.../* given an array of random numbers, push all the zero's of a given array to the end of the array
for example, if the given arrays is [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0], it should be changed to [1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0]Example:
Input: [1, 2, 0, 4, 3, 0, 5, 0];
Output: [1, 2, 4, 3, 5, 0, 0];Input: [1, 2, 0, 0, 0, 3, 6];
Output: [1, 2, 3, 6, 0, 0, 0]; */Ok fine... I get how this game works. So, let's get cracking. The first solution I start with used two arrays. Cool, no biggie. But then the interviewer asked for me to do it in-place. Ok, fine. So, I write some code that is like a bubble sort that brute forced it (ie, nested loops). We all know that it sucks to have nested loops. Anyway, the interview was cut short and that was that. I look up the "official" solution online, and it's no better than my first attempt. In fact, my first attempt was quicker due to only one loop. The one I linked to was using two loops that just weren't nested. So, not only did my original solution avoid two loops (using more memory though), but I found a more elegant solution online and I just know if that interview wasn't cut short I could've tried something like this the third go-round...
void moveZeroes(vector& nums) {
for (int lastNonZeroFoundAt = 0, cur = 0; cur < nums.size(); cur++) {
if (nums[cur] != 0) {
swap(nums[lastNonZeroFoundAt++], nums[cur]);
}
}
}But since I didn't try something like this first, I got passed on. D
Jeremy Falcon wrote:
Anyone else agree this is fundamentally broken?
Yes. For experienced folks, just a problem solving should not be the one to decide. It could also be an off day not just unable to answer exactly as the interviewer is expecting.
Latest CodeProject post: Data Visualization - Insights with Matplotlib To read all my blog posts, visit: Learn by Insight...
-
Does anyone else think coding interviews are fundamentally broken? So like, literally I've been doing this (programming) my whole life. We can all go through our accolades I'm sure, but suffice it to say I've done some things over the years to help rebuild departments in large corporations to garner the attention of regional VPs, etc. as we all have. But, I say this because, two days ago, I had an interview with Unnamed Company That Rhymes With Acelook. Don't get me wrong, they were super friendly, and it was a great chat. But I was asked questions like...
Are you comfortable with writing APIs on the backend?
That's a generic question, so of course I say sure. To me this indicates the interviewer doesn't realize the best way to interview. No real probing... just questions like that. Ok, cool. Still was a great, super friendly chat. But, then the tech portion of it came up. I was asked this.../* given an array of random numbers, push all the zero's of a given array to the end of the array
for example, if the given arrays is [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0], it should be changed to [1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0]Example:
Input: [1, 2, 0, 4, 3, 0, 5, 0];
Output: [1, 2, 4, 3, 5, 0, 0];Input: [1, 2, 0, 0, 0, 3, 6];
Output: [1, 2, 3, 6, 0, 0, 0]; */Ok fine... I get how this game works. So, let's get cracking. The first solution I start with used two arrays. Cool, no biggie. But then the interviewer asked for me to do it in-place. Ok, fine. So, I write some code that is like a bubble sort that brute forced it (ie, nested loops). We all know that it sucks to have nested loops. Anyway, the interview was cut short and that was that. I look up the "official" solution online, and it's no better than my first attempt. In fact, my first attempt was quicker due to only one loop. The one I linked to was using two loops that just weren't nested. So, not only did my original solution avoid two loops (using more memory though), but I found a more elegant solution online and I just know if that interview wasn't cut short I could've tried something like this the third go-round...
void moveZeroes(vector& nums) {
for (int lastNonZeroFoundAt = 0, cur = 0; cur < nums.size(); cur++) {
if (nums[cur] != 0) {
swap(nums[lastNonZeroFoundAt++], nums[cur]);
}
}
}But since I didn't try something like this first, I got passed on. D
To be fair, putting arbitrary things at the bottom of the pile is a pretty important task for companies these days so it's no wonder they want to know you're good at it.
-
Does anyone else think coding interviews are fundamentally broken? So like, literally I've been doing this (programming) my whole life. We can all go through our accolades I'm sure, but suffice it to say I've done some things over the years to help rebuild departments in large corporations to garner the attention of regional VPs, etc. as we all have. But, I say this because, two days ago, I had an interview with Unnamed Company That Rhymes With Acelook. Don't get me wrong, they were super friendly, and it was a great chat. But I was asked questions like...
Are you comfortable with writing APIs on the backend?
That's a generic question, so of course I say sure. To me this indicates the interviewer doesn't realize the best way to interview. No real probing... just questions like that. Ok, cool. Still was a great, super friendly chat. But, then the tech portion of it came up. I was asked this.../* given an array of random numbers, push all the zero's of a given array to the end of the array
for example, if the given arrays is [1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0], it should be changed to [1, 9, 8, 4, 2, 7, 6, 0, 0, 0, 0]Example:
Input: [1, 2, 0, 4, 3, 0, 5, 0];
Output: [1, 2, 4, 3, 5, 0, 0];Input: [1, 2, 0, 0, 0, 3, 6];
Output: [1, 2, 3, 6, 0, 0, 0]; */Ok fine... I get how this game works. So, let's get cracking. The first solution I start with used two arrays. Cool, no biggie. But then the interviewer asked for me to do it in-place. Ok, fine. So, I write some code that is like a bubble sort that brute forced it (ie, nested loops). We all know that it sucks to have nested loops. Anyway, the interview was cut short and that was that. I look up the "official" solution online, and it's no better than my first attempt. In fact, my first attempt was quicker due to only one loop. The one I linked to was using two loops that just weren't nested. So, not only did my original solution avoid two loops (using more memory though), but I found a more elegant solution online and I just know if that interview wasn't cut short I could've tried something like this the third go-round...
void moveZeroes(vector& nums) {
for (int lastNonZeroFoundAt = 0, cur = 0; cur < nums.size(); cur++) {
if (nums[cur] != 0) {
swap(nums[lastNonZeroFoundAt++], nums[cur]);
}
}
}But since I didn't try something like this first, I got passed on. D
Jeremy Falcon wrote:
Anyone else agree this is fundamentally broken?
Yes. The answer that I gave some folks a couple years ago was "Please don't ask me questions I can google the answer for." There was a few seconds of silence. The question they asked me was something along the lines of "what's an abstract class?" Seriously? I've been programming for 40+ years and you ask me that??? Marc
Latest Articles:
Thread Safe Quantized Temporal Frame Ring Buffer -
To be fair, putting arbitrary things at the bottom of the pile is a pretty important task for companies these days so it's no wonder they want to know you're good at it.
True... I could see that for sorting say notifications on the frontend, but 9 times out of 10 you'd use a method like Array.protoype.sort() rather than roll your own. Point being, for most LOB applications... we don't have to re-invent the wheel.
Jeremy Falcon
-
Jeremy Falcon wrote:
Anyone else agree this is fundamentally broken?
Yes. The answer that I gave some folks a couple years ago was "Please don't ask me questions I can google the answer for." There was a few seconds of silence. The question they asked me was something along the lines of "what's an abstract class?" Seriously? I've been programming for 40+ years and you ask me that??? Marc
Latest Articles:
Thread Safe Quantized Temporal Frame Ring BufferMarc Clifton wrote:
The question they asked me was something along the lines of "what's an abstract class?" Seriously? I've been programming for 40+ years and you ask me that???
Ha ha ha ha ha ha. I laugh because I know developers who have asked a question like that way more than once. Interviewing is a bit of a skill unfortunately. It's not something that just naturally comes to people simply because they learn to program. Granted, it's important you are technical in one IMO, but you gotta learn the soft skills too.
Jeremy Falcon
-
yep, I was once asked a question of if you can only have two variables how do you switch their values. I was in a peevy mood(due to idiot I was interviewing with) and didn't really think before I answered. But I essentially said never happens in real life and why the heck do you want too and dude it really isn't possible. Once I thought about it for a second(a week later) I understood it was just a theoretical question. But hell. a = 15 b = 5 a= a+b b = a-b a = a-b But would that ever happen in a real life work environment?
To err is human to really mess up you need a computer
There is an old trick from days when memory sizes were counted in bytes. (No I did not figure it out and had to be taught it.) Use three exclusive or operations. This will avoid the overflow issue of using add and subtract. For example:
a = 15
b = 5
a = a^b
b = b^a
a = a^b -
Jeremy Falcon wrote:
Anyone else agree this is fundamentally broken?
Yes. The answer that I gave some folks a couple years ago was "Please don't ask me questions I can google the answer for." There was a few seconds of silence. The question they asked me was something along the lines of "what's an abstract class?" Seriously? I've been programming for 40+ years and you ask me that??? Marc
Latest Articles:
Thread Safe Quantized Temporal Frame Ring Buffer