
Data Structures Reference - typpo
https://www.interviewcake.com/data-structures-reference
======
kylnew
I recently got double slammed with 2 graph questions during an interview after
having navigated for years without getting a graph question. It's wholly
irrelevant to my day-to-day work but I do hobby game development sometimes
which involves more needs for graphing. Still, I can't do much of anything
with a graph on a whiteboard. Puzzled as to why it's so important to some
companies to grill on this stuff, expecting it to be top-of-mind, even for
front end roles.

~~~
jumper_F00BA2
When faced with questions that have answers I could obviously discern by
writing and running two lines of code, I willfully shrug, answer by intuition,
hoping that's the trap for the wrong answer, and wait for a facial expression.

Today I was asked a question about inheritance and references within a
constructor, in which the answer was an either/or for the parent or child
class.

I threw up my hands and deliberately said " _I dunno parent, no wait! Child!_
" because honestly who cares, when you can figure something like that out
without even googling for it.

A question like that is like asking someone what might they expect a _Hello
World!_ program to print.

Waste my time, and I waste yours right back. I could care less what you think
about me.

~~~
throwawaymath
I don't really agree with these kinds of questions, but to be honest I find
your response to be pretty childish. In my opinion it would be better to be
honest and say you don't really know, but that you believe you could quickly
find out. But your response indicates that you have the potential to be
passive aggressive and uncooperative when presented with a question you
disagree with.

Now from the interviewer's perspective, they don't know you're absolutely fed
up with the culture of tech interviews. They can't see the full interiority of
your thoughts. So they can't know why you're reacting like this, all they can
see is your behavior. Keep in mind that you're most likely punishing an
interviewer who has either been given a mandate for these questions or who
doesn't know any better. From your perspective this could be a teachable
moment or a way to showcase your thinking.

Even though that might have been a poor question to ask, doing what you did
doesn't demonstrate that your time is important. It demonstrates you might
have problems being professional and communicating effectively. It signals
that you _think_ your time is so important that you're willing to potentially
burn an interview to spite someone asking you a question you feel is beneath
you.

It's not a good look. Don't give people reasons to write you off.

~~~
jumper_F00BA2
Sympathy for the interviewer. Well guess what, you're not going to find much
luck pulling this yarn.

Some interviewers get the fist. And that's just the way it goes.

If I'm supposed to play toady to this dog and pony show we're trying put on
together, don't step in front of me with some condescending question, that we
both know is cherry-picked trivia. You design questions to stump people, knock
them off balance, introduce a choke, and project a facade of superiority, when
we both know that's not fair play, and you expect something other than
contempt?

I'm not reciting all the state capitals, every U.S. holiday on the calendar,
and every county in the state of California for you. Try your luck with the
next applicant.

You can't expect me to roll over as subordinate, when I'm looking right at
you, and you and I both know that the canned question you just asked is total
bullshit. Sorry, now I know you're a follower, not a leader, and I won't be
led by you. Interview over.

And besides, do you really believe that passive aggression, as a personality
trait, isn't a possibility, simply because it wasn't on display during that
particular interview. Most smart people _do_ have a passive aggressive mean
streak, because it's a tactic, not a personality trait. It's in everyone's
tool kit, and smart people use it in anger. If it gets used on you, especially
when everyone in the room was trying to make a good first impression, maybe
you did something to provoke that.

~~~
throwawaymath
So I can tell you're pretty upset about being treated this way, and I can
sympathize with the frustration. But maybe my point will be better received if
I clarify it to make it more concise. In essence:

1\. You are responding to these kinds of interviews as though the interviewers
are malicious, self-aware of their biases and intentionally trying to
personally offend you. But it's not personal and not all interviewers are
trying to conspire like this. Consider that what you're feeling and perceiving
may not be intended by the interviewers.

2\. As a corollary, your relationship and responses to these interviewers are
retributional and deconstructive instead of educational and constructive.
You're writing off companies because their interviewers offend your
sensibilities. But just as interviewers don't have enough information to know
why you're reacting the way you are, you don't know if they're trying to be as
demeaning as you feel they're being.

In other words, not all companies with suboptimal interviewing methods are
shitty companies. Probably most are not! Given that, the way you're reacting
isn't just a sensitivity to personal offense, it's _getting in your own way
professionally._

~~~
enterogative
It's on the person holding all the cards to display their power judiciously.
Something designed to provoke undue stress is either glib or provocative, by
default.

Don't forget, in this card game, you may be the dealer and the asymetric
equation may be tipped in your favor, but play fair or some of the players
might surprise you by throwing the game.

As "The Boss" you better not only know more, but also consider how put that on
display. If you're actually in possession of gifted, multi-faceted
intelligence, you won't need to read minds, so much as place yourselves in the
shoes of the candidate, as you probe for awareness of facts, and exposure to
subject matter.

It's often enough, to understand the conceptual interplay of known processes,
before worrying about which color Teletubbie was the "funny" one.

------
gameguy43
Founder of Interview Cake here. Thanks for the post!

Down to chat about coding interviews and answer questions here!

~~~
hmottestad
Hi. I got an interview question a little while ago that the interviewer said
“was not a datasteuctures/algorithm question” because it was too specific. I
call bullshit, but I don’t actually know what the algorithm would be called.

Problem:

A tree of resources that you can get granted access rights to. When you get
access to a node in the tree, you inherit rights to children transitivley. You
can also have rights explicitly blocked. The ordering is important. An
example, you start of as head of IT and have all the IT stuff granted, but
explicitly no access to the IT security department. Then you make CEO and are
granted right to everything, so that should overrule your previous restriction
for the IT security department.

~~~
gameguy43
Hmmm. Can't get in your interviewer's head, but here's my guess: this might be
one of those questions where the bulk of the discussion is supposed to be
about weighing tradeoffs of different choices for the data model.

For example: how do you store the explicit blocks? More specifically, how do
you articulate that head of IT is blocked from this subtree, but the CEO
isn't? Some options:

\- store the block as pairwise (individual, subtree)

\- same idea, but instead of blocks you store explicit /allowances/ (and allow
a tree node to have a flag set of "ignore the tree-based permission system
here, and just lock everyone out who doesn't have an explicit permission")

\- instead of blocking individuals, you could add an abstraction layer, e.g.
user_groups, and assign permissions to /groups/.. You could also add an
abstraction layer on top of the treenodes themselves
(object_permission_groups?). Different tradeoffs with these options.

Again, hard to know exactly where your interviewer was trying to steer the
conversation. But that'd be my guess!

~~~
philipov
The more I think about it, the less I understand why you'd ever need to
explicitly block permissions. Permission groups are a good idea, but since the
interviewer said it's not a data structure or algorithm question, I think it's
trying to elicit problem analysis from the interviewee. What are the use-cases
for blocking permissions? Why can't you just refactor the tree so that all
assignments are allow? Using a mix of allow and deny is convoluted.

It seems like a trick question designed to see if the candidate is willing to
question assumptions.

~~~
resonantjacket5
It seems pretty similar to how aws access controls work. By default everything
is disallowed. Then you can gain more permissions explicitly. But an explicity
deny overrides all explicit allows

------
deckarep
“Hashtable: like an array but instead of an index you can set arbitrary keys
for each value.”

This sounds like a gross over simplification of what a Hashtable really is
underneath the covers.

Any candidate that shows up with that definition better be ready to dive in on
what it really is and when you’d want to use it.

~~~
cup-of-tea
That doesn't even describe a hash table, it describes an associative array, or
map. A hash table as one way to implement that, the other main one being self-
balancing binary trees.

~~~
ummonk
Or more broadly, self-balancing trees (the best performing balanced tree, the
B-tree, is not generally a binary tree). And then there is the skip list.

~~~
cup-of-tea
Yes, quite right. Is a B-tree worth it when the structure is fully in memory,
though? I would say that when talking about maps people are thinking of in
memory structures.

~~~
ummonk
It absolutely is! You get significantly better cache utilization with a
B-tree.

------
A_Person
It just amazes me that employers ask complicated CS-type questions for
ordinary programming jobs. I've been out of the game for 20 years, and only
did a few interviews anyway (as the interviewer), so what would I know! But
FWIW, here's the kind of question I'd ask.

"I'm going to write a few lines of code on the whiteboard, tell me what you
think of them." The code would be something like this:

    
    
      If f(a,b) then
        X=6
      Elseif flag1 then
        X=8
      Endif
    

My bet is, people would fall into one of three camps.

(1) The Bemused :-)

These people would have no idea what to say. That would be fine for a new
developer, I'd just prod them in the right direction. For example, "what do
you think about inline constants?" But if an experienced developer had nothing
to say about that code, that would be a big red flag for me.

(2) The Defiant!

These folk would say, "Gee that looks like very old code, I'm really more
interested in functional languages, do you guys do any Haskell?" This would
also be a big red flag. First, he's saying that he has no interest in my
priorities as the interviewer, he'll just ignore my questions and substitute
his own. Second, he shows that he's _not_ really interested in code _as such_.
It's like a guy who says he likes cars, you take him around the corner and
show him your one-off Porsche EVO hybrid, and he says "Wow, an infinity pool!
What did that cost?" Fail.

(3) What I'd Expect

Here's what I'd expect from an experienced developer, off the top of his/her
head:

"Ok, I see in-line constants, and short variable and function names. Those are
often undesirable, I can talk about that more if you like.

But the more interesting thing, is that X is only set if one of the two
conditions is true. If neither condition is true, X does not get set to
anything.

That might be a bug: the programmer meant to initialise X before the first
test, but forgot. Or perhaps X is initialised much higher up. But if that was
the case, I'd like to refactor the code to bring that initialisation closer to
the code on the whiteboard; and/or rename X to something less likely to be
used by mistake in the middle; or at least, add a comment saying "X
initialised above". Or you could just add an else branch to the code on the
whiteboard, to ensure that X gets set even when both conditions are false.

Another slight possibility is that when the first condition is false, the
second condition is necessarily true, and the developer has written in the
second condition as a form of comment. But in that case, I'd rather make it
more explicit, by changing "Elseif flag1 then", to "Else /* flag1 must be true
*/"; or even asserting that, just to be sure.

Also, if the code in question is really complex, or just messy from years of
maintenance, there might still be cases where X does not get set at all. In
that case you could initialise it to an impossible value, say NULL, right at
the start, then assert not null at the end. Or you could even re-write the
code in truth table style, which I can talk about more if you'd like."

Me: "The truth table approach sounds good. How would you do that? What kind of
data structures would you use?"

And so on.

Does everyone really use CS-type questions these days? Does anyone take the
different approach displayed above?

~~~
clarry
I have to agree with Veedrac and idontpost.

My first thought is, "This looks like a snippet of code completely made up or
taken out of context and then anonymized by renaming variables. I have no idea
what it's supposed to do, I have no idea why I'm looking at it, and I have no
fucking idea what the interviewer wants form me, and I don't play guess-the-
rules type of games." If this were real code, I'd have context. Not just a
snippet. I'd see the things I don't see in the snippet, and I'd know why I'm
looking at it and what I'm looking for. In real work, there is always a
motivation for everything you do. In this case, there is none. You might as
well show a sequence of bits. "What do you think of these bits?"

So by your prejudice, you'd probably categorize me in the first camp.
Congrats, you probably turned down someone who's been coding for 20 years.
Then again, if this really is the kind of line of business code you regularly
deal with, maybe it's for the (my) best.

This is a pattern I see all the time. Interviewers come up with their games
with their arbitrary rules and a bunch of prejudice about how a good or bad
candidate should react. They think they came up with something clever, they
always do. They have no idea.

I get the impression that good people get regularly turned down because they
didn't guess the rules of the game right, or they don't even play because they
got an offer at some place that doesn't play these silly games. Then there is
so much complaining about talent shortage, and complaining about terrible
interview practices, and complaining about having to deal with a stack of 1000
job applications.

~~~
A_Person
I'm truly bemused by your response.

First, if you truly believe that the code I showed is "a snippet of code
completely made up or taken out of context and then anonymized by renaming
variables", I can only say that I don't believe you've ever worked on large
codebases. There are millions of lines of code, in hundreds of thousands of
application, in dozens of different languages, all over the world, precisely
like the snipped I showed. If you've been coding for 20 years, as you say you
have, and haven't seen snippets like that on a thousand occasions, you must
have worked in very strange environments. If you really want me to, I'll spend
5 minutes and give you multiple links to exactly similar snippets in various
large open source projects.

Second, I'm mystified by your comments regarding my trivially simple code
question. that "Interviewers come up with their games with their arbitrary
rules and a bunch of prejudice about how a good or bad candidate should
react".

Wut? Let's make the question even simpler:

    
    
        X := Y / Z
    

Would you not expect an applicant to say, "What if Z is zero?" ? Would you
actually expect the candidate to say - quoting you:

"This looks like a snippet of code completely made up or taken out of context
and then anonymized by renaming variables. I have no idea what it's supposed
to do, I have no idea why I'm looking at it, and I have no fucking idea what
you want from me, and I don't play guess-the-rules type of games."

Are you seriously telling me that you'd hire a candidate who said that? Over
one who said, "What if Z is zero?" ?

I think one of us is missing something...

~~~
clarry
Once again you posted a snippet without context or meaning. Once again it's
like "what do you think of these bits?" Except that you didn't even ask a
question. You just posted something that is presumably code.

So it's hard to engage meaningfully. Give me motivation. Tell me what I'm
doing or why I'm looking at this code in the first place. Show me the context
and maybe I will see whether I should care about Z possibly being zero or not.
Tell me what the language is or how it handles divide by zero (does it have
exceptions?) and I might figure out that we don't give a fuck about divide by
zero because it's handled elsewhere or not at all relevant to this snippet. I
regularly write divisions without zero check because I know the divisor is a
positive compile time constant. Here, I just see a snippet out of context;
again my thought is "what the hell does this guy want from me?" Show me real
code with real context and a real purpose so we can talk real talk.

What's wrong with my x /= z;? Nothing, it's doing the perspective divide just
right. And you don't go about checking for divide by zero because I've already
clipped my primitives. There's nothing wrong with the names either.

Sure the snippet you posted could be a snippet from some real codebase but
without context it is nothing. What do you think of
100101010100000100010001000110? Sorry, wrong answer! Next guy please. That's
also real binary from a real file and it's easy to figure out what it says but
hard to say what I want from you. Try it!

> I can only say that I don't believe you've ever worked on large codebases.

I don't suppose the operating systems and web browsers I've worked on are the
largest of them all but damn. You can keep your religion though.

~~~
A_Person
> it's hard to engage meaningfully

There we agree!

------
BerislavLopac
Well, both types of trees mentioned in the article are just subtypes of graph,
which has numerous other subtypes.

I love this sentence from the technical docs of the NetworkX library, for pure
surrealism: A lobster is a tree that reduces to a caterpillar when pruning all
leaves.

~~~
oreganoz
By that logic, lists are just trees with one child per node. Except graphs are
just 2d lists if you define them via an adjacency matrix. So we've come full
circle.

But we both know they are not very much alike in practice.

------
rs86
This could benefit greatly from specifying what operations are available for
each structure.

------
emersion
Damn. Too many javascripts on this page, including Facebook's. I guess I'll
pass.

------
newscracker
Off topic. I really got turned off by the "me@gmail.com" placeholder in the
signup form at the bottom of the page. So I decided not to sign up.

Email != Gmail. It's one of the last decentralized systems holding up. Please
don't stick one more dagger into it.

------
philphil
Good one but this is even more comprehensive:
[https://news.ycombinator.com/item?id=17427190](https://news.ycombinator.com/item?id=17427190)

