Live data from Hacker News

The Programming Interview from Hell

pythonforengineers.com

51–60 of 147 posts

Re: The Programming Interview from Hell

#51
post #21

I've called out interviewers for stupid puzzle questions multiple times. Never got the job in any case, but I like to think I improved the hiring process marginally before being rejected.

I've also called out crappy interviews - while in the interview. I went on to be offered the job - but declined.

Re: The Programming Interview from Hell

#52
post #9

OK - but here's a genuine problem that came up the other day in my work (reconciling two datasets - we have various many-to-one mappings of ids that we then want to reconcile against each other). I think it's quite a neat computer science/algorithm challenge, so here goes: Write a function which takes as input a list of sets, many of which are not disjoint, but will output a list of sets where all of the non-disjoint…

Robert Sedgewick's course [1] and associated book/booksite [2] have a good overview of Union-Find problem and various algorithms to solve it.

[1] https://www.coursera.org/learn/algorithms-part1

[2] http://algs4.cs.princeton.edu/15uf/

Re: The Programming Interview from Hell

#53
post #9

OK - but here's a genuine problem that came up the other day in my work (reconciling two datasets - we have various many-to-one mappings of ids that we then want to reconcile against each other). I think it's quite a neat computer science/algorithm challenge, so here goes: Write a function which takes as input a list of sets, many of which are not disjoint, but will output a list of sets where all of the non-disjoint…

Your two examples have the same inputs but different outputs if I am reading this right. What did I miss?

On mobile, the 4th set is hidden until the line is dragged left.

Re: The Programming Interview from Hell

#54
post #9

OK - but here's a genuine problem that came up the other day in my work (reconciling two datasets - we have various many-to-one mappings of ids that we then want to reconcile against each other). I think it's quite a neat computer science/algorithm challenge, so here goes: Write a function which takes as input a list of sets, many of which are not disjoint, but will output a list of sets where all of the non-disjoint…

Your two examples have the same inputs but different outputs if I am reading this right. What did I miss?

[deleted]

Re: The Programming Interview from Hell

#55
post #47
post #37

The hiring manager of a small software company gave me a quick brief before handing me off to his technical heavy. "He's hard to get along with, but he's really smart. Oh, and he has two PhDs. He'll tell you that." I was ushered in. The Guy with Two PhDs (he showed me his business card first, and there were indeed two PhDs on it) asked me: "What is the simplest way to synchronize two threads?" I rattled off some sync…

If someone asks you the "best" way to do something but does not give you context for the problem being solved then the question is stupid. There is no all-purpose "best" way to do anything when it comes to complex systems. You use the "best" way for the problem in hand that may be shared memory, pipes, writing to a file, RPC, etc.

Exactly. When handed an under-specified problem (semantics), hand back a lambda compiled in the target language (syntax). "What do you mean? African or European?"

Re: The Programming Interview from Hell

#56

Earlier quoted context omitted.

Your two examples have the same inputs but different outputs if I am reading this right. What did I miss?

On mobile, the 4th set is hidden until the line is dragged left.

Dang my bad. Thanks for clarifying.

Re: The Programming Interview from Hell

#57
post #20

Earlier quoted context omitted.

You could model the problem as a graph (each integer represents a vertex and two consecutive integers an edge, e.g. (1, 2, 3) is a graph with nodes 1,2,3 and edges between 1 and 2 and 2 and 3). Then your problem is just to find all connected components of the graph ( https://en.wikipedia.org/wiki/Connected_component_(graph_the... .

Yeah but realising that two "nodes" of the graph are connected requires doing a set intersection, which I concluded was quite expensive to do between all possible sets. i.e. building the "graph" was an expensive operation... unless I've misunderstood you.

You build from the different tuples in your list just one graph. Then it's just a simple DFS/BFS with one random start node. Which gives you your first component. Then you can get the second if you start at a node which is not in the previous component until you visited all nodes. This should all be in O(n).

Re: The Programming Interview from Hell

#58

Thats hilarious. I was once interviewing for a C++ position and the interviewer presented me with some C code with a broken "swap" implementation and a driver function and asked me to fix it. I simply prefixed the call to swap with "std::". He wasn't very happy about it. ;-)

Hired.

Seriously that's the correct answer as far as any productive engineer is concerned right?

Re: The Programming Interview from Hell

#60
post #20

Earlier quoted context omitted.

You could model the problem as a graph (each integer represents a vertex and two consecutive integers an edge, e.g. (1, 2, 3) is a graph with nodes 1,2,3 and edges between 1 and 2 and 2 and 3). Then your problem is just to find all connected components of the graph ( https://en.wikipedia.org/wiki/Connected_component_(graph_the... .

Yeah but realising that two "nodes" of the graph are connected requires doing a set intersection, which I concluded was quite expensive to do between all possible sets. i.e. building the "graph" was an expensive operation... unless I've misunderstood you.

[(1, 2, 3), (2, 4, 5)] would result in a graph like this:

1 - 2 - 3

     \

      4 - 5
Building the (undirected) graph would take linear time, and once it is built, you can do a simple Depth First Search to mark all the connected components.
Post reply on HN