Stupid Interview Questions

   Posted by: amrath    in Technology

Let’s start someting new. I’ll add more as I find more stupidity to complain about, hmm?

The Linked List Interview Question

Stop me if you’ve heard this one before….

The bright eyed, bushy-tailed, academic who is so excited to be working in games asks you what he thinks is a very clever question: “How would you go about finding a loop in a singly linked list of unknown length?”

You think about it a moment, then ask, “Why is there a loop in the list at all? It’s an error condition that should have been caught before it corrupted the list.” He says, “Well, let’s just assume someone did something stupid, and it’s like this now.”

Okay. The most obvious cause of a loop is a double insertion. So we’re going to abandon the best practice of verifying input before working with it? Why would we do that? The point where the node is added is the obvious and optimal place to check. It’s also the point where you can stop the error before it breaks things, where you can actually have some sense of the context of the data. If you find the loop after the fact by analyzing the list without context, how do you repair the list? You can’t be certain what to do with a duplicate node. Do you remove all but the first instance? All but the last? Is order even important? Every ounce of experience tells you to modify the list code to prevent this from happening to begin with, and choose the correct course (ignore the new input, or remove the old one prior to adding) based on the intent of the list.

Hmm, how else could we get a loop? Someone could mod our pointer? C++ has private data members, and this is a classic case where they should be used. No one outside the linked list implementation should have access to these pointers to begin with.

Someone could delete an entry and not remove it from the list? Easily circumvented by overriding delete() for the class in question and doing a check. Again, C++ provides a good solution.

Memory stomp? The memory manager should have a debug mode to detect this and warn of the occurrence.

In all cases, we could and should be solving this problem at a centralized location, and using the facilities the language provides to avoid the situation entirely.

Only that’s not the answer the guy wants. “Let’s just assume you can’t do that.”

You ask why we don’t know the length of the list, since it’s an obvious and trivial thing to add to the implementation? Then you could walk the list and if you exceeded the count, you’d know something was wrong. “Well, never mind that, you just don’t. How would you go about it?”

Context is even more difficult now. Ok, so I am using a linked list that is not only half-assed and lacks the capabilities of a list in the STL, but also that I somehow I don’t have access to the source to fix it properly. Why would that be? Well, maybe it’s a library. But why am I using a broken library? Why don’t I replace it with my own code? It wouldn’t take very long to write a more robust system that would eliminate this situation and handle it properly.

Again, “Let’s just assume you can’t do that.”

Jeez, Louise, so I have to assume I suck as a programmer to answer the question? Why do you want to know how a sucky programmer would solve this problem? How can I think like a sucky programmer unless I am a sucky programmer? If you know C++, you know full well that there really isn’t such a programming situation. The entire point of C++ is modularity. Don’t like printf()’s default behavior? Override it with your own version. I really can’t think of a situation where this would be a problem. My feet are no longer in contact with the earth in regard to this question.

Okay, okay, let’s assume the code was written by the CEO, and he’s a crazy jealous guy who will fire me if I mod even one character of his precious code, or even have the temerity to suggest that his code is anything but absolutely perfect. Ignoring the obvious solution of refusing to work for such a person (“Let’s say the CEO has a gun….”), well then….

We could record all of the pointers and see if any of them matched. It’s expensive, though. It’s a bad solution.

He doesn’t really care that it’s a bad solution, just that it’s not the one he has in mind. “Let’s say you don’t have the memory for that.”

Hmm. *Scratches head.* Ok, if we’re on a modern system, and we’re behaving in a mostly sane manner, we’re dealing with aligned pointers. I could set bit 0 of each node pointer as I pass, and then if I come across one with the bit set, I would know  had a loop. Of course, I’d have to reset them after the fact, and it could be bad in a multithread environment if someone else was meddling with the list. We wouldn’t want to lock other threads out for that long, either. So it’s a bad solution, too.

Same deal, doesn’t really care about the ‘bad’ part, only that it’s not the clever answer he has in mind. “Well, let’s say this list is in ROM.”

At this point, I have no answer but the one no programmer should fear, but too many do: “I don’t know.” And junior programmer smiles patronizingly, certain that I know fuck all about anything. He concludes this not because I don’t understand programing, but because he has read or heard something he thought was clever, and I have not. But in point of fact, it’s not even clever.

The answer he wants, which anyone could find in less than 30 seconds searching google, is simple. You iterate the list with two pointers, one going one at a time, one going two at a time, and if the pointers are ever the same, then you have a loop. But it’s a useless solution. Once you detect the loop, you still don’t really know how to fix the problem, in that you have no context. The best you can do is hope that it was caused by a double insertion, and pick a node at random to preserve, or scissor it out entirely and hope for the best. If it was a double insertion, either choice is a hail Mary and hope for rain. If it was a memory stomp or someone meddling with the pointers, you’re just outright screwed. It is a fact that an error discovered in a linked list is a catastrophic failure that can’t be solved without context. Any solution that works is blind luck, not proper engineering, and is a bug waiting to happen because it relies on undocumented, perhaps unknown behavior.

In addition, it’s a more laborious process than having checked the input when the node was added.

But this was the clever answer he wanted, and no other solution counted, even if it was superior.

The academic will justify this scenario by saying it tells him how you think about things. But does it? I suppose it says something, in that it tells him whether you simply accept a problem at face value and plod away at it, or whether you actually try to dig deeper, find the root cause of the problem, and solve it correctly.

This question, like many others one runs across, says more about the questioner than the questioned. It says the questioner doesn’t think deeply about how his system interacts with others, and that his designs, while perhaps clever in their own right, may be completely wrong for the priorities at hand.

One comment


My answer would have been “HADOoOoOoKEN!!!”

July 21st, 2009 at 2:30 pm

I am so almost done with the third and final synopsis, and having the rest of the plotline locked in stone. From there, chapters can proceeed very quickly, one per day if I actually work on them. More likely, one per week, since I need to write other stuff like CODE in order to keep body and soul together. And then there is Chunk in the mix. Well, ok, and World of Warcraft. I have to be honest, eh? (chuckle)

Speaking of Chunk, he and I recently saw a zombie trying to break down our front door, but I dispatched him quickly with my trusty shotgun. Jess was kind enough to capture the moment on film. No, not of the zombie, of us!





Well, little Matt is getting bigger and bigger. I call him Chunk, a little ironic reference to how small he was when we brought him home in February. I can hardly believe he’s the same baby, both in terms of size and his interaction with the world. He seems more alive every day, more aware of his surroundings, and more cantankerous about having his way.
Of late, he has decided that the hours between 1am and 5 am are prime time, and becomes very angry that the rest of us are not available for his amusement. A few nights ago, he was putting up quite a fuss, a real tantrum, kicking, howling, waving his fists, pulling the hair on my chest. I thought to myself, “Man, he must be in pain, I hope he is not sick!” I turn on the light to check him, and the Chunk is instantly happy and quiet, looking up at me with great interest.
So he is already quite willful. I am pleased. But he must also know his limitations. (chuckle)
Some people asked for pics.  Here are some I took yesterday, starting with him in his, hmm, I dunno what it’s called, but it’s a bit like a recliner with a seatbelt. He is not pleased!
Chunk becomes enraged!

Chunk becomes enraged!

Chunk is briefly mollified by attention

Chunk is briefly mollified by attention

Chunk does not understand bright light!

Chunk does not understand bright light!

Chunk does not like bright light!

Chunk does not like bright light!

Chunk will crush!

Chunk will crush!

They will be coming up all day, but here’s the first one I found, and it gave me quite a laugh.

Google seems to have a new and interesting feature.


Online Seller’s Rules

   Posted by: amrath    in Dark Mutterings


Why do we need rules? Why can’t we just act sensibly and make a deal, exchange a few bucks for some used stuff, and both be happy? In the world of online bartering and person to person sales, there are way too many people who simply don’t have common sense or courtesy: crooks who try to con you, chiselers who want something for nothing, and outright morons who apparently cannot distinguish between a Neiman Marcus Showroom and my humble abode and get bent out of shape when they don’t get Neiman Marcus levels of service.

So, to save time. and so that I am not forced to injure my hand by pounding it against someone’s thick skull, I have created these rules. Please refer to them when you are seized by idiot notions. It will save me the trouble of having to choke sense into you. I will make it simple, and use lots of examples and colorful language, so you can understand. Ok?

And if you are a seller, please, by all means, link this page in your posts. It will probably save you some trouble.

The Rules:

1. I do not need your money. I don’t want to get ripped off, and it’s nice to get a little something for my stuff, but the truth is that I could set it all on fire and not lose any sleep over it. It would be out of my way, which is my primary goal. The hassle you present is being weighed against simply having the garbage collectors take it away in one of my several free ‘bulky pickups’ they offer me throughout the year. If you offer me five bucks for a piece of furniture that I only asked 25 for to begin with, it is a bad deal for me. I could use it for firewood and come out better. Don’t be silly.

2. I will not bring the item to you for inspection. I will not be taking your cashiers check. I will not be taking your personal check. I will not be mailing the item. You will bring your ass to my house and pay me in cash. It’s that simple.

3. This is not a showroom, and I am not getting a commission. My dinner is getting cold while you agonize over a minor defect in a cheap piece of used furniture. I will not stand overlong in the cold or heat pretending to enjoy your asinine company while you catalog every flaw on an item we both know isn’t really suitable to display your collection of Ming Dynasty Vases. It’s a cheap table, ferfuxsake! Take it or leave it, or make a reasonable offer and have the cash in hand. Your twenty bucks does not buy you much more than five minutes of my valuable personal time, even less if you are annoying.

4. I will not answer your twenty-question email that accompanies your offer of half my asking price. You haven’t even seen the item yet, and you are not even standing in front of me with your chiseling half-off offer, yet you actually expect me to take you seriously? Your mail went straight into the trash, unless I found it amusing enough to forward copies to my friends for laughs at your expense.

5. No, I will not give it to you for half my asking price. I picked that price for a reason. It’s pretty much break even with me versus donating the item and claiming the deduction on my taxes. If you can’t afford 25 bucks, then you can’t afford the gas to drive over and pick it up anyway.

6. I will NOT be lifting the couch and hauling it about, turning it this way and that for you to inspect, most especially if it is over ninety degrees outside. I don’t care if you’re worried about there being a tear on the underside. Surely you’ll see that when we load it, and we could cross that bridge if and when we come to it. I’m not going to bust my ass when you’re not even committed to taking it off my hands.

7. You came to buy a table. Making inappropriate comments about my wife and how saucy she sounded on the phone puts you very close to being in the hospital or the morgue, and very far from any sort of good bargaining position. Yeah, pal, special price for you: $100.

8. It’s a cheap TV stand, ferfuxsake! I don’t know where it came from! I can barely remember my ex-wife’s middle name, much less where she bought the damned thing.

9. Yes, I am probably willing to shave my price a little, but that involves you making it easier, not harder. If you show up, don’t waste my time or ask me to do a bunch of crap, and offer me $40 on my $50 item, I will likely accept. If you have me measure every dimension, recite everything I know about the history of the item, take multiple extra pictures, and reschedule your visit five times, and then offer me 25 for the same item, I will not only tell you to fuck off, I am likely to put my foot in your ass. My time is just as valuable as yours. If you take a lot of my time, you have essentially used up any bargaining room, so don’t push it.

10. This is the big one, the golden rule, the summation of all others, the alpha and the omega of rules: you may be bargain hunting, but you are also a guest in my home. If you don’t behave as such, I will kick your ass to the curb in short order. You may think you’re a special snowflake, or that you have some mesmeric power, but you’re not, and you don’t. I have been buying and selling stuff on craigslist for a long time. In a day or so, someone will come by, be respectful, quick, and offer me 80% or more of my asking price. They will get a great deal, and we will both be happy. You know where the door is. Don’t let it hit you in the ass on your way out.

One comment


This is what happens when people have too much time on their hands. That being said, OMG THANK YOU SO MUCH THIS IS AWESOME!!! Now go finish your book!

March 17th, 2009 at 4:06 pm

Matthew Robert Lewis Gilbert was born today at 15:03 pst. He is a bit early, and it came as a surprise to us, so now we have to scramble to get things in order, but he is healthy and whole. Jess and I are both exhausted, but a night’s sleep should work wonders. Would that I had it in me to put down some moving words right now, but I am tired to the bone. Soon, I promise, I’ll get to that.



2 comments so far


A king is born, and a 1,000 year reign of terror begins…

February 27th, 2009 at 8:54 am

*chuckle* I would prefer him be a hero, but if he does turn out to be a villain, I should prefer he be fearsome indeed, a destroyer of worlds rather than a petty thief.

February 27th, 2009 at 11:22 am

Posting from my G1. Can’t say I anticipated that when I bought it, but it works. He’s coming early, about three weeks. All seems well, even so. He should be here soon now. I’ll post a pic as soon as I have one.


Honesty, Act III

   Posted by: amrath    in Current Projects

Man, I am having a really hard time, here. I am right at the end, and I just can’t bring it together. I have been stalled for quite some time, like a month.  I need to sit down and do some serious rethinking about the finale, only I have had many other things on my radar during the holidays.

This is the freakin hard part. I can write the actual chapters anytime once this is done. I do a few pages a day, following this skeleton, and I can easily get a chapter or two a week in my spare time. But I need this skeleton finished.

I know why I stall. It’s because I have gone off track. I have made characters do things they don’t want to do, or not allowed them to do what they must. If I force them, I lose the feel of them, and they stop talking to me, or rather, maybe I am just not listening. Whatever the case, if I can’t feel and hear them, I can’t channel them, and I don’t know what to do. So I don’t do anything.

There is nothing I can do but fix it. I just need to actually do it. Sometime this week, I swear, I will back out the bad shit and make it right. I’d really like to move forward here. It’s just that life keeps me busy.

I’ve been neglectful of this place for a bit, for lots of different reasons, but it’s time to get started here again. It’s been terribly busy of late, in a good way, with family visiting over the holidays. To make a long story short, too much food was eaten, far too much booze was consumed, and I have probably gained ten pounds. Ouch! Time to get back on the straight and narrow.

Three months now until the baby is born. We have tentatively named him Robert Matthew, though we’re still flexible. I found it amusing that Jess’s Grandma Nellie included a present addressed to him at Christmas, a small outfit that he will presumably wear shortly after he officially exists. I did, however, find it passing strange that one might receive gifts prior to officially existing, but that’s just how my head works: you do not exist, therefore, you do not receive a gift. I suppose, in truth, he is in a strange, proto-state somewhere between existence and non-existence currently.  Certainly, the IRS does not consider him real, this despite the large protuberance from Jess that is definitely not a tumor.

More to come soon.

One comment


You give the gift AFTER he’s born, silly. Of course you can’t give something to someone that doesn’t exist yet. 🙂

January 9th, 2009 at 12:02 pm

As is usual this time of year, there will be a Halloween Hootenanny at my place, and pretty much anyone is welcome to attend.

Page 10 of 13« First...89101112...Last »