Open In App
Related Articles

Microsoft Interview Experience | Set 141 (Off-Campus – Online Coding Test for IDC)

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
The online test was conducted on CoCubes on 2017, 5th November. The test was webcam enabled to avoid any kind of cheating. You cannot open any other tab or minimize the window. It consisted of 3 coding questions. TIME LIMIT: 75 minutes (*) Marks(Qn-1) = 2 (*) Marks(Qn-2) = 3 (*) Marks(Qn-3) = 5 Question 1: Write a function which accepts an integer array and its size and modifies the array in the following manner:
1) If the elements of index i and (i+1) are equal then, double the value at index i
and replace the element at index (i+1) with 0. 

2) If the element at index i is 0, then ignore it.

3) Any number (element in an array) must be modified only once.

4) At the end, shift all the zeros (0s) to the right of the array and remaining
nonzeros to the left of the array.

Example: 
Input: 2 2 0 4 0 8
Output: 4 4 8 0 0 0

Input: 2 2 0 4 0 2
Output: 4 4 2 0 0 0
Question 2: Write a function which accepts an integer array and its size and returns the maximum index difference i.e. (i-j) such that array[i] < array[j] and i < j. If there is no such case, return -1 .
Input: 2 0 3 5 6 1
Output: 4

There was only one test case given which is mentioned above. But I am providing the below
one of the sample cases which is an important thing to be noted. It returns -1 because all the
elements after any given element are smaller than it. DO take care of such cases.

Input: 9 8 7 6 5
Output: -1
Question 3: Write a function which accepts the root of a tree, and returns a Linked List which contains the leaf nodes of the tree from left to right order. Assumptions:
(*) Structure of the node of tree is as follows:
struct TreeNode
{
    int data;
    struct TreeNode* left;
    struct TreeNode* right;
};

(*) Don't allocate extra memory for Linked List, just let the right pointer of a leaf
node point to the next leaf node to form a linked list.

Example:
            10 
         /      \               
       20        100          
      /  \       / \             
    30    40    9   66

Output: 30 -> 40 -> 9 -> 66 
     
Keep practicing questions from GeeksForGeeks.

Last Updated : 06 Nov, 2017
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads