Log Date

Welcome to techInterview, a site for technical interview questions, brain teasers, puzzles, quizzles (whatever the heck those are) and other things that make you think!

  1. Text post

    Getting a fair result with an unfair coin

    How can you get a fair coin toss if someone hands you a coin that is weighted to come up heads more often than tails?

    Notes: 41 notes

  2. Text post

    We are NY Tech asks:

    "How many unique areas of human knowledge have the right size of passionate users to make it as a Stack Exchange site?”

    Answer: 30,000.

    Notes: 5 notes

  3. Text post

    Storing 1 million phone numbers

    What is the most efficient way, memory-wise, to store 1 million phone numbers?  Apparently this is an interview question at Google, although this seems like its a bit too easy.

    Notes: 8 notes

    Tags: google interview

  4. Text post

    Reverse a String

    A typical programming interview question is “reverse a string, in place”. if you understand pointers, the solution is simple. even if you don’t, it can be accomplished using array indices. i usually ask candidates this question first, so they get the algorithm in their head. then i play dirty by asking them to reverse the string word by word, in place. for example if our string is “the house is blue”, the return value would be “blue is house the”. the words are reversed, but the letters are still in order (within the word).

    Read More

    Notes: 16 notes

  5. Text post

    100 Doors in a Row

    Problem: you have 100 doors in a row that are all initially closed. you make 100 passes by the doors starting with the first door every time. the first time through you visit every door and toggle the door (if the door is closed, you open it, if its open, you close it). the second time you only visit every 2nd door (door #2, #4, #6). the third time, every 3rd door (door #3, #6, #9), etc, until you only visit the 100th door.

    question: what state are the doors in after the last pass? which are open which are closed?

    Read More

    Notes: 34 notes

  6. Text post

    Red Marbles, Blue Marbles

    Problem: you have two jars, 50 red marbles, 50 blue marbles. you need to place all the marbles into the jars such that when you blindly pick one marble out of one jar, you maximize the chances that it will be red. (when picking, you’ll first randomly pick a jar, and then randomly pick a marble out of that jar) you can arrange the marbles however you like, but each marble must be in a jar.


    Chance! chance is easy if you know how to do the formula. we know that we have two choices to make. first we’ll pick a jar, and each jar will have a 1/2 chance of being picked. then we’ll pick a marble, and depending how we stack the marbles, we’ll have a (# of red marbles in jar)/(# of total marbles in jar) chance of getting a red one.

    for example, say we put all the red marbles into jar A and all the blue ones into jar B. then our chances for picking a red one are:

    1/2 chance we pick jar A * 50/50 chance we pick a red marble
    1/2 chance we pick jar B * 0/50 chance we pick a red marble

    do the math and you get 1/2 chance for a red marble from jar A and a 0/2 chance for a red marble from jar B. add ‘em up and you get the result = 1/2 chance for picking a red marble.

    think about it for awhile and see if you can figure out the right combination. we had a 50/50 (guaranteed) chance in picking a red marble from jar A, but we didn’t have to have 50 red marbles in there to guarantee those fantastic odds, did we? we could’ve just left 1 red marble in there and the odds are still 1/1. then we can take all those other marbles and throw them in jar B to help the odds out there.

    let’s look at those chances:

    1/2 we pick jar A * 1/1 we pick a red marble
    1/2 we pick jar B * 49/99 we pick a red marble

    do the math and add them up to get 1/2 + 49/198 = 148/198, which is almost 3/4.

    we can prove these are the best odds in a somewhat non-formal way as follows. our goal is to maximize the odds of picking a red marble. therefore we can subdivide this goal into maximizing the odds of picking a red marble in jar A and maximizing the odds of picking a red marble in jar B. if we do that, then we will have achieved our goal. it is true that by placing more red marbles into a jar we will increase the chances of picking a red marble. it is also true that by reducing the number of blue marbles in a jar we will increase the odds also. we’ve maximized the odds in jar A since 1/1 is the maximum odds by reducing the number of blue marbles to 0 (the minimum). we’ve also maximized the number of red marbles in jar B. if we added any more red marbles to jar B we would have to take them out of jar A which reduce the odds there to 0 (very bad). if we took any more blue ones out of jar B we would have to put them in jar A which reduce the odds there by 50% (very bad).

    it wasn’t really a good proof, but QED anyway :-P

    Notes: 6 notes

  7. Text post


    problem: two trains enter a tunnel 200 miles long (yeah, its a big tunnel) travelling at 100 mph at the same time from opposite directions. as soon as they enter the tunnel a supersonic bee flying at 1000 mph starts from one train and heads toward the other one. as soon as it reaches the other one it turns around and heads back toward the first, going back and forth between the trains until the trains collide in a fiery explosion in the middle of the tunnel (the bee survives). how far did the bee travel?

    Read More

    Notes: 6 notes

  8. Text post

    int atoi( char* pStr )

    Problem: write the definition for this function without using any built-in functions. if pStr is null, return 0. if pStr contains non-numeric characters, either return 0 (ok) or return the number derived so far (better) (e.g. if its “123A”, then return 123). assume all numbers are positive. plus or minus signs can be considered non-numeric characters. in order to solve this program, the programmer must understand the difference between the integer 0 and the character ‘0’, and how converting ‘0’ to an int, will not result in 0. in other words, they have to understand what ascii is all about.

    Read More

    Notes: 8 notes

  9. Text post

    Daughters’ Ages

    Two MIT math grads bump into each other at Fairway on the upper west side. They haven’t seen each other in over 20 years.

    the first grad says to the second: “how have you been?”
    second: “great! i got married and i have three daughters now”
    first: “really? how old are they?”
    second: “well, the product of their ages is 72, and the sum of their ages is the same as the number on that building over there..”
    first: “right, ok.. oh wait.. hmm, i still don’t know”
    second: “oh sorry, the oldest one just started to play the piano”
    first: “wonderful! my oldest is the same age!”

    problem: how old are the daughters?

    Read More

    Notes: 10 notes

  10. Text post


    Problem: this year on October 2, 2001, the date in MMDDYYYY format will be a palindrome (same forwards as backwards).
    when was the last date that this occurred on? (see if you can do it in your head!)

    Read More

    Notes: 5 notes

Tumblr Theme 'Nautical' by PixelUnion