25 years of programming reduced to a question.
-
That's probably even less efficient than my Linq code! :laugh: List<T> - Is it really as efficient as you probably think?[^]
"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!
-
But internally, the splice() operation is performing an O(N) operation - moving all elements down by one position. Your solution is therefore O(N^2). If I were the interviewer, I would ask if you can see a problem with this solution, and then ask you for a more efficient (O(N)) solution.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
Daniel Pfeffer wrote:
If I were the interviewer, I would ask if you can see a problem with this solution, and then ask you for a more efficient (O(N)) solution.
I'd throw my dry-erase marker at my interviewer's forehead and storm out!! :rolleyes: ... Later, they would offer me the job for sticking to my principles. :laugh:
-
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
-
Fueled By Caffeine wrote:
A lot of people are not good at on the spot tests like this, so this type of interview gets a lot of false negatives.
Yeah that's exactly right. It takes time to analyze a problem you haven't run across before. When the interview is cut short... time is not on your side. It's so much easier to spend time working on it when nobody is watching. It's almost to be a developer you have to study algorithms you'll never use and study what you'll actually be doing. Twice the effort for half the gain.
Fueled By Caffeine wrote:
One slight point though - your single loop solution will typically be slightly less efficient then the two loop solution, although it does seem clearer what your solution is doing.
Oh I agree. The further up the loop you go in the second solution the quicker it becomes, but still... hard to work against the clock like that for something new. Such is life I guess. Bubble type sorts are slow, but at least they are tried and true... which is why I went that route for the second solution. Given enough time... I'd like to think I could've done better. Guess, I'll have to brush up on stuff I'll never use once I get the job.
Fueled By Caffeine wrote:
Addendum: So when does OG start at Acelook?
Dunno... hopefully he'll get me in the door too. :laugh:
Jeremy Falcon
Jeremy Falcon wrote:
...the quicker it becomes, but still... hard to work against the clock like that for something new...
Grumpy Old Man mode (IE, Wise and Omniscient Programmer Mode): "Is this going to be a mission critical component of the software that will handle hundreds of millions to billions of values in an array, day in and day out? If not, buzz of - ANY solution I come up with for a twenty element array will be finished so shortly after the 'Enter' key is pressed with modern hardware that it doesn't matter. All that matters is getting on to the next thing. But then again, that probably isn't the right way to butter up a prospective job, although a good interviewer should recognize the truth to your statement and be much more inclined to hire you. :laugh:
-
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:
...the quicker it becomes, but still... hard to work against the clock like that for something new...
Grumpy Old Man mode (IE, Wise and Omniscient Programmer Mode): "Is this going to be a mission critical component of the software that will handle hundreds of millions to billions of values in an array, day in and day out? If not, buzz of - ANY solution I come up with for a twenty element array will be finished so shortly after the 'Enter' key is pressed with modern hardware that it doesn't matter. All that matters is getting on to the next thing. But then again, that probably isn't the right way to butter up a prospective job, although a good interviewer should recognize the truth to your statement and be much more inclined to hire you. :laugh:
:thumbsup::thumbsup::thumbsup:
Jeremy Falcon
-
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
-
I've had to hire for several firms. I don't think probing technical questions are even the best way to find good developers. Testing how people think is I think the best approach, but it's not always easy to come up with good questions for this. If I had my way, I'd be able to give each candidate a simple set of functional requirements and have them produce a small application (like notepad) then I'd look at the code. However, in practice, I've never had the opportunity to look at someone's coding style on demand like that. Whiteboarding is one thing, but it only gets you so far. When I do ask technical questions they are usually things like what is the practical difference between a linked list and a vector just to make sure they aren't totally wasting everyone's time but I can get that out of the way on the phone in a lot of cases. What I really look for though - and this puts a candidate on a shortlist for me is - do they love to code? Is it a passion? If the answer is yes, I can assume a fair number of important things about them, like that they will throw themselves at a new coding challenge rather than avoid them. The green ones are not always the best project managers, but they typically make solid coders who learn fast. Talent comes from passion, IMO. The nice thing about this, is you can tell. Do their eyes light up when they talk about code, or is it just a job to them? You can almost always tell when someone is really passionate about what they do. All that being said, I guess it should be obvious that I profoundly disagree with the techniques of interviewers you had. The questions they asked didn't find talent, and didn't really rate your ability. It seems like a poorly executed question attempting to get at the way that you think. And apparently it was complicated enough to trip up the interviewer themselves, which led them to passing over you. It sounds like they think an interview is an attempt to outsmart others and they succeeded in only outsmarting themselves. Even when I'm in your shoes I'm always the interviewer. The question in my mind when I approach a company is do *I* want to work for you? That has always served me well. You know what I think? I think you don't want to work for people like that anyway. I don't think they know how to find talent, so they probably don't appreciate the talent they have. If they did, one of them would have been interviewing you and what happened to you wouldn't have happened. So maybe they can't retain good people. It happens to a
honey the codewitch wrote:
Sorry for the long winded reply. I have a lot of feelings about the way the field hires.
It's a great post, thanks for sharing. To your points I agree wholeheartedly. I find it's much better to ask them what they study at home and what tickles their fancy the most about tech. You can teach an algorithm to people, but you can't teach personality and drive. Granted, you do need a baseline to ensure the job can be done... but a solution based on a task that's akin to the actual work being done is better than algorithmic questions alone. Or at least ask some technical questions alongside the algorithm test and not just one and done on the algorithm by itself... make it a bonus question or something.
Jeremy Falcon
-
Jeremy Falcon wrote:
we don't have to re-invent the wheel.
That is probably the correct answer. Any good programmer will reuse (or, at least, get good ideas from) code that has been proven reliable rather than creating something new that may contain bugs.
jsc42 wrote:
rather than creating something new that may contain bugs.
Exactly :thumbsup:
Jeremy Falcon
-
But internally, the splice() operation is performing an O(N) operation - moving all elements down by one position. Your solution is therefore O(N^2). If I were the interviewer, I would ask if you can see a problem with this solution, and then ask you for a more efficient (O(N)) solution.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
And while you're at, can you stop space and time and develop the first programming language used on Mars and feed that back to us? Then on the actual job... your coworker asks you... what's a box model again? How do you configure Webpack? How do I actually do any of the things my job requires? Well, at least I studied algorithms for a few weeks while interviewing. Phew. :rolleyes:
Jeremy Falcon
-
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^bI remember that from my C days. If someone asked me that in JavaScript though I'd have to take a step back end think about.... a lot. I miss a good XOR at times.
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
XOR swap algorithm - Wikipedia[^]
Software Zen:
delete this;
-
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:laugh: :laugh: :laugh: :laugh:
Jeremy Falcon
-
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!
Doing it, "in place":
List a = new List( new int[] { 1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0 } );
int count = a.RemoveAll( i => i== 0 );
a.AddRange( new int[ count ] );It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
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
Interview I mostly bullshit, I totally agree! Often not done by the people who will work for you but by people who have no clue... with whimsical question either way... It highlights the following truism - being unprepared will guarantee you failure... - being well prepared will leave success to luck... To edge your luck a bit more one got also to work on social skill and self promotion! :p
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Of course it's broken - HR doesn't know anything about the job, so they tend to rely on things like automated scanners that look for the magic keywords in the resume. Then once you've managed to pass through that first filter, the next level of the challenge is getting past the human part of the HR process, where someone who has no idea what you do decides whether or not to pass you on to the actual person/people who needs the job done. Even when you get to that step, there's a fair chance that the manager you talk to doesn't really know what they need, depending on their background and, to some extent, how long it's been since they actually did any coding. And for the high profile darlings of the stock market, as you noted, it's then on to some test totally unrelated to the day-to-day duties you'd actually be performing. It's only when you've passed all of those ridiculous barriers to entry that you might (but only might!) talk to someone who actually knows what the job entails and may be competent to judge whether or not your skills would be a good fit. How else would I wind up as a VB.Net programmer and Excel VBA macro writer when my previous experience was 40+ years of first Fortran and then C in a succession of Unix/Ultrix/Linux environments? And I still tease them about the wisdom of hiring a then 62 year old programmer to replace the 65 year old guy who was retiring!
Hey, are you my alter ego? 8) I've just thought, maybe old programmers never die, they just become VBA devs... Like you, I started with FORTRAN; then Algol68, Algol60, Pascal, assembler, C, C++, Java, PHP and a few others; now HTML5/CSS/JS, SQL, Python and VBA (Access). By the time I reach 70, will I be reduced to Scratch? HA HA Bonk!
-
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
-
And while you're at, can you stop space and time and develop the first programming language used on Mars and feed that back to us? Then on the actual job... your coworker asks you... what's a box model again? How do you configure Webpack? How do I actually do any of the things my job requires? Well, at least I studied algorithms for a few weeks while interviewing. Phew. :rolleyes:
Jeremy Falcon
Jeremy Falcon wrote:
And while you're at, can you stop space and time and develop the first programming language used on Mars and feed that back to us?
Well, we already have the first programming language to be used on Jupiter ([JOVIAL](https://en.wikipedia.org/wiki/JOVIAL)) :-\
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
-
Hey, are you my alter ego? 8) I've just thought, maybe old programmers never die, they just become VBA devs... Like you, I started with FORTRAN; then Algol68, Algol60, Pascal, assembler, C, C++, Java, PHP and a few others; now HTML5/CSS/JS, SQL, Python and VBA (Access). By the time I reach 70, will I be reduced to Scratch? HA HA Bonk!
It does appear we have a lot of things in common. The first real life project I was on straight out of college I used Cobol on a IV-Phase mini, Fortran, Cobol and Assembler on an Interdata 8/32, and Fortran, Cobol, PL/I, RPG and Assembler on an IBM 370/158 MVS system, and also wound up writing the production JCL. Since then it's been Fortran on a Banyan network, Fortran and C under Ultrix on microVAXen communicating with Fortran on Windows PCs, then C on Xenix, SCO Unix, and finally Linux, to my hopefully final job with VB/Windows using SQL on an Access database, plus a lot of Excel VBA over the last 10 years or so. Now I've started playing around with 3d resin printing, Arduinos and Pi's in my spare time so I won't be too bored in retirement; also taking classes in electronics, microprocessors, etc, at the local community college since I can audit them tuition free now that I'm over 60.
-
It does appear we have a lot of things in common. The first real life project I was on straight out of college I used Cobol on a IV-Phase mini, Fortran, Cobol and Assembler on an Interdata 8/32, and Fortran, Cobol, PL/I, RPG and Assembler on an IBM 370/158 MVS system, and also wound up writing the production JCL. Since then it's been Fortran on a Banyan network, Fortran and C under Ultrix on microVAXen communicating with Fortran on Windows PCs, then C on Xenix, SCO Unix, and finally Linux, to my hopefully final job with VB/Windows using SQL on an Access database, plus a lot of Excel VBA over the last 10 years or so. Now I've started playing around with 3d resin printing, Arduinos and Pi's in my spare time so I won't be too bored in retirement; also taking classes in electronics, microprocessors, etc, at the local community college since I can audit them tuition free now that I'm over 60.
I'd forgotten about SCO Xenix/Unix: Believe it or not, the first multi-user reservation system I developed for a shipping/airline operator was written in dBase II running on Xenix with multiplexed Wyse terminals running over AC15 lines between sites. Did a lot if stuff in dBase at one time, it really was revolutionary in the early days of micros. Likewise T/Maker a predecessor to modern day spreadsheets. I may be an old git, but I've grown up with and used many of the significant developments in computing in the last 50 years and it has been an incredible (if not particularly well paid) journey. 8)