📜  微软面试经历 | Set 141(校外-IDC在线编码测试)

📅  最后修改于: 2022-05-13 01:58:39.488000             🧑  作者: Mango

微软面试经历 | Set 141(校外-IDC在线编码测试)

在线测试于 2017 年 11 月 5 日在 CoCubes 上进行。该测试启用了网络摄像头,以避免任何形式的作弊。您无法打开任何其他选项卡或最小化窗口。它由 3 个编码问题组成。

时间限制:75 分钟
(*) 标记 (Qn-1) = 2

(*) 标记 (Qn-2) = 3

(*) 标记 (Qn-3) = 5

问题 1:编写一个函数,它接受一个整数数组及其大小,并按以下方式修改数组:

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

问题 2:编写一个函数,它接受一个整数数组及其大小,并返回最大索引差 ie (ij),使得 array[i] < array[j] 并且 i < j。如果没有这种情况,则返回 -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

问题 3:编写一个函数,它接受树的根,并返回一个链表,其中包含从左到右顺序的树的叶节点。
假设:

(*) 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 
     

继续练习 GeeksForGeeks 的问题。