r/programming • u/svpino • May 08 '15
Five programming problems every Software Engineer should be able to solve in less than 1 hour
https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour227
u/romple May 08 '15
How come I never see "Here's 2 libraries with 0 documentation, make something with them". That's been my basic software enginering experience for the past 5 years.
85
May 08 '15
Ooh zero documentation, lucky you. I'd be pleased to get that rather than misleading documentation.
→ More replies (5)46
u/romple May 08 '15
LOL. Yeah that's true.
Oh oh and maybe my favorite. "Here's a link to our javadocs!" ... click... IDE generated javadoc w/ 0 actual documentation!
→ More replies (1)→ More replies (8)53
u/vanhellion May 08 '15
Or "we have this legacy code that nobody has touched because the original developer left and the one time somebody opened the main class they vomited twice before going comatose. It's now your problem, here's a list of 200 tickets that need to be fixed. Good luck."
Literally every job I've had to date.
18
u/romple May 08 '15
"oh by the way it was written in fortran and we need to port it to C#"
→ More replies (5)→ More replies (1)9
u/baseketball May 08 '15
Honestly, this is probably the best type of problem to gauge how a programmer would do at your company. It's like 90% of my work. Of course, sometimes the legacy code is something I wrote 7 years ago that I completely forgot about. Writing code isn't that hard. Reading code on the other hand is a nightmare.
809
u/holypig May 08 '15
Well this asshole should stop calling himself a software engineer, since his solution for #4 is WRONG!
https://blog.svpino.com/2015/05/08/solution-to-problem-4
Try running with [52,5,3]
157
u/code_mc May 08 '15
This should be at the top, what a pretentious human being.
→ More replies (4)45
u/DougTheFunny May 09 '15
And he is very "humble" too, look what he said about his mistake: link.
PS: But after a train of downvotes he deleted the message.
181
May 08 '15
aha what a moron. And he wrote that without any interview pressure.
95
u/holypig May 08 '15
I can't imagine solving all of these while working under the pressure of a 1hr deadline. This whole thing seems more fitted for a hackathon then an interview.
→ More replies (9)80
u/goomyman May 08 '15
not to mention number 3 goes beyond big int in size... so your going to have to write your own addition and output methods.
soo ya.. great questions /not. Just goes to show what you think is an easy question can be quite difficult on the spot, on a whiteboard, with pressure.
→ More replies (14)→ More replies (39)28
u/cipherous May 08 '15
Hilarious, so I guess he wouldn't pass his own interview questions.
→ More replies (5)
47
u/joshschmitton May 08 '15
I've been interviewing candidates for software engineering positions since the 90s -- and then working with them after they've been hired.
I've had several cases where people who were awesome at solving these types of problems (which made us all very excited at the time) who wound up being pretty bad, for a variety of reasons. And on the other hand, some of them have been awesome.
I'm not saying questions like this don't tell you anything. We still (usually) ask at least one question similar to the first three listed here.
But I certainly wouldn't spend an hour on stuff like this (especially 4 and 5) unless it was some kind of an all day interview. Given a limited amount of time, there are other extremely important things you need to try to get a feel for about a candidate that have nothing to do with how well they solve these types of problems.
→ More replies (5)4
u/TenNeon May 08 '15
What kind of interview-visible characteristics do you find most accurately predict good performance?
→ More replies (1)
753
u/inmatarian May 08 '15
Do you pass the interview if you write a script to post the questions in a blog, then post that link to reddit, then wait 59 minutes, and then outputs that thread's comments link where everybody was having a pissing match to see who could answer all the problems?
579
u/ThereOnceWasAMan May 08 '15
125
May 08 '15
God, I'm starting to wonder if he doesn't just make comics about things he wants to happen.
→ More replies (25)54
→ More replies (6)80
35
→ More replies (6)12
250
u/retsotrembla May 08 '15
Number 3 is tougher than it looks since once you get above the 91th Fibonacci number, 12200160415121876738, it doesn't fit in an unsigned 64-bit integer, so to solve it, you have to write a bignum package.
124
145
u/Falmarri May 08 '15
Python supports arbitrarily large integers transparently
→ More replies (4)47
43
u/matthieum May 08 '15
I think that if you point the 64-bits integer overflow issue, you pass the question.
→ More replies (1)28
u/Transfuturist May 08 '15
First-order approximations! First-order approximations everywhere! Dx
148
u/retsotrembla May 08 '15
Any program can be arbitrarily sped up if it isn't required to provide the correct answer.
→ More replies (19)23
u/goomyman May 08 '15
lol apparently number is a terrible question... unless your looking for someone to bring this up. I know i would have missed that lol.
I bet the interview question guy failed this one too.
18
u/JavaSuck May 08 '15
Yes, but you only need to implement addition. Here is my attempt. It can be done in well under half an hour.
→ More replies (3)18
u/mdempsky May 08 '15 edited May 08 '15
You can simplify it a bit further.
Note that Fibonacci numbers grow slower than doubling (specifically, they grow by a factor of about 1.618), so the 100th Fibonacci number will be less than 2100. That means you can represent it with just 2 64-bit numbers x_0 and x_1.
To make printing the numbers a bit easier, instead of using x_0 + 264*x_1, you can just use x_0 + 1018*x_1.
You might be asked to show that 1036 > 2100 then. I generally remember that 103 ≈ 210, so 1036 ≈ 2120, which should be enough slack to argue it's >2100.
Note also that 1018 ≈ 260, which is why you know it will fit in a 64-bit integer.
→ More replies (1)6
→ More replies (29)3
279
u/doodly1234 May 08 '15
Some guy posts a blog and suddenly I have stopped calling myself a Software engineer :)
235
May 08 '15
Suddenly? We're averaging about 90 squillion "nobody can code for shit but me lol fizzbuzz" posts a week these days.
→ More replies (3)27
u/tequila13 May 08 '15
These days? It's been going on since the Internet started to spread.
→ More replies (5)→ More replies (6)59
u/Eckish May 08 '15
Well, if I were splitting hairs, none of these problems demonstrate software engineering. They are in the realm of computer science.
The industry has trended to labeling generic programmers as software engineers, but the field is much broader than that.
→ More replies (24)
584
u/__Cyber_Dildonics__ May 08 '15
The fifth question doesn't seem nearly as easy as the rest (the fourth question is not that hard guys).
186
u/orclev May 08 '15
That fifth one honestly has me a bit stumped... I can see how to brute force it, but there's got to be a simple solution. All the others are pretty simple and shouldn't require too much thought even if you've never seen them before.
90
u/__Cyber_Dildonics__ May 08 '15
Other people have mentioned brute forcing it, and if I was in an interview that's what I would do in that situation.
→ More replies (27)→ More replies (26)180
u/youre_a_firework May 08 '15
#5 is probably NP hard since it's kinda similar to the subset-sum problem. So there's probably no way to do it that's both simple and efficient.
→ More replies (142)181
u/codebje May 08 '15
I got stuck on #1 trying to write a for-loop in Haskell.
→ More replies (4)26
u/spacelibby May 08 '15 edited May 08 '15
for i end body
| i == end = id
| otherwise = body i . for (i+1) end body
You should be able to do that in less than an hour.
→ More replies (19)112
u/Zequez May 08 '15 edited May 09 '15
Ruby 7-liner:
['+', '-', ''].repeated_permutation(8).each do |perm| sum_text = ('1'..'8').zip(perm).flatten.join + '9' sum = eval(sum_text) if sum == 100 puts "#{sumText} = 100" end endRuby bring tears to my eyes <3
Took me more than 1 hour though, I did it in JS first, which yield a much less efficient result. I won't post the JS code because the things I did to get to the result are horrific and should not be seen by mortals. Ok here it is. I know, it's bad.
Edit 1: Optimised it a bit with something I saw someone doing below, adding the permanent '9' at the end of each string.
Edit 2: Yes! As mentioned below, you can make it shorter, 4 easily readable lines:
['+', '-', ''].repeated_permutation(8).each do |perm| sum_text = ('1'..'8').zip(perm).flatten.join + '9' puts "#{sum_text} = 100" if eval(sum_text) == 100 endAlso, added underscores for convention, sorry, too much JS lately.
Also, obligatory thanks for the gold, although I feel I didn't deserved it, too many mistakes, the code could have been 4 lines from the start!
Edit 3: Ok, since someone asked, here is a version without eval, using
String#to_i['+', '-', ''].repeated_permutation(8).each do |perm| sum_text = ('1'..'8').zip(perm).flatten.join + '9' puts "#{sum_text} = 100" if sum_text.split(/(?=[+-])/).map(&:to_i).reduce(&:+) == 100 endEdit 4: Ok, here is a version without any kind of string manipulation, all integers, no one can complain now. And still in technically 4 lines! Because I expanded the chain, so it could be just 1 line. Although I cheated with a
;inside oneinject. So let's call it 4 1/2 lines and call it a day:# The operators are: # 0 = no operator # 1 = + operator # 2 = - operator [0, 1, 2].repeated_permutation(8).each do |perm| sum_array = perm .zip(2..9) # [[0, 2], [1, 3], [0, 4], [2, 5]] etc, equivalent to 2+34-5 .inject([[0, 1]]) {|arr, (op, num)| op == 0 ? arr.last.push(num) : arr.push([op,num]); arr } # [[0, 2], [1, 3, 4], [2, 5]] etc .map{|arr| ((arr.shift == 2) ? -1 : 1) * arr.reverse.each_with_index.inject(0){ |sum, (n, i)| sum += n * (10**i) } } # [2, 34, -5] etc puts "#{sum_array.join} = 100" if sum_array.reduce(&:+) == 100 end→ More replies (34)15
u/mattgrande May 08 '15
repeated_permutation
Wow, I've never seen that function before. Now I'm going to be looking to use it all over the place...
→ More replies (6)60
u/Watley May 08 '15
Number 4 requires dealing with substrings, e.g. [4, 50, 5] should give 5-50-4 and [4, 56, 5] would be 56-5-4.
Number 5 I think can be done with a recursive divide and conquer, but it would be super tricky to make efficient.
→ More replies (43)105
u/__Cyber_Dildonics__ May 08 '15 edited May 08 '15
4 is definitely non trivial and doesn't really belong with the rest of the problems that make me feel like a genius.
I think it could be done by sorting based on the left most digit (obviously) and then resolving conflicts in the first digit by the double digit number being greater if the second digit is greater than or the same as the first digit. The rest of the sorting should happen naturally I think, so a standard sort algorithm could be used.
Edit: Before you reply, think about if your method (which is probably 'sort them as strings directly') would sort 56 then 5 then 54 in the correct order (which is 56 5 54).
→ More replies (285)15
u/goomyman May 08 '15
umm number 4 is definitely non trivial as is number 5 ( if efficiency matters ) otherwise brute force seems ok.
Answering numbers 4 and 5 in an hour interview - with 15 minutes of chitchat about your former work and resume - is unlikely. Especially at a smaller company that isnt willing to pay a silicon valley salary.
→ More replies (5)36
u/Otis_Inf May 08 '15
yeah same here. I've a degree in CS and 21 years of professional software development experience and see myself as an OK developer but I completely stopped in my tracks at 5. I could only do it through brute force which is stupid of course, but I didn't see the trick or algorithm to solve it.
Which is the problem with these problems at interviews: if you don't see the trick / algorithm to solve it, you're in trouble as it's otherwise only solveable through brute force. See it as you're given a couple of Spoj questions and you don't see the algorithm to solve them other than brute force which will be too slow and not the answer.
IMHO a silly way to test whether developers are up to the task. Sure, they show the person can write code, but you can test that in other ways too. E.g. by giving the person real-life problems they have to solve on the job as well and see how they'd solve it, complete with whiteboarding, documentation of what they're going to write, tests and working code.
→ More replies (16)13
u/Johnnyhiveisalive May 08 '15
I think you're supposed to brute force it, if it becomes a bottle neck you bring in a rockstar ego who can spend furtive weeks plotting and scheming, or just throw CPU at it like everyone else..
→ More replies (1)→ More replies (84)3
u/Peaker May 08 '15
The fifth was much easier for me than the fourth. I think many people believe they solved the fourth but at least their first solution was wrong (the blog post author included!)
278
u/crashorbit May 08 '15
Probably the best interview question is: "have you ever read a blog post about interviewing programmers?"
→ More replies (18)97
u/karlhungus May 08 '15
This is one thing i've learned from reading programming blogs: people who read programming blogs are way ahead and just peachy!
32
u/flukshun May 08 '15
So long is it's not that other blog with that other stance on things, mind you.
86
u/flat5 May 08 '15
Less than an hour for all 5, or less than an hour each?
I can do both 4 and 5 but they might take a little time to make sure I've gotten them right.
The first 3 are quite easy and should be doable in a few minutes.
→ More replies (4)29
u/B8foPIlIlllvvvvvv May 08 '15
Less than an hour for all 5.
34
u/Oberheimz May 08 '15
an hour for all 5.
It took me 42 minutes to solve the first 4 problems and I was unable to finish the fifth within one hour.. Unless there's a really simple trick on the fifth one which I can't see it takes a while write all the code.
→ More replies (15)
532
u/webby_mc_webberson May 08 '15
This guy sounds like he would he horrible to work with.
50
u/awkwardarmadillo May 08 '15
Heh, the best part is he didn't even have a correct solution for problem 4 at the outset.
If you're going to be condescending, make sure that you at least know your shit.
→ More replies (7)185
u/flukshun May 08 '15
indeed. these sorts of questions are supposed to be differentiators to help decide the best candidate, not high-stress pass/fail tests where the interviewer labels you a fake-ass-mofo who should pick a different career if you don't cruise through everything.
→ More replies (10)106
May 08 '15
Either English is his second language, or this guy needs to get off his high horse and realize that he might be a "software engineer" but he's a shitty "writer".
→ More replies (1)54
May 08 '15
Yep. I kinda get what the guy/gal is saying, but maybe there's a way of not being a dick about it.
I get that these problems should be solvable by a reasonably good programmer, but the ability to solve the challenges within a timeperiod should be taken for what it is (some challenges that a guy wrote a blogpost about) & not some divine sign from the programming-gods that one is garbage & should be thrown out.
It does seem the writer has a high opinion of him- or herself.
If you bother to read this blog at all (or any other blog about software development), you are probably good enough to solve these and 5 more problems within the hour.
→ More replies (5)→ More replies (3)53
May 08 '15
I never said that you'll be hired if you know how to answer these problems, but I won't consider you if you can't.
"I have a tiny dick."
→ More replies (3)
27
u/is_this_4chon May 08 '15
Technically I got them solved in <2 minutes, but Stackoverflow took 50+ minutes to respond to my posts.
112
u/IAMA_dragon-AMA May 08 '15
If you bother to read this blog at all (or any other blog about software development), you are probably good enough to solve these and 5 more problems within the hour. The people that think are above all these "nonsense" are usually the ones that can't code crap.
Holy shit I can feel the smug self-superiority from across the Internet.
→ More replies (1)6
u/question99 May 08 '15
I never said that you'll be hired if you know how to answer these problems, but I won't consider you if you can't.
Everyone has a way. This is mine.
Who would want to work for this asshole anyway?
24
u/arstin May 08 '15
I notice that the author didn't shut down his blog after finding out his solution to problem #4 was wrong.
→ More replies (1)
22
u/AboutHelpTools3 May 08 '15
Is there a subreddit dedicated to these kinda problems?
→ More replies (5)6
u/incestuousCookies May 08 '15
All 5 of these were quite simple - but only because I have spent a lot of time on Project Euler. If you want math related programming problems - check out
Unless you cheat and do a web search - programming solutions to the questions aren't available until you solve it yourself
118
u/camilos May 08 '15
Stop lying to yourself, and take some time to re-focus your priorities.
So basically, if you're not exactly the developer he expects you to be, then you do not deserve to call yourself a developer. This author is full of himself.
→ More replies (3)14
16
15
u/SikhGamer May 08 '15
This is a pointless post. These are regurgitated problems, you can train anyone to pass these.
The important skill is problem solving in unique cases. Not problem solving for the same damn problems over and over again.
→ More replies (10)
39
u/OneWingedShark May 08 '15
Problem 1
Write three functions that compute the sum of the numbers in a given list using a for-loop, a while-loop, and recursion.
So, how many solutions had recursion, for-loops, and while-loops in all three functions? ;)
10
u/sarahbau May 08 '15
Or used recursion, for, and while to get one solution
#!/usr/bin/perl use strict; my @list = (1,2,3,4,5,6,7,8,9,10); my $size = scalar(@list); my $i = 0; my $sum = &forsum + &whilesum + &recsum(@list); print "sum = $sum\n"; sub forsum() { my $s = 0; for( ; $i<($size/3); $i++) { $s+=shift(@list); } return $s; } sub whilesum() { my $s = 0; while($i < ($size/3)*2) { $s+=shift(@list); $i++; } return $s; } sub recsum() { if((scalar @_) == 0) { return 0; } return shift(@_) + &recsum(@_); }(yes, this was meant to be horrible. I just felt like being silly).
→ More replies (5)
13
u/mdbDad May 08 '15
Also, you have to do it on a whiteboard while being stared at with blank faces. Any errors, however simple, and they will think you are an idiot. And don't forget to use and show proficiency for their favorite library.
11
u/metaphorm May 08 '15
anyone else get a really bad vibe from this guy's blog and twitter account?
4
u/thisisdaleb May 08 '15
A horrible one. I would not want to work at this company after dealing with him.
72
10
185
u/startup-junkie May 08 '15 edited May 08 '15
Useless smug-fuckery. Give me a practical use for 3,4, and 5 that doesn't involve cryptography!
How about asking them to find bugs in a given repo? ...Or optimizing a chunk of old if statements into a switch?
If your goal is to impress and reality check junior devs... start with a little reality. This post reminds me of the ponytailed guy from the bar in Good Will Hunting.
4
u/mccoyn May 08 '15
You can not solve 3 unless you are attentive to overflow issues. You must test 4 on a wide range of inputs or you are likely to miss an edge condition. If you don't have a sense of how much time an algorithm will take you might miss the fact that 5 can be brute forced and waste a lot of time doing something complicated. All three of these turn out to be a little bit deeper than they initially appear, while not being so deep that they would take a long time to solve.
→ More replies (16)3
u/Don_Andy May 08 '15
That's kind of how I was supposed to hold an interview a couple of months ago (that sadly got canceled). Instead of giving them some nonsense task like the ones from the blog I was supposed to show him one of our projects and then give him a made-up change request for the project that closely resembles what we usually get from the customer. Then I was just going to kick back and see how he goes about it.
It wouldn't even have mattered if he would managed to pull it off right off the bat, we mostly just wanted to check how he'd go about solving the problem. What would his ideas for implementing it be, would he asks questions if he's stuck, how would he go about it, what's his coding style.
That tells us so much more about how this guy actually performs as a software engineer than having him write a fucking Fibonacci function.
Of course, that was just one guy. I can totally understand that this might not be feasible approach if you have to do loads of interviews.
→ More replies (5)
64
u/jaybazuzi May 08 '15
To those who say these questions are insufficient to determine whether to hire someone in an interview: I think that's the point. The author is saying that people who can't solve these problems shouldn't even be applying for a programming job.
Still, I don't agree. I don't want to hire someone based on what they know; what they can learn is far more important. I'll take an eager, curious person who knows nothing about programming over an experienced, skilled, knowledgeable person who doesn't care to learn anything new.
That's because the bottleneck is writing software is learning. Learning how an API works. Learning a new programming language. Learning whether your code works the way you expect it to. Learning what your customers will actually pay for.
In a team setting, even more important than willingness to learn is empathy / emotional intelligence. See Collective intelligence: Number of women in group linked to effectiveness in solving difficult problems
→ More replies (10)
7
u/heimeyer72 May 08 '15
I'd retracting my application. One hour is gone and I have only solved about half of it. #3 contains an unpleasant surprise, the numbers go up too much too quick - ksh delivers negative numbers, at some point, awk's results stay positive but are wrong at the end, so that alone requires doing it in C using some things I don't know by heart.
And #5 probably involves string operations to concatenate numbers (gives string results), then interpreting these strings as numbers and test out all possible combinations. I'd need more than one hour to just think of a solution for that alone.
I still believe that I could solve all of them. But all that together within one hour? Forget it, I don't want to work there.
→ More replies (2)3
7
May 08 '15
I think I stood half an hour to understand the difference between what the author meant as number in #5. Digits.
7
u/wordsoup May 08 '15
I guess is fine to apply for a "Front-End Web Developer" position if the only thing you know is jQuery [...]
Great, begin your blog post with being condescending. Good luck, you will need it.
→ More replies (1)
42
u/Aeolun May 08 '15
1-3: I can easily do by virtue of having seen them before, or them being basic math.
4-5: These seem a solid order of magnitude more difficult. There's undoubtedly some way to solve them, but they're more akin to riddles than programming questions. I would not expect any programmer to know the solution to these (aside from brute force) if he'd never had to deal with problems of this kind before.
→ More replies (19)3
u/manghoti May 08 '15
ditto. Still scratching my noodle on the specifics of 4, and the comment in this topic have brought up some edge cases that make the question seem so much nastier. Best algorithm I've seen so far is a divide and conquer strategy.
→ More replies (16)
17
May 08 '15
The solution for the fourth one:
Let's say you have the following numbers: {9, 95, 959,9585,9595}
You take the LCM of the number of digits, so LCm of 1,2,3,4,4 which is 12.
You expand the numbers to 12 characters long by repeating. So =>{999999999999, 959595959595, 959959959959, 958595859585, 959595959595}.
Now arrange in descnding order => {999999999999, 959959959959, 959595959595, 959595959595, 958595859585}
Looking back at the corresponding numbers you get the number: 99599595959585, which should be the answer.
7
u/zhay May 08 '15
Or make a comparator that compares a.b to b.a where . is concatenation and then sort with that comparator.
→ More replies (2)→ More replies (11)3
u/want_to_want May 08 '15 edited May 08 '15
It looks like the fourth problem is much deeper and more interesting than the others. It involves sorting strings using a very weird ordering that I haven't seen before, maybe we should call it "iterated lexicographical". Here's a couple equivalent definitions of that ordering:
String a is "greater" than string b if the infinite string aaaaa... is lexicographically greater than the infinite string bbbbb...
String a is "greater" than string b if the string ab is lexicographically greater than ba.
It's obvious that the first definition gives a transitive ordering (with the caveat that some strings will compare as equal, if they are both repetitions of the same string). But it's much less obvious that the second definition gives a transitive ordering, or that the two definitions are equivalent. After some thinking, I've managed to find a proof, but I haven't been able to make it short and beautiful. Anyone?
(Of course, once you prove any of those facts, solving the actual problem is trivial. Just convert the numbers to strings, sort them in that order, and concatenate them.)
Edit: there's actually a simple proof of equivalence, it's in the Quora link given by zhay in the sibling subthread.
6
u/Zwejhajfa May 08 '15
A good test case for number 4:
0,7,8,9,79,80,87,89,98,797,798,879,897,899,979Correct answer:
99897989989897887987807987979770→ More replies (2)
38
May 08 '15 edited May 08 '15
The people that think are above all these "nonsense" are usually the ones that can't code crap.
Or maybe I think that these are nonsense because it has nothing to do with actual Software Engineering tasks. These are high school math problems, nothing else. Have fun coding Fibonacci numbers all over again and again in your "scalable and fast enterprise software applications" dear Santiago.
What a boastful prick.
EDIT: OP, I almost took you seriously, almost.
→ More replies (1)4
u/sonjaa May 08 '15
Right? I'm not much of a programmer, but those aren't problems. They are solutions.
5
u/qudat May 08 '15 edited May 08 '15
I really struggle to see the value in these sorts of interviews. Why not give them a code challenge and ask them to complete an actual task they will be doing on the job? This allows the developer to take the problem home, spend time thinking about it, write up with a solution, and then consequently doing a code review with the interviewer after it's all over. And if the project is good enough and you asked them to accomplish something the team could actually use then you also get a free product out of it. All the interviews I administer involve a code challenge where the end result is something my team could use and benefit from.
Example: We have a dashboard web app that pulls in data from our web analytics tracking, synthesizes it into some data visualization and then is presented on TVs mounted throughout the entire building. These dashboards don't directly affect revenue and aren't extremely complicated, but it is something we all value nonetheless. We like to ask interviewees to create a single dashboard to display some new or different metric. What do we gain from this sort of code challenge?
We ask the interviewee to work with code we've already created so they get to read code they will need to understand on the job anyway
We allow the interviewee to get into their normal development process and devise a solution in the comfort of their own home without the pressure or people leering at every keystroke
The challenge forces them into our development process, which helps us see how well their dev process works with us.
When the code is done we can easily pull down their work and see how well it integrates into our app
We get to see exactly how they would complete a real world task
We get to code review the end result with the interviewee, even if we don't hire them, it's an excellent learning experience
We get to keep their dashboard and potentially use it if we like it
If we do hire them then we know on day 1 they are already familiar with one of our product's source code and can get them to started on another dashboard immediately
Not only would the above interview process be immediately beneficial to my team but it also doesn't remove the developer from the development process the team employs on a weekly basis.
I really struggle to see how any other interview process can beat it. Does anyone else have any thoughts?
→ More replies (1)3
u/Banana_Hat May 08 '15
I think you way would be the best way to go. IANAL but there may however be some legal issues using the code of someone you haven't hired in one of your products as they did work for you that you haven't compensated them for. As a interviewee I liked getting test projects to work on rather than on the spot problems where I couldn't use research tools.
53
u/laddercreek May 08 '15
the first 3, I get the intention; we want our programming candidates to um, yeah, actually know how to write code --and the 3rd one only barely qualifies. #4 and #5 I find myself (damn near 25 years of appdev experience, thankyouverymuch) asking why? Where's the applicability when I need to hire someone to grab some shiz from a db and do some transformation and spit it up on a webpage (hello, that's like 75% of software development)?
101
u/__Cyber_Dildonics__ May 08 '15
Step 1. Separate the html5/javahipsters from the men. Step 2. Create a problem where you know a more optimal answer than the candidate will get to in an hour so you can still feel superior.
→ More replies (3)31
→ More replies (5)4
u/Guvante May 08 '15
It is really hard to talk about asymptotic running time in an interview without an example. Since everyone learns about sorting it is good to do a non-sorting problem where you can talk about how long something takes to run.
22
u/howdoidoit123 May 08 '15
Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
I can't figure this one out
29
u/itsSparkky May 08 '15
Think like a tree, at each digit you can do the following Add next number Subtract next number Times current number by 10 and add next number
3 outcomes each time, you can either depth first or breadth first search and then evaluate the solution at the end and keep the paths that result in 100.
→ More replies (8)17
u/billatq May 08 '15
Yeah, I was thinking about doing it with a BFS and a tree. Seems like an okay problem, but I feel like that particular one is more like a math trick than anything else.
→ More replies (11)13
u/cretan_bull May 08 '15 edited May 08 '15
Just brute-force it. Between each number, there a 3 possibilities: plus, minus, or concatenated digits. In total, this is
39=1968338 = 6561 cases to check.EDIT: off-by-one error
→ More replies (6)12
4
u/carnetarian May 08 '15
Here's my solution in perl. I'm sure a better programmer than me could make something much more efficient, but this gets the job done. Basically I generate every possible combination of strings like "1-2+3+4-56-89" then I evaluate each of those strings. This problem took me much longer than all the other problems combined.
#!/usr/bin/perl use strict; sub interpolate($) { my $str = shift; my @results = (); push(@results, $str); if (length($str) > 1) { for (my $i = 1; $i < length($str); $i++) { my $start = substr($str, 0, $i); my $end = substr($str, $i); my @temp = @{interpolate($end)}; foreach my $t (@temp) { push (@results, "$start+$t"); push (@results, "$start-$t"); } } } return \@results; } sub evaluate($) { my $equation = shift; my $lastPlus = rindex($equation, "+"); if ($lastPlus != -1) { my $a = substr($equation, 0, $lastPlus); my $b = substr($equation, $lastPlus + 1); return evaluate($a) + evaluate($b); } my $lastMinus = rindex($equation, "-"); if ($lastMinus != -1) { my $a = substr($equation, 0, $lastMinus); my $b = substr($equation, $lastMinus + 1); return evaluate($a) - evaluate($b); } return $equation; } my @results = @{interpolate("123456789")}; foreach my $result (@results) { my $sum = evaluate($result); if ($sum == 100) { print "$result\n"; } }→ More replies (3)→ More replies (10)4
11
u/evolvedant May 08 '15
"Here is my list of 5 EASY questions that if you can't get right in under an hour, you aren't a programmer."
later...
"Ok, I see Reddit which is full of strong bright programmers is up in arms about question 5, so let me explain my solution in a blog post that probably took more than an hour to write..."
When even Reddit, which is full of really strong programmers has a problem with your 5 questions, obviously your entire ideology of judging who should call themselves a programmer or not based on 5 problems in under an hour needs to be reevaluated. But sure, instead of questioning your ideology, let's just write a blog to try and convince everyone otherwise...
/facepalm
The best question for a programmer interview is to ask if they do any programming on the side, such as pet projects. See if they have a passion in programming.
3
u/Randosity42 May 08 '15
also he got #4 wrong. He couldn't his own questions without a time limit, let alone while under pressure.
→ More replies (1)
4
May 08 '15
I got to be honest... If an employer ask me to do this, I will shake the interviewer hand and walkout the room asap.
Not that I couldn't solve the problems but given the time constrain and the pressure of the interview itself I would probably fail therefore why bother trying if the result will be that I wouldn't complete in time so the most logical option will be not to waste time on it (of course unless it's a job I want).
4
u/vuldin May 08 '15
Oh well guess I need to find another job. I'll be talking with manager about my incompetence later today. Thanks for the heads up!
3
u/rabid_briefcase May 08 '15
I'll be talking with manager about my incompetence later today.
Yay, job opening! Where do/did you work? :-)
4
u/dooklyn May 08 '15 edited May 08 '15
I don't see what the 4th or 5th questions have to do with actual programming. Those are logic problems and while they are tough, they don't test anything relevant to programming patterns, knowledge of tools, basically anything relevant to actually building modern software. Do you even ask if the guys know any relevant libraries? Or is it enough that he can solve your 5 little problems in QBASIC and that makes him a programmer?
You seem like the kind of elitist that writes obscure code just to stump others in order to feel superior. I bet it sucks balls working with you, maybe that's why you can't find anyone good.
Edit: how did this get 2000 upvotes, are people that insane? Or maybe the guy has some shitty bot running...
→ More replies (3)
13
u/Opux May 08 '15 edited May 08 '15
Number 5 seemed like it was much more difficult than the others. So, I decided to solve it. If anyone is interested, here is a non-eval language (namely, C++) solution. It handles eval with operator precedence by generating reverse polish notation and then solving it with the shunting yard algorithm (these steps are combined).
The cartesian_product function should probably use typetraits to enforce iterator structure and derive the output container type, but after a time I started to not care anymore.
You can make the Cartesian product lazy by making a fake output iterator that evals and prints, but I decided to not (again, I stopped caring).
#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <stack>
#include <vector>
using namespace std;
template <typename InputIterator, typename OutputIterator>
void cartesian_product(InputIterator input, InputIterator end,
OutputIterator output) {
vector<typename InputIterator::value_type::value_type> current;
cartesian_product_helper(input, end, output, ¤t);
}
template <typename InputIterator, typename OutputIterator>
void cartesian_product_helper(InputIterator input, InputIterator end,
OutputIterator output,
vector<typename InputIterator::value_type::value_type>* current) {
if (input == end) {
*output++ = *current;
} else {
for(auto i : *input) {
current->push_back(i);
cartesian_product_helper(input+1, end, output, current);
current->pop_back();
}
}
}
enum class BinaryOperator {
ADD, SUBTRACT, DIGIT_APPEND
};
int precedence(BinaryOperator op) {
static map<BinaryOperator, int> precedence_lookup {
{BinaryOperator::ADD, 0},
{BinaryOperator::SUBTRACT, 0},
{BinaryOperator::DIGIT_APPEND, 1}};
return precedence_lookup[op];
}
string to_string(BinaryOperator op) {
static map<BinaryOperator, string> to_string_lookup {
{BinaryOperator::ADD, "+"},
{BinaryOperator::SUBTRACT, "-"},
{BinaryOperator::DIGIT_APPEND, ""}};
return to_string_lookup[op];
}
int eval(BinaryOperator op, int left, int right) {
switch(op) {
case BinaryOperator::ADD:
return left + right;
break;
case BinaryOperator::SUBTRACT:
return left - right;
break;
case BinaryOperator::DIGIT_APPEND:
return left*10 + right;
break;
}
return 0;
}
void print(const vector<BinaryOperator>& operators) {
int current_num = 1;
for (auto op : operators) {
cout << current_num++ << to_string(op);
}
cout << current_num << " = 100" << endl;
}
void eval_once(stack<int>* num_stack, stack<BinaryOperator>* op_stack) {
int r = num_stack->top();
num_stack->pop();
int l = num_stack->top();
num_stack->pop();
num_stack->push(eval(op_stack->top(), l, r));
op_stack->pop();
}
int eval(const vector<BinaryOperator>& operators) {
stack<int> num_stack;
stack<BinaryOperator> op_stack;
int current_num = 1;
for (auto op : operators) {
num_stack.push(current_num++);
while (!op_stack.empty()) {
if (precedence(op) <= precedence(op_stack.top())) {
eval_once(&num_stack, &op_stack);
} else {
break;
}
}
op_stack.push(op);
}
num_stack.push(current_num);
while (!op_stack.empty()) {
eval_once(&num_stack, &op_stack);
}
return num_stack.top();
}
int main() {
vector<BinaryOperator> ops {BinaryOperator::ADD,
BinaryOperator::SUBTRACT,
BinaryOperator::DIGIT_APPEND};
vector<vector<BinaryOperator>> cart_prod_input;
fill_n(std::back_inserter(cart_prod_input), 8, ops);
vector<vector<BinaryOperator>> cart_prod_output;
cartesian_product(cart_prod_input.begin(), cart_prod_input.end(),
std::back_inserter(cart_prod_output));
for (auto ops : cart_prod_output) {
if (eval(ops) == 100) {
print(ops);
}
}
return 0;
}→ More replies (4)4
u/matthieum May 08 '15
Just knowing the Shunting Yard algorithm probably qualifies you better than any of the 5 problems.
For fun, I tried without, and I didn't get significantly less code: http://ideone.com/cPT5Pc although it might be more straightforward, maybe.
→ More replies (2)
15
7
u/ph0bitor May 08 '15
Blogs like these and the resultant threads always make me realize how many people in this field are super arrogant jerks. Lambasting people or trying to strip them of their title by asking tricky or unfamiliar questions reeks of having a superiority complex.
If someone has a CS or SE degree, they've likely gone through a fairly rigorous curriculum and telling them they don't deserve it because they can't connect all the dots you want on the odd interview question just makes you sound like a prick. If you want to make answering all these questions successfully a requirement for employment at your company that's fine, but please fuck off with the 'holier than thou' attitude already.
I don't see any other group of professionals incessantly blog or comment at how incapable their peers are.
→ More replies (4)4
u/fiercekittenz May 08 '15 edited May 08 '15
I tend to agree with your sentiments. I'm not saying there isn't value in asking people to solve problems during interviews. However, there's a big difference between seeing how the candidate thinks and attempts to solve a problem and whether it's right or wrong. With problem #5, if a candidate made a good effort, didn't have a little freak out, and was able to think critically through the problem, I'd be ok with that.
9
u/halifaxdatageek May 08 '15
Good post, they started easy and moved up to a reasonable degree of difficulty (Problem 5 would probably take me right up to the edge of the hour, haha).
Now I have my own list of five for people who are good with this list:
Correct someone's code without making assumptions about the person who coded it.
Give a talk to a group of more than ten people you don't know.
Give a talk to a group of more than ten people you do know.
Successfully convince your boss why something is a bad idea for business reasons.
Manage a group project involving more than three developers.
→ More replies (2)3
May 08 '15
What? Get out of here with your interpersonal bullshit! All that's important in programming is that you like being "in the code" and are a "hack" and why would you need a code review to tell you what you already know, that you're the best there ever was, amirite?
P.S. Those quotes are from actual recruitment emails that I've received.
→ More replies (1)
59
u/Mekigis May 08 '15
This has nothing to do with software engineering. Do mechanical engineers get questions about steel alloying elements microstructure? Hell no, they do know such alloys exist and where to use them; same way software engineers know there are algorithms to solve their tasks.
→ More replies (11)55
u/johnw188 May 08 '15
Yes, but mechanical engineers get questions about analyzing random nonsensical physical situations, much as software engineers get questions about random nonsensical software tasks.
For example, I interviewed with Apple as a meche a few years back. Got asked the following: Take a glass of water and place it on a record player, then start the player spinning. Does the water spill out of the glass before the glass tips over?
13
→ More replies (18)45
u/RICHUNCLEPENNYBAGS May 08 '15
Take a glass of water and place it on a record player, then start the player spinning. At what time will the first train arrive in Toledo?
→ More replies (1)
11
u/thebhgg May 08 '15
(defun prob-1a (lst)
(reduce #'+ lst))Crap, it's not a for loop.
(defun prob-1b (lst)
(apply #'+ lst))Crap! It's not a while loop!
(defun prob-1c (lst)
(let ((val 0))
(dolist (x lst val) (incf val x))))CRAP!!
(defun prob-1d (lst)
(if lst
(+ (car lst)
(prob-1d (cdr lst)))
0)) It figures: recursion is the only natural way.
→ More replies (3)3
6
May 08 '15
Overall these problems were fun but I'd rather just do FizzBuzz or something else that's quick during an interview. I feel that an hour is pushing it and I'm sitting comfortable in my home with my favorite tools, not sweating in front of a whiteboard. Use the interview time to engage with the candidate and get a feel for more than just puzzle coding ability. An hour of time is worth money to both of you and I wouldn't want to waste that much time with a heads-down pop quiz.
I did it in a little over an hour but messed up #4 when sorting as strings, as some people here have pointed out. I fixed it using padding with the letter "A" which is later stripped out.
static long ProblemFour(List<int> myInts)
{
List<string> myStrings = new List<string>();
int longestString = 0;
foreach (int x in myInts)
{
myStrings.Add(x.ToString());
if (myStrings.Last().Length > longestString)
{
longestString = myStrings.Last().Length;
}
}
for (int i = 0; i < myStrings.Count; i++)
{
while (myStrings[i].Length < longestString)
{
myStrings[i] += "A"; // "A" is greater than "9" when sorting
}
}
myStrings.Sort();
string s = "";
for (int i = myStrings.Count - 1; i >= 0; i--)
{
s += myStrings[i];
}
return Convert.ToInt64(s.Replace("A", ""));
}One and two were easy. Three was easy except whoops, integer overflow. Recoded as longs and whoops, long overflow. Fibonacci gets big fast.
My solution to number five is a brute forcer shown here but I'm sure it can be improved upon:
static void ProblemFive()
{
string[] operands = new string[8];
ProblemFiveInner(operands, 0);
}
static void ProblemFiveInner(string[] operands, int cursor)
{
if (cursor < operands.Length)
{
// go deeper
string[] newOperands = (string[])operands.Clone();
int newCursor = cursor + 1;
newOperands[cursor] = "-";
ProblemFiveInner(newOperands, newCursor);
newOperands[cursor] = "";
ProblemFiveInner(newOperands, newCursor);
newOperands[cursor] = "+";
ProblemFiveInner(newOperands, newCursor);
}
else if (cursor == operands.Length)
{
// check validity
int sum = 0;
string s = "";
int i = 9;
while (i > 1)
{
s = i.ToString() + s;
if (operands[i-2] == "-")
{
sum -= Convert.ToInt32(s);
s = "";
}
else if (operands[i-2] == "+")
{
sum += Convert.ToInt32(s);
s = "";
}
i--;
}
sum += Convert.ToInt32("1" + s);
if (sum == 100)
{
string res = "1";
for (int j = 2; j < 10; j++)
{
res += operands[j - 2] + j.ToString();
}
Console.WriteLine(res + " = 100");
}
}
}Answers to number five are as follows:
12-3-4+5-6+7+89 = 100
123-4-5-6-7+8-9 = 100
123-45-67+89 = 100
123+4-5+67-89 = 100
123+45-67+8-9 = 100
12+3-4+5+67+8+9 = 100
12+3+4+5-6-7+89 = 100
1+23-4+56+7+8+9 = 100
1+23-4+5+6+78-9 = 100
1+2+3-4+5+6+78+9 = 100
1+2+34-5+67-8+9 = 10010
→ More replies (1)3
u/abeliangrape May 08 '15
It pays to use a high level language for these types of problems. Check out my python solution:
from itertools import * l = [str(x/2) if x%2==0 else '' for x in range(2,19)] for ops in product(['','+','-'],repeat=8): l[1::2] = ops if eval(''.join(l))==100: print "%s = 100"%''.join(l)And the output:
123+45-67+8-9 = 100 123+4-5+67-89 = 100 123-45-67+89 = 100 123-4-5-6-7+8-9 = 100 12+3+4+5-6-7+89 = 100 12+3-4+5+67+8+9 = 100 12-3-4+5-6+7+89 = 100 1+23-4+56+7+8+9 = 100 1+23-4+5+6+78-9 = 100 1+2+34-5+67-8+9 = 100 1+2+3-4+5+6+78+9 = 100→ More replies (3)
3
u/Spiderboydk May 08 '15
Remember bruteforcing the answers is legitimate. Postpone worrying about optimization until you know you need it, and you don't know that before you've profiled. :-)
3
u/numbski May 08 '15
"Five lists that you can post to a news aggregation site to get hits. Because lists get clicked."
3
u/Kylearean May 08 '15
The reality here folks is that you will encounter interviewers like this, whether or not you think it is right.
Isn't it better to be prepared? None of your potential employers will be objective and fully rational people.
→ More replies (1)
3
u/jgotts May 08 '15
Can't remember the last time I worked on a serious problem as a software engineer that took me less than an hour. Been doing it full time since 1999.
These toy problems aren't necessarily going to find you good software engineers. They might have the opposite effect. You'll bias your hiring towards people who write terrible software from a maintenance perspective but are adept at cobbling together hacks in one hour.
3
u/Darkmoth May 08 '15
This reminds me of an interview where one of the lead devs asked me to enumerate all the options of the "grep" command.
I told him the answer was "man grep".
→ More replies (4)
3
u/usethedoorknob May 08 '15
These questions aren't worded very clearly, particularly the last one. Are they intended to evaluate proficiency at interpreting unclear specifications?
3
u/bitcoinsftw May 09 '15
I can vouch for this. I'm a Software Engineer and I write algorithms for the fibonacci sequence daily.
→ More replies (1)
3
u/rickcarlino May 09 '15
Inflammatory blog post laced with name calling and aimed at an industry whose biggest fear is imposter syndrome. So helpful and professional!
10
u/travelooye May 08 '15
To be honest to solve all of them in hour (so that the solution passes all the test cases) is a big stretch. The 4 n 5 would atleast take some time to come up with an optimal solution and If these qs are asked in the interview (which some programmers usually get asked) I really qs whether the interviewer would be able to answer the same qs if he/she dint know about the optimal algo. before hand.
EDIT:typo
10
u/ponytoaster May 08 '15
If I got asked to do this in an interview I'd probably walk out. They are easy enough, 5 is a bit harder, but doing this doesn't show my skill. Anyone can code, less can develop - which is what I'm probably there for.
At our place when we/I conduct interviews we typically don't do code tests unless we think the candidate is lying about a skill or we are unsure. Even then it's an incredibly simple task to write a small console app. I believe this is far more beneficial as you see someone's thought process, their code style and it makes for interesting talking points.
→ More replies (2)8
u/Ada1629 May 08 '15
If only more people did that. The stories I hear about the bullshit programmers are put through during interviews, and I've had some of that happen to me too. Procter anyone? I don't know any other profession which makes people jump through hoops as much as IT people with software developers, unless it's the fucking circus. And don't justify it because of what software devs make, because managers and bankers make more, and they aren't treated like circus animals. If companies need to see me jumping before they hire me, then that seems to indicate my 100k degree in cs seems meaningless to them, in which case I wish I had been told about this BEFORE I took the loans out.
My dad spent 4 hrs up at a whiteboard writing code while 5 guys watched him...at age 50...He was not happy. My friend was told to write a program in 20 minutes else he wouldn't have a chance to be hired, while the guy interviewing him told him it took him 2 days...wtf?
Now truth be told, I suffer from a really low self esteem, especially in my career. Maybe it's because I'm a female in a extremely male dominated field which itself might not be the problem except that guys tend to one up each other in ways I am not accustomed to, and I interpret the bragging literally and without a grain of salt. Maybe as a female, due to culture or biology, I'm more adapt at understanding 'one upping' and 'alpha/beta' on female terms, in a female context, and since in the cs world there is none of that I suffer. I'm also not a gamer and hate the new star wars movie and I don't like comics so I start feeling inadequate right at the hobbies level.
I've taken a few of the cs tests recruiters made me take and did quite well...I started studying up on some of the basics and filling in some of my gaps, which has improved my confidence a little. BTW just to clarify I've had really good jobs and done pretty well at them - these are things I keep having to remind myself of on a daily basis however. So in that way I'm glad I took the tests...but in general I freak the fuck out anytime a test is mentioned in an interview context. I just lose my goddamn mind thinking about it.
And the thing is, outside of interviews, I love puzzles - I'm usually the first one to grab pencil and paper and start solving...as long as people aren't watching me. And judging my coding.
But deep down something tells me I'm not that stupid. And I enjoy coding...I really really love writing code. I wish I knew more, which is my fault, partly due to laziness and partly due to my feelings of inferiority which made me run away and stay silent instead of asking questions.
tl;dr my point is that I really really hate the huge egos (like OP's) in software development that judge others. I also think it's really unfair to make software developers with degrees and/or years of solid experience stand by the whiteboard and jump on command while people sit and judge. I consider it a hindrance to the field (it keeps people who are smart but more easily intimidated, out for no good reason (being able to withstand peer intimidation serves as no real advantage for software developers, wall street guys maybe, but not devs). Also as a female I feel disadvantaged right from the start of the dick-bragging, because hey, guess what, I don't have one. At the same time puzzles are fun and sometimes taking tests can be insightful.
→ More replies (1)
6
u/hakkzpets May 08 '15
I have always wondered why programmers seems so obsessed with "X things all programmers need to know".
I follow a lot of subs for different professions, but /r/programming is the only place where these articles constantly are posted.
You never see "X things doctors/musicians/laborers/electricians need to know" threads pop up anywhere else.
→ More replies (2)6
u/minusSeven May 08 '15
Because its something that makes people feel better about themselves.
omg that guy can't make a fibonacci series using recursion. omg half the people at interviews can't solve such a simple problem.
The bigger problem is people are terrible at taking interviews far more than interviewees bad at interviews.
→ More replies (1)
7
May 08 '15
Yeah because I've ever actually used the fibonacci sequence in any real-world problem. What a load of drivel. This is facebook group quality stuff here.
→ More replies (2)
9
u/bzeurunkl May 08 '15
Yeah, uhm, I'm really a bit too busy updating my input form to accept more than 15 "flight legs" of data input while making sure we don't spill out of the 720px width the div has been assigned so it doesn't break the formatting of the Airport Station List to it's right.
But hey.... If you need a guy to add the digits 0-9, then do go right ahead with your search.
2
u/arocketman May 08 '15
This is how I solved the first 4 problems in Java. Fifth one is ... not that easy really :/ .
→ More replies (6)
2
u/umilmi81 May 08 '15
I don't know where this guy lives where he's got a choice of so many web developers, but where I live knowing jQuery is certainly enough to get an entry level programmer position. We'll train you for all the other stuff, just need a guy who wants to be a web developer. We'll make you a web developer.
2
u/Neuromante May 08 '15
I'm late to the party, but being a developer with small professional experience... are this kind of problems actually RELEVANT to real, day to day, software engineering?
Most of the work I've done (and other colleages do) involves calling API function A, patching API function B so it returns exactly what you need and implementing new properties files. The closest I've been to an actual, real, interesting algorythm was implementing an undo/redo queue.
And is a honest question. Spending most of my time Ctrl+click'ing through the codebase and looking the documentation for the specific function to call (so future developers ctrl+click through it) is slowly burning me.
2
u/_StupidSexyFlanders May 08 '15
This article actually hit close to home as I'm proud to say my business card says Software Engineer, but I could only do a couple of these.
The thing is though is this article really a test of if you can code or is it just what some know it all wants to categorize you as?
I may not be able to answer all of these questions within an hour off the top of my head, but if my company has an issue which can be solved programmatically, I am capable of developing a solution. I'm not faking my way through this career. I create applications and solve problems. May not be the most elegant or efficient code, but it does what it needs to. And I'm constantly learning and improving.
Bicker and bitch about whatever you want to address my job as. All this article really proves is how some people care way too much about things that don't concern them.
→ More replies (1)
2
u/angry_wombat May 08 '15
A lot of those test just seem to prove you can use recursion. And the last one seems to be more of a brain teaser, I couldn't understand what it was asking me to do. I thought it was all numbers between 1..99 because of the combined 2 digit numbers
I think implementing the luhn algorithm would be a good test. Proves you know the modulus operator.
2
May 08 '15
Less than one hour each? Or all 5 in less than one hour? The latter is challenging, but I think I could do it :P But, I'm not 'every programmer' so, I feel like you mean an hour each.
2
u/MikeVegan May 08 '15
Who doesn't like fun puzzles? 5th is unfair compared to all the others, here is my solution in python
def one_hundred():
def __one_hundred__(curr_expression, numbers, action):
expression_new = [x for x in curr_expression]
numbers_new = [x for x in numbers]
number = numbers_new.pop(0)
if action == 0: #join with last
last = expression_new.pop()
expression_new.append(int(str(last) + str(number)))
if action == 1: #simple addition
expression_new.append(number)
if action == 2: #simple subtraction
expression_new.append(-1 * number)
if len(numbers_new) == 0 and sum(expression_new) == 100:
print expression_new
if (len(numbers_new) > 0):
__one_hundred__(expression_new, numbers_new, 0)
__one_hundred__(expression_new, numbers_new, 1)
__one_hundred__(expression_new, numbers_new, 2)
__one_hundred__([], range(1, 10), 1)
__one_hundred__([], range(1, 10), 2)→ More replies (2)
2
u/sparafucilee May 08 '15
Used Python in Emacs with an interactive interpreter.
Took me 20 minutes to write and test the first 4, more than half of which was spent debugging syntax errors, your usual mistypes, and looking up functions (I haven't written Python in a few years so I kind of bumbled through it).
Took me 20 minutes to solve the last one, most of which was spent thinking about how to solve it. The question probably needs rewriting... It took me a bit to figure out what you meant. Hardest part is just figuring out the best way for your language to generate the permutations.
2
2
u/vegiimite May 08 '15
Author's own approach to #4 is incorrect.
→ More replies (1)
2
u/stompinstinker May 08 '15
In my experience problems like this only prove people are good at problems like this. I need people who can work on big things and not be dicks to everyone on the team. As well, the author struggled with it themselves.
2
u/flatlander_ May 08 '15 edited May 08 '15
Here are my solutions in python FWIW. Definitely didn't get them in an hour. Guess I need to go quit my job.
2
2
u/IWasTrickedAgain May 08 '15
Great questions / problems to be asked in an interview. Straight away I would know that I wouldn't want to work for him or the company.
2
u/kamiikoneko May 08 '15
This is horse shit.
I interview and I own a business and I don't give a fuck if someone can solve these problems. They don't make you a "software engineer" they make you a coder, and a coder is useless to me. These kind of problems NEVER come up in the workplace.
A software engineer, in an interview, should be handed a large app feature and get designing how to implement it and model the data.
2
u/DuneBug May 08 '15
First 3 are pretty basic... Stuff you could be able to do after your first compSci class if you actually understood the material.
4 Is a really great question in my book but.. I wonder if it's not the same for everyone, not everybody thinks the same. But I could see asking this in an interview and having a fun discussion to walk the guy through the problem.
5 is bad, unless you're looking for a developer to work on number crunching or something. #5 is IMO the kind of question NOT to ask. Every elitist SE has their own question like this that they think is super clever and if you can't solve it you must be an idiot. But they probably had seen something similar to it in the past, or do a lot of number crunching, or just have a brain that works that way. Most of reddit disliking this question is proof enough of this. Honestly I've had questions like this and turned down the job because I didn't want to work for the guy that thought this was a good question.
At the end of the day #5 has very little to do with programming or problem solving. I think it's a reasonable question to give someone that has a day to solve it, but not an hour. The OP's solution is like 40 lines of code... You're expecting someone to solve that in under an hour, during an interview?
Maybe I'm bitter because I wouldn't be able to solve it (not sure actually?), and I know some people that probably could. But it's used as some litmus test for programming or software engineering when it has very little application to either. If this is your boolean for "can this guy code" you'll turn down a lot of people who can code software, and accept the people who can code recursive functions manipulating integers... Who might also be able to write software.
2
u/gripejones May 08 '15
I've seen a few of these types of problems floating around. Does anyone have a list of these somewhere? I would like to use them to learn other languages.
→ More replies (1)
2
u/pixaeiro May 08 '15
These are actually very good questions. Sometimes I have to interview software engineers, and it is hard to find questions that are easy enough to explain, but hard enough to answer. These would be good questions for a phone interview!
2
u/sebnukem May 08 '15 edited May 08 '15
lol OP got the wrong answer. He missed -1+2-3+4+5+6+78+9.
→ More replies (3)
2
u/rooktakesqueen May 08 '15
There are 12 solutions to problem 5, not 11, if you want to count: -1+2-3+4+5+6+78+9 :)
→ More replies (1)
2
2
u/prelic May 09 '15 edited May 09 '15
Disregarding the fact that the blog author is kind of a dick for posing these questions in the most arrogant conceivable way, and then getting one wrong, I'm surprised I always see the same type of algorithmic questions. Here is a list of 5 problems I'd to see a potential candidate answer:
Open a file, read its contents and write them to another file.
Create a simple message-logger class/interface/API that outputs an information/warning/error level and a message string to stdout.
Create an application that parses 3 command line arguments and prints them out.
Create a file, create a simple source control repository, change the file, and commit your change into the repository.
Write a simple number guessing game (higher or lower).
→ More replies (2)
2
u/keyslemur May 09 '15
Funny that you say at the end:
The people that think are above all these "nonsense" are usually the ones that can't code crap.
Even if you use the word usually, that's still extremely pretentious. Tell me with a straight face when you'd use any of these in an actual job (except for sum) and I'll take it back.
You want to know why tech interviews are so annoying, it's because people are so stuck up on asking trick questions and difficult problems that are absolutely pointless. If this was the interview set I got, I would likely walk out of the interview.
Can I solve them? Yes, but that's not the point. The type of mentality required to justify asking such questions is to me very annoying to work with.
Number 4 itself is the hardest problem by far on that list when actually looking into performance. I would be surprised if a standard Junior to Midlevel could solve that in under 30 minutes without permutations.
→ More replies (3)
2
u/EddieTheHead14 May 09 '15
What's the big deal guys, these are simple one-liners, right?
l = [55,556,5,1,2,9]
l2 = ['a','b','c','d','e','f']
# Problem 1
print reduce(lambda x, y: x+y, [k for k in l])
# Problem 2
print [x for y in zip(l, l2) for x in y]
# Problem 3
print map(lambda n:(lambda q, *a: q(q, *a))(lambda fib, n: n if n < 2 else fib(fib, n-1)+fib(fib, n-2), n), range(10)) # Replace 10 with 100 for first 100 fib elements
# Problem 4
print("".join(list(reversed(sorted([str(s) + "_" for s in l])))).replace("_",""))
# Problem 5
from itertools import product;exec('for ___ in (product(["+", "-", ""], repeat=8)):\n\tif(eval("".join(str(_)+__ for (_,__)in(zip([i for i in range(1,10)],___ + ("",))))) == list((map(lambda x: x**2, [10])))[0]): print( "".join(str(_) + __ for (_, __) in (zip([i for i in range(1,10)], ___ + ("",)))) + " = %d"%(list((map(lambda x: x**2, [10])))[0],))')2
u/load231 May 09 '15
Biggest horseshit I read in a while.
If you ever come across a company where the autor of this is in charge of anything, you better run as fast as you can.
2
u/myxie May 09 '15
1, 2 - easy; 3 - requires more than machine precision; 4 - nastier, can do a constrained search (only consider numbers with a maximal first digit) or a brute force search (all permutations); 5 - brute force, not much point trying to constrain the search
→ More replies (1)
2
May 09 '15
import Data.List (foldl1', sortBy)
-- I'm just going to sum a list 3 different ways
-- since for/while-loop equivalents make no sense here
problem1 :: [Integer] -> Integer
problem1 = foldl1' (+)
problem1' :: [Integer] -> Integer
problem1' = sum
problem1'' :: [Integer] -> Integer
problem1'' = sum'
where sum' :: [Integer] -> Integer
sum' (n:ns) = n + sum' ns
sum' [] = 0
-- One more with tail-recursion
problem1''' :: [Integer] -> Integer
problem1''' = sum' 0
where sum' :: Integer -> [Integer] -> Integer
sum' c (n:ns) = sum' (c+n) ns
sum' c _ = c
problem2 :: [a] -> [a] -> [a]
problem2 = intersperse
where intersperse :: [a] -> [a] -> [a]
intersperse (x:xs) (y:ys) = x : y : intersperse xs ys
intersperse (x:xs) [] = x : intersperse xs []
intersperse [] (y:ys) = y : intersperse [] ys
intersperse [] [] = []
problem3 :: Int -> [Integer]
problem3 n = take n fibs
where fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
problem4 :: [Integer] -> String
problem4 = concatMap show . sortBy (\a b -> let a' = show a
b' = show b
in compare (b' ++ a') (a' ++ b'))
where concatNums :: Integer -> Integer -> Integer
concatNums n m = read $ show n ++ show m
problem5 :: Int -> [Int] -> [String]
problem5 total ns = concatMap (\x -> solve total x (show $ head x))
. flatten $ partitions ns
where partitions :: [a] -> [[[a]]]
partitions [] = [[]]
partitions (x:xs) = [ [x] : part | part <- partitions xs ]
++ [ (x:ys) : yss | (ys:yss) <- partitions xs]
flatten :: [[[Int]]] -> [[Int]]
flatten [] = []
flatten (x:xs) = map (listToNum 0) x : flatten xs
where listToNum c (y:ys) = listToNum (10*c + y) ys
listToNum c _ = c
solve :: Int -> [Int] -> String -> [String]
solve n (x:y:xs) rep = solve n (x + y : xs) (rep ++ " + " ++ show y)
++ solve n (x - y : xs) (rep ++ " - " ++ show y)
solve n (x:_) rep
| n == x = [rep]
| otherwise = []
main = do
putStrLn "Problem 1"
print $ problem1 [1..5]
print $ problem1' [1..5]
print $ problem1'' [1..5]
print $ problem1''' [1..5]
putStrLn ""
putStrLn "Problem 2"
print $ problem2 [1, 3 .. 10] [2, 4 .. 10]
putStrLn ""
putStrLn "Problem 3"
print $ problem3 100
putStrLn ""
putStrLn "Problem 4"
putStrLn $ problem4 [420, 42, 423]
putStrLn $ problem4 [52, 5, 3]
putStrLn ""
putStrLn "Problem 5"
mapM_ putStrLn $ problem5 100 [1..9]2
2
May 10 '15
Ridiculous. The definition of a developer is not someone who can answer your questions. No interview ever is going to be able to measure some skill you can barely define. And someone who is a developer for you possibly won't be a developer to someone else with a different random criteria.
2
u/ConfuciusDev May 10 '15
Your article is condescending and you give no reasoning, not too mention you can't even get all of your solutions right. Find a better way to boast your ego, because posting blog articles, and coming up with interview questions is not your strong point.
6
4
4
May 08 '15
Joel on Software had a nice article about what he looks for in people. Basically it's two things:
Do they get stuff done?
Are they smart enough to work here?
When I interview, that is all I'm looking for. For the most part the resume tells you if they get stuff done but, you need to validate it through some questioning.
For the smart enough part, there are a ton of ways to go about it but, you can usually get it from people without putting the hammer down on them. A couple times I've used the white board with candidates but, nothing like this. I used actual real world problems I had recently come across. Because at the end of the day, anyone can Google a Fibonacci solution. Not everyone can develop a real world system with real world constraints.
And to the OP, I had a person interview me like that once. They were condescending pricks who thew a bunch of these at me. I solved all of them, easily I might add. I then got up, thanked them for their time and walked out. I'm not working for someone who can't look at my body of work, talk to me about the real world algorithms I've created and respect my career enough to this point to understand that I'm a competent developer. It's insulting.
→ More replies (2)
9
u/amateurk-night May 08 '15
Awesome! I'm paid 6 figures to write fibonacci as well! Kudos the OP!
How about this, you ask people who are interviewing for previous projects and open source they've done and stop treating developers like god damn children.
15
u/virnovus May 08 '15
Part of the goal is to weed out bullshit artists, and to see how they think. It hardly even matters if they solve the problem, but watching their approach to problem solving can tell you a lot about someone.
7
u/twistedrapier May 08 '15
Great, until you run into developers who have only worked on closed source projects for work in the past, and can't contribute to open source thanks to work contracts.
→ More replies (1)13
u/coffeesippingbastard May 08 '15
You've never interviewed before then.
Bullshit artists....bullshit artists everywhere.
→ More replies (1)
5
May 08 '15
Write a function that given a list of non negative integers, arranges them such that they form the largest possible number. For example, given [50, 2, 1, 9], the largest formed number is 95021.
Is the solution to this one simply concatenate the numbers in descending order by the first digit (e.g. [9] [5]0 [2] [1]) plus the cases where there are multiple numbers that begin with the same digit, where you would move to the 2nd, 3rd etc digit in that number?
→ More replies (58)
334
u/vital_chaos May 08 '15
Yeah I write Fibonacci sequences all the time. It's my hobby. /s Why do people think that writing short test functions in an interview has anything to do with actually delivering products? Sure some ditch digger might fail at these, but does it tell you anything about how well they build actual apps?