Google Fresher Interview Questions – round 3

 

  • Write C++ class for the game Connect Four. [Connect Four (also known as Plot Four, Four In A Row, and Four In A Line) is a two-player board game in which the players take turns in dropping discs into a seven column grid with the objective of getting four of one's own discs in a line.]
  • Given a stack and an input string of 1234.At any point you can do anyone of the follow 
    i. take the next input symbol and Enque.
    ii. you can pop as many as you can. When ever you
    pop an element it will be printed
                (you cannot pop from an empty stack)

    How many such permutations are possible on an input of size N?

    Solution:
    It is Nth catalan number.For a detailed solution look at question5 of Stacks and Queues

  • Give an example of one permutation that this data structure cannot generate. 
    For Example:
    
    1234 is input.
    
    First push all 1,2,3,4 on to stack and pop all.
        output will be 4321.

    It means that this data structure can generate 4321.

    Solution:
    3124 
    for a detailed solution please look at question7 of the post
    Stacks and Queues

  • Question 2 was pretty easy right? Now do again the same question but the data structure this time around is a Deque. 
    Input: 12345
    Data Structure: Deque ( Doubly Que )
    
    Note: Deque is a data structure into which you can do enque
        and deque from both sides.Some thing like this
    __________________________________
    enque ---> <----enque dequeue <---- ----->dequeue
    __________________________________

    Solution: 
    It is N!. Guess why?(no constraints).Convince yourself by proving that every permutation can be generated by a set of valid operations.This prove can be using the principle of strong mathematical induction.So for this specific input the answer is 120.

  • Classic Egg Puzzle Problem You are given 2 eggs.You have access to a 100-store building. Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical.You need to figure out the highest floor of a 100-store building an egg can be dropped without breaking. Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process.

    Solution: 
    Let “d” be the number of drops required to find out the max floor.we need to get the value of d.

    let’s say if we drop from height d then if it breaks then we have d-1 floors to check for the second egg . so max of “d” drops, so first we will drop it from height “d” if it doesn’t break at a height “d” then we are left with “d-1″ drops,so lets drop it from d + ‘d-2′ + 1 height suppose if it break there then you are left with ‘d-2′ drops.
    and so on until that sum is less than 100, it’s like a linear search,

    in equations,

    (1+(d-1))+ (1+(d-2)) + …. >= 100

    here we need to find out d

    from the above equation

    d(d + 1)/2 >= 100

    from above d is 14

  • Tags: , ,


    Did You Enjoy This Post?

    Subscribe to our blog through our RSS feed or email to receive updates on more posts like this.post on your favourite social networking or media site to let others know about this post. Help us generate more buzz by submitting/voting for this post with the following buttons.

    Leave a Reply











    request new questions/article: send email to freequestionbank at gmail dot com