7号刚从新加坡回来,晚上就被公司通知可以参加中科院面试专场,我并不是中科院学生,所以很感谢360公司给予自己面试的机会。
这次360面试分为三面,一面是简单的筛选,二面是牛任面,三面是Hr面,自己糊里糊涂地居然参加完了三次面试,第二天就收到了公司的面试通过邮件。自己准备的不太充分,但是很幸运能够通过三轮面试,还是出乎我的意外。
360公司的面试现场比较混论,比如插队、等待时间不准确等等,主要还是靠工作人员的叫号和维护,自动化程度比较低,但是面试人员都是很亲切的,三场面试下来感觉是在和同学、老师聊天,氛围调整的还不错。
一面主要考察项目经验和编程功底,自己C++不够扎实,所以在编程时语法忘记不少,但是思路是正确的,所以勉强通过了;二面是360人工智能研究院的副院长,因为我的工程项目比较多,所以我们聊起来很开心,最后他说我和公司需求的契合度很高,表达能力很好,所以顺利通过二面;三面是Hr姐姐的面试,也是在一起聊聊自己的背景和未来的发展规划,很轻松。
下面主要讲一下一轮面试的编程题目:已知两个整数数组,求两数组的交集。
我的思路是先对两数组排序,然后依次比较两个数组元素的大小,挑选出来相等的元素。
如果A数组小于B数组,则A数组元素后移;
如果B数组小于A数组,则B数组元素后移;
如果A数组等于B数组,则A、B数组元素后移,且取出该元素放入交集数组;
程序注意点:数组为空、原数组是否可以破坏、交集有重复元素等。
#include <iostream> // std::cout
#include <algorithm> // std::sort
#include <stdio.h>
#include <vector> // std::vector
std::vector<int> duplicate(int AArray[], int ALength, int BArray[], int BLength);
int main()
{
/*
//重复元素
int aArray[] = { 2, 4, 2, 1, 4 };
int bArray[] = { 2, 4, 2, 1, 4 };
*/
//不等长
int aArray[] = { -2, 4, 4 };
int bArray[] = { -2, 4, 2, 1, 4 };
/*
//无效输入
int *aArray = nullptr;
int bArray[] = { 2, 4, 2, 1, 4 };
*/
//得到数组长度
int ALength = sizeof(aArray) / sizeof(aArray[0]);
int BLength = sizeof(bArray) / sizeof(bArray[0]);
std::vector<int> dupArray = duplicate(aArray, ALength, bArray, BLength);//求交集
//删除重复元素
//首先将vector排序,已排序
//然后使用unique算法, unique返回值是重复元素的开始位置。
std::vector<int>::iterator pos;
//Removes all but the first element from every consecutive group of equivalent elements in the range[first, last).
pos = std::unique(dupArray.begin(), dupArray.end());
//最后删除后面的那段重复部分
dupArray.erase(pos, dupArray.end()); //Removes from the vector either a single element (position) or a range of elements ([first,last))
//输出
auto beg = dupArray.begin(), end = dupArray.end();
while (beg!=end)
{
std::cout << *beg << std::endl;
beg += 1;
}
getchar();
}
//得到两个整形数组的交集
std::vector<int> duplicate(int AArray[], int ALength, int BArray[], int BLength)
{
//重复数组
std::vector<int> dupArray;
if (AArray == nullptr || BArray == nullptr)
{
return dupArray;
}
else
{
//排序
std::vector<int> AVector(AArray, AArray+ ALength);
// using default comparison (operator <):
std::sort(AVector.begin(), AVector.begin() + ALength);
std::vector<int> BVector(BArray, BArray + BLength);
std::sort(BVector.begin(), BVector.begin() + BLength);
//比较
auto Abeg = AVector.begin(), Aend = AVector.end();
auto Bbeg = BVector.begin(), Bend = BVector.end();
while (Abeg!=Aend && Bbeg!=Bend)
{
if (*Abeg == *Bbeg) //解引用
{
dupArray.push_back(*Abeg); //重复数组放入
Abeg += 1;
Bbeg += 1;
}
else if (*Abeg < *Bbeg)
{
Abeg += 1;
}
else
{
Bbeg += 1;
}
}
return dupArray; //vector转数组
}
}