Live data from Hacker News

Inverting Binary Trees Considered Harmful

jasq.org

11–20 of 225 posts

Re: Inverting Binary Trees Considered Harmful

#11
Yeah I remember the Google interview a few years back. I did it mostly for fun, and because their recruiters kept contacting me.

So there we were, building a tree out of a forest of existing smaller trees or such. That was after they couldn't find my resume, and used a 5 year old one they found some place. They seemed annoyed and tired. By that time I felt nothing short of me proving P!=NP would have help changed their mood. I mean, they didn't even ask me what I knew, what I worked on lately. Heck, I could have been herding goats for the previous 5 years, but if I could have solved that tree problem, well, Googleplex here I come, I could have been herding goats there, maybe as part of some a green eco-initiative project...

I guess half way through I just kind of decided that Google must be a pretty bad place to work at and kind of gave up. I was tempted to ask them how often they had to build the tree out of subtrees at Google. Or in this case how many times did they really have to invert the binary tree, but I am nicer that than, maybe they really did have a pretty shitty day.

Ever since then I've declined to interview at Google. I get contacted every year like clockwork "Wanna try again?", "No thanks, good luck inverting binary trees though..."

Re: Inverting Binary Trees Considered Harmful

#13
post #9

What does it mean to invert a binary tree?

To change the nodes to point the other way around. So if the left edge of N1 points to N2 and the right edge points to N3 you make it so that N1's left edge points to N3 and the right edge points to N2. It's a trivial problem of changing pointers around. It's like 4 or 5 lines of code if you write a recursive function.

Re: Inverting Binary Trees Considered Harmful

#14
This just comes off as a bunch of bragging with the issue in the title sitting in the periphery. Also, people would be well served to realize that companies use these tests as a proxy for intelligence and education. They very much try to avoid making it a trivia contest.

Re: Inverting Binary Trees Considered Harmful

#16

I'm only a rising junior in CS on my second internship and I completely agree. I did really well in my Data Structs & Algorithms class (A+...) and I just hate these types of problems. I bombed Google and Dropbox's interviews, and am ready to never go through another process like that again if I can. I've been exceedingly lucky landing gigs at great companies that don't filter with these questions. I worked for LeadGe…

[deleted]

Re: Inverting Binary Trees Considered Harmful

#17
I enjoy the challenge of programming interviews. When I interviewed in Mountain View, I thought it was just super cool to have been invited. It was like the mother ship had summoned me home!

I was mega-underwhelmed when I botched the last session, though. And after doing so poorly, no one escorted me out or summed things up. Efficient, I suppose -- I'd met with the recruiter at the beginning of the day and there was nothing left to discuss. But there was no denouement. A big build up all day and all of a sudden -- nothing.

That last session I was asked to implement a particular matrix manipulation. IMO a bit more utility than tree inversion. And I tried to talk through my thought process but I'll admit it just wasn't getting there. After it was over, I went back to the hotel, wrote a test case and kept coding until I made it work. I'm a little ashamed to admit that it took 1.5-2hrs to get it to work -- so probably not just intimidation/stage fright. After writing the code, I don't think I understood the design well enough to explain it -- but I did do it on my own w/o any reference. I guess I wasn't surprised when I didn't get an offer.

So I've been contacted again as a part of this latest hiring campaign. I'll give it another try, I suppose. My ego's buoyed by being contacted again and doing well on phone screens, so I suppose I can take another bruising. :)

Re: Inverting Binary Trees Considered Harmful

#19
post #3

>You are then ushered into a room with the programmer's worst nightmare - a blank whiteboard. Am I the only one who enjoys programming interviews? Even if you screw it up, it's still fun to try your hand at whatever problem they give you. They also don't expect you to do it perfectly; you're allowed to have sub-superhuman performance.

I interviewed at Microsoft and it was about 10 hours of this stuff and I loved it. Had a great time, and I think I did pretty well. One guy wanted me to write a shuffling program. So I came up with one which I later discovered was Fisher-Yates and optimal. But he kept saying "how can it be faster" so I'm not sure what I was missing. Most of the other stuff was pretty fun and straightforward - pointer stuff, string copying, synchronization. It felt like if you had gone through Sedgewick's algorithm book you'd be set for the most part.

Unfortunately by 7pm or so I was sorta exhausted (didn't sleep the night before 'cause I was so excited). I met the hiring manager, and he asked something fun like make a ring buffer and also write a non-recursive inorder traversal function of a binary tree. I apparently had some off-by-one bug in the ring buffer code, and then I just blanked out on the traversal question. No hire :\.

(OTOH, that team wasn't sure if they were going to be using VB6, or C++, or maybe .NET, but probably not because they wanted to ship with Office and Office severely limits dependencies. So maybe it was for the better.)

Re: Inverting Binary Trees Considered Harmful

#20
post #8

While I'm completely, 100%, against these kinds of questions, how else can a company that receives thousands of resumes a day filter out the good from bad?

How about sitting the candidate down in front of an actual computer, or ask the candidate to bring in their own laptop? Then if you want to see how they do, pick out some open source projects that need a feature or two added, or a bug fixed, and have the candidate walk through some solution? This way, you are getting to see what their style is, and the random open source projects gets a potential improvement. And you won't get accused of having the candidate programming for you without pay, because contributing to random open source projects is kind of like charity or community volunteer work.

Or, here's a fun project. Have the candidate write up (in the language of their choice, or preferably multiple languages) a program that generates solutions for the Cracker Barrel peg board game (or variations thereof).

Post reply on HN