Interview Questions #7


1) We have N number of train seats say 1, 2, ...,.. N, and If the input is seat number '5', you must tell the opposite seat number '12'. Just write a program to get the output as opposite seat number, and don't want to focus on compartment or window.

         Seat Numbers are like this
      // 1     2     3    4    5     6     7     8  //  Window
      // 16   15   14  13  12   11   10   9  //
        ----------------------------------------  compartment 1
      // 17   18   19   20  21   22   23   24 //
      // 25   26   27   28  29   30   31   32 //
        ----------------------------------------  compartment 2
     //  ....   ....   ....   ....


2)  An array 'arr' is sorted with elements 1, 2, 3, 3, 4, 5, 10, 11, 11, 13. Find the number 5 and count only once the number of elements present greater than 5.  The output is 3 (10, 11, and 13). Consider the time complexity also. Click here for answer.


3)  Process A has 3 sockets and thread 2, and Process B has 1 socket and thread 1. Process B sends 3 messages "Hi", "Hello", "Bye" consecutively to Process A's 3 sockets and it will be processed in thread 2. We use message queue for message transfer.


Comments