Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
It's funny.  Laugh.

Tech-Interview Riddles 843

An anonymous submitter writes "A computer engineering student at UC Berkeley has made a comprehensive archive of riddles from technical interviews. Very challenging and loads of fun. Also useful for interview preparation."
This discussion has been archived. No new comments can be posted.

Tech-Interview Riddles

Comments Filter:
  • more info... (Score:5, Informative)

    by onby2000 ( 593621 ) on Tuesday July 23, 2002 @11:53PM (#3942227)
    for more tech interview questions and answers try http://www.techinterview.org/ [techinterview.org]
  • by Derleth ( 197102 ) <<chbarts> <at> <gmail.com>> on Wednesday July 24, 2002 @12:23AM (#3942347) Homepage
    January 1, 1970 0000 GMT is the standard *nix epoch, so the clock must have been set to zero at the time it spat up that little gem.
  • by Anonymous Coward on Wednesday July 24, 2002 @12:26AM (#3942357)
    Here's the answer that immediately popped into mind for me...I'm too lazy to make sure that it actually works :)

    unsigned triple_protect(unsigned a, unsigned b, unsigned c)
    {
    unsigned tmp1, tmp2, tmp3;

    tmp1 = a & b;
    tmp2 = b & c;
    tmp3 = a & c;
    return (tmp1 | tmp2 | tmp3);
    }
  • google cache.. (Score:2, Informative)

    by neo8750 ( 566137 ) <zepski.zepski@net> on Wednesday July 24, 2002 @12:36AM (#3942408) Homepage
    here ya go

    Google Cahce is Ace [216.239.51.100]

  • by Turing Machine ( 144300 ) on Wednesday July 24, 2002 @01:29AM (#3942600)
    The "official" answer (which Microsoft was still using as recently as a couple of years ago, according to some friends of mine who interviewed there) is so the covers won't fall through the hole.

    This answer fails on at least two levels:

    1) There are plenty of manhole covers (or manhole-cover-like-objects) that aren't round. If you've been observant enough to notice this, you fail.

    2) There are plenty of other curves of constant width; an infinite number, in fact. The old Wankel rotary engine used such a shape. Though a circle is the only curve of constant *radius*, that's not the issue. If you know enough math to realize this, you fail.

    Another possible answer is that it makes it easier to roll a heavy cover out of the way. Again, one of the other curves of constant width would do just about as well.

    The REAL answer is that no one knows.

    Personally, I think Microsoft would be better off asking people why using fixed-sized buffers for user input is a bad idea, but hey.....
  • by Latent IT ( 121513 ) on Wednesday July 24, 2002 @02:32AM (#3942783)
    Well, crikey. But ask yourself this - if not round, well, what?

    Okay, so you're a guy, and you have to put a hole in the street, and put a cover on it. What shape do you make it? Triangular? Well, uh, why? It's pointy, and can fall through the hole. So you wouldn't do that. Square? Well, you really can't roll it, and TRUCKS have to drive over it, so it'll be heavy, so you'd *want* to roll it, rather than heft it.

    Hey, circles can roll.

    Oh, yeah. And that crap about a Wankel. Why would you want to fiddle around in traffic trying to get it to be oriented properly when a circle HAS a constant radius, as you point out? You can thump it down any old way. Fits!

    So, answer: Because it's just better than any other shape.
  • by SlugLord ( 130081 ) on Wednesday July 24, 2002 @02:32AM (#3942784)
    Some answers from the hard section:

    Criminal cupbearers:
    Let's assume we only have 10 prisoners and that they each drink from up to 512 bottles. Number the bottles from 0 to 999. Prisoner 9 samples 0 to 511. Prisoner 8 samples 0 to 255 and 512 to 999. Prisoner 7 samples 0 to 127, 256 to 383, 512 to 639, etc. (prisoners alternating between sampling and not sampling blocks of wine in decreasing powers of 2 -- prisoner 0 drinks from every other bottle) Now line up the prisoners after onen month and treat corpses as ones and living prisoners as zeros and you have your answer in binary.

    Mysterious Triangle area
    Well, to make a long story short, they're not triangles.

    100 Prisoners and a Lightbulb
    Well if we assume they can all see the bulb every day, they can just toggle the bulb iff this is the first time they've been selected. If the last prisoner has counted the number of times the bulb has been toggled, he can assert that he is the last one to be selected.

    Square Formation
    Move the "notched" piece to teh righth of the current larger square and put the small square piece in the notch. put the larger of the triangular pieces at the top, horizontal edge of the new formation.

    Calendar Cubes
    I like this one. You need all the numbers from 0 through 9 plus 0 through 3. That's 14 faces. You will never need 00 though, so you can remove one of the 0s. Also, you will only ever need the 3 with 0 or 1, so you can remove it from one of the blocks. The solution: the numbers 1-6 on one block, and 7-9 and 0-2 on the other. Yeah it works.

    Mystery Matrix
    4. Entry from row plus Entry from row 2 plus 1 mod 10.

    Fork in the road I
    "is that the city you come from?" If the response is yes, go there, otherwise turn away.

    Fork in the road II
    Assume each person is standing on his respective road. "Is one of you a liar?" Yes means he's a truth teller, no means he's a liar.

    Egg Dropping
    18. Drop from the 10th, 20th, 30th, etc. After it breaks, go back 9 floors and start dropping every floor. You use 18 drops if it can drop from the 98th or 99th floors.

    Greedy Pirates
    It's not apparent to me that this is the intended answer, but "Throw pirates 3 and 4 overboard and divide up the rest between 1,2, and 5. Pirates 1 and 2 will agree to the largest share, and pirate 5 always has a say after that, since 3 and 4 can't agree to anything, so he's needed for the majority.

    Hmm, well it's getting late so I'll just do one more:
    Card Game
    Bob takes any card over 9. The probability that none will show up is roughly .2 with an average payoff of $5. That means that the probability of getting a face card is .8 with a payoff of 11.5. Using more precise figures, i.e. not .2 and .8, the average payoff is about 10.0857 (706/70)

  • by WilliamWu ( 595491 ) on Wednesday July 24, 2002 @02:45AM (#3942804) Homepage
    hi! thanks for checking out the site. i decided to not post answers because i figured it would take the joy out of doing these riddles; part of that joy is banging on blackboards and repeating to yourself that things are impossible and pulling your hair out. this torture then makes the solution all the more joyful :) if i made the solutions available, i think most people would be tempted to click on the answers after just a few minutes of thought at most, and that would kinda ruin the learning experience.
  • rec.puzzles (Score:3, Informative)

    by valentyn ( 248783 ) on Wednesday July 24, 2002 @02:49AM (#3942815) Homepage
    There are lots of these sorts of puzzle sites. One of the older/more famous is the rec.puzzles archive. Find it at here [rec-puzzles.org].

    Another good resource: the Princeton Mathclub [princeton.edu]

  • Re:Incense riddle (Score:2, Informative)

    by Anonymous Squonk ( 128339 ) on Wednesday July 24, 2002 @03:22AM (#3942877) Journal
    The original riddle comes from a Japanese TV show, and they used a katorisenkou, a mosquito releeant which is shaped like a spiral and burns lying down. But none of you would know what that is, so incense was the closest I could think of to that...
  • by UncleFluffy ( 164860 ) on Wednesday July 24, 2002 @04:50AM (#3943045)
    I only ask one "tech" question when interviewing prospective programmers:

    void echo(void)
    {
    char *s;
    gets(s);
    puts(s);
    }

    What is wrong with this code ?

    The scary thing is, over 50% of the people I ask can't answer it.
  • by po8 ( 187055 ) on Wednesday July 24, 2002 @05:11AM (#3943083)
    You're neither one as 1334 as you think.
    Here's 4 operations:
    return (a ^ b) & c | a & b;
    (Extra parens are for wimps.)

    Show that it can be done in 3 C ops, or
    prove it impossible.
  • Re:Infuriating,,, (Score:2, Informative)

    by nils ( 7142 ) <.ed.eotpit. .ta. .slin.> on Wednesday July 24, 2002 @05:30AM (#3943119)
    willywutang is hanging out on a heavily forested island that's really narrow: it's a narrow strip of land that's ten miles long. let's label one end of the strip A, and the other end B. a fire has started at A, and the fire is moving toward B at the rate of 1 mph. at the same time, there's a 2 mph wind blowing in the direction from A toward B. what can willywu do to save himself from burning to death?! assume that willywu can't swim and there are no boats, jetcopters, teleportation devices, etc.. (if he does nothing, willywu will be toast after at most 10 hours, since 10 miles / 1 mph = 10 hours)
    It's easy: willywutang grabs a burning log from the fire, runs to let's say the middle of the island, sets fire to the wood there, watches the wood turn into ashes (with the fire moving towards B) and when the fire coming from A would reach him, he can easily retreat to the no longer burning ashes.
  • by rufusdufus ( 450462 ) on Wednesday July 24, 2002 @06:59AM (#3943264)
    I did a lot of interviews at MS when I was there, and I quickly learned not to ask riddles. First off, it makes people who don't get them uncomfortable and angry. Second, it doesn't actually show that the person can write software.

    I used a much simpler approach, so simple most people think its silly. But thats the point; nobody leaves the interview thinking they were tricked or duped. I always started with implementation of strcpy(). Half of the candidates failed right there! They took most of the hour to get it right (or not), but were able to see point-blank that they were not ready for the job.
    Next, I would ask about crashing cases, and if they figured out overlapping memory locations, have them write a 'fixed' version. This weeded out another big chunk. After that, I went into some color counting algorithms.
    I stayed well withing the field of what the candidate would expect, and did not try to trick him or make him nervous with off the wall riddles.

    This approach worked great, and didn't leave anyone feeling robbed and abused. The ability to solve riddles *is* an indicator of how smart the person is, but it is *not* an indicator of how good a programmer they will be.
  • Re:Infuriating,,, (Score:2, Informative)

    by Trak ( 670 ) on Wednesday July 24, 2002 @09:32AM (#3943853) Homepage Journal
    The answer they are looking for has to do with starting a second fire between the burning end of the island and the safe end. Then when the first fire reaches willy, he just steps into the burned-out space from the second fire which he started.
  • by jeremyp ( 130771 ) on Wednesday July 24, 2002 @09:32AM (#3943854) Homepage Journal
    In 1998 I was interviewed by the Technical Director of a small company in the UK. Their standard tech question was "write a function to rotate a monochrome bitmap". The idea was not to come up with necessarily the correct answer (as if there was *one* correct answer), but to see how you tackled the problem. The only problem with that particular question is that there was a danger that some otherwise perfectly adequate programmers would freeze like a rabbit caught in headlights.

    OTOH I've never seen a company with a higher concentration of good programming skills.
  • by SerpentMage ( 13390 ) on Wednesday July 24, 2002 @10:00AM (#3944015)
    Actually you do not need the man pages. Correct me if I am wrong here... BUT...

    char *s; get(s); put(s);

    Well s is not initialized and pointing at anything. Hence even if get allocated a buffer that value will not be carried back since it is a single pointer. For that to work you would need write get( &s) and then that would work.

    Yes?
  • Re:A Dilemma: (Score:2, Informative)

    by CProgrammer98 ( 240351 ) on Wednesday July 24, 2002 @10:34AM (#3944239) Homepage
    There's excellent explanations of why it's correct to switch here [greylabyrinth.com] and here [maths.org]

  • by Jhan ( 542783 ) on Wednesday July 24, 2002 @10:43AM (#3944303) Homepage

    Unfortunately, Numbers will only be able to increase his tally by one, each time he's picked (less actually, since after a while there will be a high probability that no 'untallied' prisoner has been in the room since he was last there).

    If Numbers is called on the average every 100 days, and can increase the tally by one each time, the procedure will take a bit less than 30 years!

    Not that my solution is much better:

    The prisoners make up their own calendar, in which every month has 100 days. Each prisoner is also assigned a number (1-100).

    Now, if a prisoner is called on day N of the 'month', turning the light on is a signal to next guy that he knows for sure that prisoner number N has been in the room. Turning the light off is a signal that he doesn't have a clue about prisoner N.

    If a prisoner is called on day N and sees a light, he makes a note that guy number N-1 has been in the room. The first prisoner that has all 100 checked can get the lot sprung.

    Initially, each prisoner can only be sure of himself, so things will not start moving until by chance a prisoner is called on his own day. This should happen several times during the first month though. Knowledge of who has been in the room will then slowly spread among the prisoners.

    The process won't complete until (some time after) every prisoner has been called on his day at least once. I tried to calculate how long that would be but my math isn't up to it. Probably some decades :-(

  • by ChaosDiscordSimple ( 41155 ) on Wednesday July 24, 2002 @12:04PM (#3944935) Homepage

    A couple of years ago I was asked: How many gas stations are there in the US?

    My answer: I don't know, I'd probably check a search engine.

    After I insisted that I couldn't come up with an answer on my own, I was informed that they were looking for people who "think out of the box" and only people that hazarded a guess made it to level two interviews.

    It sounds like the interviewer remembered a typical "impossible" question, but forgot why you ask it. The purpose isn't to think out of the box, the purpose is to examine problem solving skills with a problem the applicant has never seen before. Sure, you don't know anything about gas station density in the US, but you'll eventually be required to answer a question you don't really know anything about. "We've been asked to implement a simple web browser that will run on an embedded system that doesn't exist yet. Give me an estimate for how long it will take." It sucks, but you're going to need to do it.

    Because most engineers are loathe to pull estimates out of thin air, it's only fair to explain that you're only looking for a very rough estimate. If the engineer continues to resist, explain that you know he doesn't have good input to work with.

    That said, your answer, "check a search engine" isn't that bad of a place to start. (That's what reference materials are for!). When you're told that it's a good place to start, but that it's not an option, start making up numbers and guessing. Make it clear when you're guessing at numbers. "Well, there are about 300 million people in the US, about half don't have cards, so 150 million cars. You typically get gas once per week. A gas station can serve 100 people per day. That's 700 people per week, or about 1,000 for ease of doing the calculation. So you'll need about 150,000 gas stations." I promise that I pulled that answer out of the air. I have no idea how many people are in the US, let alone any of the other numbers, but I'm pretty sure that I'm within an order of magnitude. In fact, quickly searching the web it looks like I'm very close [oldgas.com].

    Similar logic can get you surprisingly accurate numbers for the volume of water that flows out of the Mississippi each minute, the number of malls, police stations, high schools in the US, or other seemingly hard to know things. Just take what you do know and make educated guesses.

    The string hash function was just stupid, although it might have helped to ask the interviewer what properties he wanted out of the hash. In general, bouncing questions about the problem off the interviewer looks good and can often make the solution easy. The question does sound like an esoteric knowledge question, and those are the worst.

    Being asked to solve a tricky technical question? Well, it's a legit, real problem. It's a fair way to gauge your problem solving ability (did you stumble across the same things they did? Good. Did you suggest something new? Great.). I wouldn't worry about their "stealing" your answer. If the problem really is hard, it's unlikely in the ten or twenty minute interview question that you'll find a superior answer to them.

  • my stab at a proof (Score:2, Informative)

    by invictus ( 83837 ) on Wednesday July 24, 2002 @02:38PM (#3946241) Homepage Journal
    000 0
    001 0
    010 0
    011 1
    100 0
    101 1
    110 1
    111 1

    (a & b) | (a & c) | (b & c ) | ((a & b) & c))

    Karnaugh Mapping...
    'a'b 'a b a'b a b
    c _ x x x

    'c _ _ _ x

    so the simplifications that can be made....

    (c & (a | b) ) | (a & b)

    there are no other 'little circles' that can be made on the map (as my EE101 prof was so fond of saying) therefore there are no further simplifications.

  • by invictus ( 83837 ) on Wednesday July 24, 2002 @02:49PM (#3946306) Homepage Journal
    ack. that got all messed up... (well the map anyway)
    well, i cant seem to get it to line up... lets see it this way...
    .
    -.|a'|a'|a.|a.|
    -.|b'|b.|b'|b.|
    --+--+--+--+--+
    c.|..|x.|x.|x |
    --+--+--+--+--+
    c'|..|..|..|x.|
    wow, that was a PITA

The hardest part of climbing the ladder of success is getting through the crowd at the bottom.

Working...