News for hackers. Stuff that matters.
Re:On Secretly Terrible Engineers by mkozlows on Sunday March 08, 2015 @04:14PM (#9167036)
No, I mean it literally, as in can't do do a loop/if/assignment level operation. ("Write a function that returns the sum of the two largest numbers in an array" is the literal question I would ask that the majority of candidates -- all with years of experience doing software dev -- were unable to answer.)

They simply flat-out could not program. Full stop.

Re:On Secretly Terrible Engineers by FLUX-YOU on Sunday March 08, 2015 @04:31PM (#9167113)
And if I did this in your interview, how would you feel about that?

    List<int> blah = new List<int> { 3, 8, 2, 1, 5, 9, 0, 12, 14 };
    // pretend I don't know the numbers :)

    blah.Sort();
    blah.Reverse();

    return blah[0] + blah[1];
Re:On Secretly Terrible Engineers by mkozlows on Sunday March 08, 2015 @05:21PM (#9167325)
Congratulations, you are now better than 2/3 of applicants I saw.

I'd follow up by asking whether there's another way you could have done this (the obvious loop and store method); if you didn't come up with it, I'd explain it to you, paying attention to how well you seemed to understand it. I'd go on to ask about what characteristics make one of those solutions better than the other, hoping you'll mention the performance characteristics of sort vs. simple iteration, and maybe also the maintainability/extensibility of the two methods.

And then I'd move on to my next question with cautious hope.

Re:On Secretly Terrible Engineers by ryandrake on Sunday March 08, 2015 @07:44PM (#9167909)
2/3 is generous. That implementation probably puts you in the top-90% of candidates that make it to a technical interview.
Re:On Secretly Terrible Engineers by madcaptenor on Monday March 09, 2015 @12:59PM (#9172110)
You mean the top 10%?
Re:On Secretly Terrible Engineers by Luyt on Sunday March 08, 2015 @06:17PM (#9167575)
Another way to do it, assuming that the list can be mutated: find the largest number in the array, store it somewhere and remove it from the list. Do this a second time. Then add those two numbers.

It evades sorting the array, but you have to search it twice.

    a = [7, 9, 2, 8]
    
    highest = max(a)
    a.remove(highest)

    nexthighest = max(a)
    a.remove(nexthighest)

    print highest + nexthighest    
Optimisation: just scan the array once, and keep track of the two highest numbers.

    a = [7, 9, 2, 8]

    highest = None
    nexthighest = None

    for item in a:
        if not highest or item > highest:
            highest = item
        elif not nexthighest or item > nexthighest:
            nexthighest = item

    print highest + nexthighest
Re:On Secretly Terrible Engineers by mden on Sunday March 08, 2015 @06:56PM (#9167748)
Fyi, there's a mistake in your second solution - consider a strictly increasing list.
Re:On Secretly Terrible Engineers by Luyt on Sunday March 08, 2015 @07:23PM (#9167842)
Thanks for the tip!

    a = [2, 7, 8, 9]

    highest = nexthighest = None

    for item in a:
        if not highest:
            highest = item
        elif item > highest:
            nexthighest = highest    
            highest = item
        elif not nexthighest:
            nexthighest = item
        elif item > nexthighest:
            nexthighest = item

    print highest + nexthighest
Re:On Secretly Terrible Engineers by FLUX-YOU on Sunday March 08, 2015 @06:36PM (#9167670)
And my beef is with the huge variety of interview techniques (sorry if it felt like I was calling you out there, I wasn't trying to) and that candidates have to prepare for a whole range of them. One answer gets a spectrum of responses and there is rarely any good answers for everyone. (Maybe I'm just stating the obvious here)
Re:On Secretly Terrible Engineers by rakoo on Sunday March 08, 2015 @04:59PM (#9167232)
At least it works. Since you're able to give that in not even a minute, the interviewer has plenty of time to go further:

- Do you see any problem with your method ?

- If yes (you should say yes), how can you improve it ?

In other words: the real point of asking technical questions is not can you code but much more can you engineer a solution to a problem.

Re:On Secretly Terrible Engineers by alkonaut on Sunday March 08, 2015 @04:44PM (#9167162)
As an interviewer, I would have hoped for this:

    int sum = blah.OrderByDescending(x => x).Take(2).Sum();
Re:On Secretly Terrible Engineers by codygman on Sunday March 08, 2015 @05:57PM (#9167472)
Ha, that's basically what I just did with the Haskell version:

   Prelude> import Data.List
   Prelude Data.List> sum . take 2 . reverse . sort $ [1..5]
   9
Re:On Secretly Terrible Engineers by Luyt on Sunday March 08, 2015 @06:56PM (#9167746)
I can do that in Python ;-)

    a = [7, 9, 2, 8] 
    print sum(sorted(a)[-2:])
Re:On Secretly Terrible Engineers by codygman on Sunday March 08, 2015 @07:48PM (#9167932)
Oh cool, slices don't return index errors:

    >>> print sum(sorted([])[-2:])
    0
Re:On Secretly Terrible Engineers by Luyt on Sunday March 08, 2015 @09:01PM (#9168219)
Reading the original problem, "Write a function that returns the sum of the two largest numbers in an array", I took the liberty of assuming that the input list would always contain at least two items.
Re:On Secretly Terrible Engineers by minimaxir on Sunday March 08, 2015 @05:02PM (#9167243)
Clearly your Reverse() is unnecessary and inefficient when you can just do

   return blah[blah.size()-1] + blah[blah.size()-2];
I totally would not hire you. :P