News for hackers. Stuff that matters.
Re:“But didn't you write an embedded OS?” by bluedino on Sunday May 13, 2018 @09:12AM (#17058736)
How’s the old interview question go?

Using the programming language of your choice, sort the strings in this file and remove duplicates. You have 30 minutes.

    sort foo | uniq
Re:“But didn't you write an embedded OS?” by flatline on Sunday May 13, 2018 @09:53AM (#17058885)
I always give props to people who give a solution like this because sometimes that is the right thing to do and it acknowledges that we are dealing with a toy problem with a ready solution. And I think that’s what the interviewer in this post failed to do. But in reality we may have a not-dissimilar problem that doeasnt deal with strings and is just a bit more complicated so you can’t just take a bash command or genetic function off the shelf and have it work. You’re going to have to write some code, it’s going to take a little thought, and your solution can’t be O(n^2) when we throw ten million elements at it.

I’ve worked with engineers who are competent programmers but just can’t handle these problems when they come up in practice. If the job actually requires it, I don’t know of a better way in the context of an interview to determine if a person is that type of programmer than with a few toy problems and a solution in code. You may miss some good people because the format is suboptimal, but you will weed out the people who just don’t have the theoretical and practical background to solve this particular type of problem.

Re:“But didn't you write an embedded OS?” by new299 on Sunday May 13, 2018 @12:18PM (#17059661)
I'm not certain that it's true that you "will weed out the people" who can't solve algorithmic problems. There are a relatively small number of algorithmic problems, that are simplest enough to be asked and solved in an interview context. People now study these types of problems for months when preparing for interviews...

I think there are better ways of doing things than the standard X interviews of 1 hour. One method that works well is hiring people for short term contracts (few days) and seeing how they work with the team on real problems.

Re:“But didn't you write an embedded OS?” by ac2u on Sunday May 13, 2018 @01:03PM (#17059852)
I agree, the interview format isn't sufficient if it's algorithmic trivia.

The parent comment of yours identified the right need for them (a person who can come up with a solution when the time comes in the real world), but the method of toy algorithms means you could end up with the following scenario:

Person A: Spends months drilling solutions on whiteboards to memorize the answer. They pass as they can regurgitate every toy algorithm possible without thinking. They pass the interview.

Person B: doesn't deal well with interview situations and doesn't get the chance to talk in general about how they'd approach it in real life. They freeze up as they're stood up in front of a panel of people holding a whiteboard marker and being stared down. They don't progress in the interview.

Perhaps person B was the person who would sit at their desk for 20 mins in silence and come up with:

"ok if we're not deduping these on the inserts for our system, I guess the least we can be doing is maintaining one of those in-memory bloom filter things, I read about those one time as a good probabilistic data structure, might end up being a part of solution. I'll ask the tech lead if we have any memory constraints as I see that our AWS instances are compute optimised instead of memory optimised, anyway, we might get an off the shelf solution"

Person A: "which question in my 'interviewing for algorithms' text book does this belong to?"

You want Person B, you optimised your interview process for A.

Re:“But didn't you write an embedded OS?” by hn_throwaway_99 on Sunday May 13, 2018 @12:30PM (#17059717)
> One method that works well is hiring people for short term contracts (few days) and seeing how they work with the team on real problems.

The problem is that most really great people, who are in high demand, won't put up with this because they know they can get someone else to hire them with less hassle. Your approach ends up weeding out your best candidates.

Re:“But didn't you write an embedded OS?” by new299 on Sunday May 13, 2018 @11:38PM (#17062495)
Google and Amazon (and I assume Facebook) interviews are already a large and uncompensated investment of time for the interviewee (up to several days). So I don't see it has much different.

I can see that there are scenarios where it might not work, for example if non-competes are in place and the industry is similar. But in most cases I think there's enough flexibility to make it practical.

Re:“But didn't you write an embedded OS?” by bluedino on Sunday May 13, 2018 @01:25PM (#17059945)
I definitely agree.

I've seen the typical examples of ugly code over the years; over-complicated conditions, piles of IF statements, things that should be in a database or associative array, all because the person just couldn't solve the problem in a simple, straight-forward way.

These people get stuck on what should be a simple problem and productivity plummets. If you've spent the whole morning on something, taking it from 5 lines to 105, you're probably attacking the problem from the wrong angle.

Re:“But didn't you write an embedded OS?” by dronescanfly on Monday May 14, 2018 @06:46AM (#17064330)
Definitely can relate to that... One of my colleague is the type of person who somehow forcibly denies doing the most straightforward things/solutions. Every problem is being 'solved' by pulling in yet another library that somehiw touches the problem. Of course it needs it's own layer of abstraction to be swapped out easliy for yet another library im case the first is deprecated.

All that for stuff which can be solved with simple 1-10 lines of code. (not these everlasting functional programming chained to eternity lines. real slim and dumb code)

Re:“But didn't you write an embedded OS?” by emodendroket on Sunday May 13, 2018 @01:08PM (#17059875)
So... we use the SortedSet provided by the library?
Re:“But didn't you write an embedded OS?” by NullPrefix on Sunday May 13, 2018 @09:34AM (#17058816)
Clearly a suboptimal solution. That pipe isn't free. /s

  sort -u foo
Re:“But didn't you write an embedded OS?” by my123 on Sunday May 13, 2018 @09:42AM (#17058847)
Seems to be too little UNIXy. Modern tools sometimes not only do one job. (the z flag might have been kept out of tar too for example) :P
Re:“But didn't you write an embedded OS?” by emilfihlman on Sunday May 13, 2018 @01:56PM (#17060071)
With piping you can leverage multiprocessing for free.

Using sort -u alone might actually not be as fast as sort | uniq -u.

Re:“But didn't you write an embedded OS?” by sireat on Sunday May 13, 2018 @05:43PM (#17061198)
Doesn't have to be Bash either, Python is pretty good for this too:

  sorted(set(foo.strip.split(' ')))  #although we need to open the file first
just to be on the safe side

Perl's not too shabby either for this kind of stuff :)

Re:“But didn't you write an embedded OS?” by viraptor on Sunday May 13, 2018 @09:36AM (#17058824)
If you're using gnu coreutils: sort -u foo.
Re:“But didn't you write an embedded OS?” by amelius on Sunday May 13, 2018 @09:51AM (#17058882)
And what if the strings are separated by spaces instead of newlines?
Re:“But didn't you write an embedded OS?” by flerchin on Sunday May 13, 2018 @10:06AM (#17058951)
sed foo -e 's/ /\n/g' | sort | uniq
Re:“But didn't you write an embedded OS?” by innagadadavida on Sunday May 13, 2018 @01:28PM (#17059961)
If you want to preserve order, this is how you uniq with awk: awk '!x[$0]++'
Re:“But didn't you write an embedded OS?” by amelius on Sunday May 13, 2018 @10:14AM (#17058977)
Yeah, but what if the strings I wanted to sort contain newlines?
Re:“But didn't you write an embedded OS?” by jws on Sunday May 13, 2018 @10:25AM (#17059036)
You (sir|madam), are a feature creep. If it weren’t for people like you and their “real requirements” software would be easy.

By the time you say “unicode” and “collation” the programmer is going to be in serious trouble.

Fortunately the programmer can lawyer the problem. The original requirements don’t specify what the strings are sorted by. I choose “position in original source” file and complete the task with a NOP.

Re:“But didn't you write an embedded OS?” by diegoperini on Sunday May 13, 2018 @11:21AM (#17059352)
echo "Input file already sorted."
Re:“But didn't you write an embedded OS?” by flerchin on Sunday May 13, 2018 @10:21AM (#17059022)
You haven't specified a delimiter.
Re:“But didn't you write an embedded OS?” by stepvhen on Sunday May 13, 2018 @10:59AM (#17059226)
protip:

tr ' ' '\n' < foo | sort | uniq

Re:“But didn't you write an embedded OS?” by emilfihlman on Sunday May 13, 2018 @01:55PM (#17060070)
Broken. uniq alone removes only adjacent duplicates. You need uniq -u to remove all duplicates.
Re:“But didn't you write an embedded OS?” by benchaney on Sunday May 13, 2018 @02:14PM (#17060154)
This is not a concern for already sorted lists.
Re:“But didn't you write an embedded OS?” by JadeNB on Sunday May 13, 2018 @02:30PM (#17060242)
> > sort foo | uniq

> Broken. uniq alone removes only adjacent duplicates. You need uniq -u to remove all duplicates.

As benchaney (https://news.ycombinator.com/item?id=17060154) points out, the duplicates will be adjacent after `sort`.