Yahoo Interview Questions

Yahoo Telephonic Round:

Design classes for the following problem. (C++)

A Customer Can have multiple bank accounts A Bank account can be owned by multiple customers When customer logs in he sees list of account, on clicking on an account he sees list of transactions.

Solution :

Customer class, Account class, Transaction class
Customer class contains an array of pointers to the account classes
Account class contains an array of pointers to its owner customer classes
Account class also contains an array of transactions associated to it.
Transaction class contains id or pointer the customer who did that transaction
In customer class write a function with prototype


for (i in Accounts )
{
cout << i.AccountName << endl;
}
cin >> id;
for(i in Accounts[id].transactions )
{
cout << i.TransDetails << endl;
}


Yahoo Interview Round 1:

  1. How to call a C++ function which is compiled with C++ compiler in C code?

    Solution: The C++ compiler must know that f(int,char,float) is to be called by a C compiler using the extern "C"construct:

    The extern "C" line tells the compiler that the external information sent to the linker should use C calling conventions and name mangling (e.g., preceded by a single underscore). Since name overloading isn't supported by C, you can't make several overloaded functions simultaneously callable by a C program.
    // This is C++ code 
    // Declare f(int,char,float) using extern "C":
    extern "C" void f(int i, char c, float x);
    ...
    // Define f(int,char,float) in some C++ module:
    void f(int i, char c, float x)
    {
    .....
    }


  2. When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)
  3. How do you initialize a static member of a class with return value of some function?

    Solution :

    Static data members are shared by all object instances of that class. Each class instance sees and has access to the same static data. The static data is not part of the class object but is made available by the compiler whenever an object of that class comes into scope. Static data members, therefore, behave as global variables for a class. One of the trickiest ramifications of using a static data member in a class is that it must be initialized, just once, outside the class definition, in the source file. This is due to the fact a header file is typically seen multiple times by the compiler. If the compiler encountered the initialization of a variable multiple times it would be very difficult to ensure that variables were properly initialized. Hence, exactly one initialization of a static is allowed in the entire program.

    Consider the following class, A, with a static data member, _id:

       
    //File: a.h
    class A
    {
    public:
    A();
    int _id;
    };

    The initialization of a static member is done similarly to the way global variables are initialized at file scope, except that the class scope operator must be used. Typically, the definition is placed at the top of the class source file:

       // File: a.cc
    int A::_id;

    Because no explicit initial value was specified, the compiler will implicitly initialize _id to zero. An explicit initialization can also be specified:


    // File: a.cc
    int A::_id = 999;

    In fact, C++ even allows arbitrary expressions to be used in initializers:

          // File: a.cc
    int A::_id = GetId();
  4. How can one application use same API provided by different vendors at the same time?
  5. If you are given the name of the function at run time how will you invoke the function?

    Solution :

    • Compile your program with --export-dynamic on the gcc command line
    • Link with -ldl (dynamic library handling, needed for dlopen and dlsym
    • Call dlopen() with a null parameter, meaning you aren't loading symbols from a file but from the current executable
    • Call dlsym() with the name of the function you'll be calling. Note that C++ modifies function names, so If you're trying this with C++, you'd have to either declare this function as extern "C", or figure out what name the function has after compiling. (On unix, you could run nm -s on the object file for this).
    • If dlsym() returns non-null, use the returned value as a function pointer to invoke your function.
Yahoo Interview Round 2:
  1. When will you use shell script/Perl ahead of C/C++?
  2. How does yahoo handles billions of requests, does it create a thread per request or a process?
  3. How does HTTP works?

    Solution :HTTP Is a request-response protocol.

    For example, a Web browser initiates a request to a server, typically by opening a TCP/IP connection. The request itself comprises o a request line, o a set of request headers, and o an entity. The server sends a response that comprises o a status line, o a set of response headers, and o an entity. The entity in the request or response can be thought of simply as the payload, which may be binary data. The other items are readable ASCII characters. When the response has been completed, either the browser or the server may terminate the TCP/IP connection, or the browser can send another request.

  4. How to count number of unique music titles downloaded from a log file which contains an entry of all music title downloaded?
  5. What is the difference between COM and CORBA?

    Solution :COM is linked to Microsoft and CORBA to UNIX,Moreover, COM objects require installation on the machine from where it is being used .CORBA is ORB (Object request broker) , and also its a specification owned by OMG, which is open. Not owned by a company. So we cannot say that it only belongs to Unix. Corba servers can run on windows NT, and CORBA clients can run on Unix.

  6. What is web service?

    Solution :Web Service is defined as "a software system designed to support interoperable Machine to Machine interaction over a network." Web services are frequently just Web APIs that can be accessed over a network, such as the Internet, and executed on a remote system hosting the requested services.

I got only these two Rounds as of now, if I get any more I will post them here. If you have attended yahoo interview please share your experience and questions with us. You can mail them at kchaitanyya@gmail.com or you can comment here.Solutions for rest of questions will be provided later.if you know any of the questions which are unsolved please comment the solution. we will include.

16 comments:

  1. its better if u post the answers tooo

    ReplyDelete
  2. I am trying them ... it takes some time..we can discuss them.try and comment..

    ReplyDelete
  3. Hello,

    I had my first telephonic inerview with ITC banglore for PHP programmer then they told or second interview with yahoo. yahoo currently emphasizing on css,html,javascript. why ?

    why they told for second interview with yahoo ?

    ReplyDelete
  4. Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Massagem, I hope you enjoy. The address is http://massagem-brasil.blogspot.com. A hug.

    ReplyDelete
  5. Thanks Massagem for your comments on my blog.

    ReplyDelete
  6. Hi All ,
    Please help me to give hint or solution of algorithm given below realted to Binary Tree.
    Problem:
    Assume that you are given a binary tree such that each node only contains pointers to its left and its right tree(i.e there are no back pointers back to the parent) Assume that the leaves of the binary tree have been assigned values and the all internal nodes have undefined values (you cannot assume that some special value such as -32.767 means that no value is defined).
    Write a function sum_up_nodes that fills in each internal node with a value = sum of its childern. The interface of the function could be as follows
    Void sum_up_nodes(Treetr tree)

    Thank you
    Suri

    ReplyDelete
  7. This is a reply for ssingh request:

    All you have to do is traverse the tree and in the process when you reach to the leaf node return the value, and sum up the values returned from the left and right nodes and set to the current node and return that value. Here is a psedocode.

    sum_up_nodes(Treetr tree)
    {
    if(tree==null)
    rturn 0;
    if(tree.left==null && tree.right==null)
    return tree.value;


    tree.value = sum_up_nodes(tree.left);
    tree.value += sum_up_nodes(tree.right);

    return tree.value;
    }

    ReplyDelete
  8. Suppose you have a case where you have to say "List all files which contain "Chaitanya". Now this is a single line command in Shell scripting using its grep utility. However there is no direct way of doing something similar in C++/C.

    Though compiled languages are fast and efficient, Shell scripts work at a higher level than the machine.Also to complete a task in Unix that you need to do repeatedly, you either spend 2 hours writing a shell script, or 2 days writing a C++ program. Your call.

    ReplyDelete
  9. Hello,

    Can you tell me what questions were asked you in telephonic interview for PHP? I have interview tomorrow.

    ReplyDelete
  10. Anna!!! Your blog "keka".... Nice questions... If possible provide answers with explanations. It will help alot buddy... the blog is really awesome... with nice questions.... Keep it up.. Do the Best...

    ReplyDelete
  11. That's great information on this.Thanks a lot for sharing it with us.It will keep us knowing the business!!!!!

    Common Interview Questions

    ReplyDelete
  12. A good interview with some excellent question answer session. I like your post very much.

    ReplyDelete
  13. Answers to some of the most important interview questions can be seen at the mentioned site:

    Interview Made Easy.

    ReplyDelete
  14. Are these only questions asked by yahoo or do you have any more list of questions.

    ReplyDelete
  15. Hi

    I read this post 2 times. It is very useful.

    Pls try to keep posting.

    Let me show other source that may be good for community.

    Source: Yahoo interview questions

    Best regards
    Jonathan.

    ReplyDelete
  16. interview questions can be seen at the mentioned site:

    Job Interview Tips

    ReplyDelete