商汤提前批面经 一共三面 已有意向书
商汤科技 提前批 22领航员-MIG-自动驾驶软件开发工程师
笔试
7.16前投递简历的不需要笔试。
一面 技术面 8.3
应该是问了一些项目和八股文,具体不太记得清了,好像有问vtable存在哪里的,我说存在data section,不太确定,面试完查了下是对的。
后面是手写shared_ptr,然后问了下它的thread safety,如何实现(mutex和atomic,atomic我没说出来)。
#include <iostream>
using namespace std;
template<typename T>
class SharedPtr {
int* refCount;
T* pData;
public:
SharedPtr(T data)
{
refCount = new int(1);
pData = new T(data);
}
SharedPtr(T& other) {
refCount = other->incrementRefCount();
this->pData = other->getData();
}
int* incrementRefCount() {
++(*refCount);
return refCount;
}
T* getData() {
return pData;
}
~SharedPtr() {
--(*refCount);
if(*refCount == 0) {
delete pData;
delete refCount;
}
}
};
int main() {
SharedPtr<int> a(1);
SharedPtr<int> a2{a};
cout << *a.getData() << " " << *a2.getData();
return 0;
}
二面 技术面 8.6
开场聊项目,简历上写什么问什么,还问了一点Python,因为简历上有写,Python问的是往tuple里面塞list能不能改list里面的东西,我回答的是虽然Python的tuple是immutable的,存的应该是一个reference,list里面的东西还是mutable的。八股文好像还问了vtable存在哪里的。
我简历上有写docker相关的,问了container和image的区别,我说了container是image的instance,image一般用Dockerfile来创建,container可以存为image,但是docker是layered system,重新存回的image会比原来的image大很多,因为对于container的修改是一层一层往上append的。
还问了一些docker相关的命令,比如如何进入一个container,我回答了下面两种
docker exec -it <container name> /bin/bash docker attach <container name>
还有问如何运行一个container,publish端口,挂载本地存储
docker run --name <container name> -p <host port>:<container port> -v <host path>:<container path> <docker registry>/<image name>:<image version>
Linux查看编译后binary的命令,面试的时候忘了,把自己带坑里去了,面试完才想起来是nm。
然后是两题编程题。
第一题:Find the top k elements with the highest frequency in an array.
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
using namespace std;
typedef pair<int, int> PII;
// find the K most occurred elements of an array
vector<int> kElementsWithHighestFrequency(vector<int>& nums, int k) {
unordered_map<int, int> freq;
for(auto x: nums) {
++freq[x];
}
priority_queue<PII, vector<PII>, greater<PII>> pq;
for(auto [num, f]: freq) {
pq.emplace(f, num);
if(pq.size() > k) {
pq.pop();
}
}
vector<int> rets;
while(!pq.empty()) {
rets.push_back(pq.top().second);
pq.pop();
}
return rets;
}
int main() {
vector<int> input {1, 2, 3, 2, 2, 2, 1, 1, 1, 1, 3, 4, 5, 8, 9};
auto rets = kElementsWithHighestFrequency(input, 2);
for(auto x: rets) {
cout << x << " ";
}
return 0;
}
第二题:第一题做得比较快,面试官好像临时又出了一题矩阵乘法
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
using namespace std;
int matrixMultiply(vector<vector<int>>& m1, vector<vector<int>>& m2, vector<vector<int>>& res) {
if(m1.empty() && m2.empty()) {
res = {};
return 0;
}
if(m1.empty() || m2.empty()) return 1;
if(m1[0].size() != m2.size()) return 1;
int m = m1.size();
int n = m2[0].size();
int t = m2.size();
res.resize(m, vector<int>(n, 0));
for(int i = 0; i < m; ++i) {
for(int j = 0; j < n; ++j) {
for(int k = 0; k < t; ++k) {
res[i][j] += m1[i][k] * m2[k][j];
}
}
}
return 0;
}
int main() {
vector<vector<int>> m1 {{1, 2}, {2, 3}};
vector<vector<int>> m2 {{1, 4}, {4, 5}};
vector<vector<int>> rets;
int ret = matrixMultiply(m1, m2, rets);
if(ret) cout << "failed";
else {
for(auto& row: rets) {
for(auto x: row) {
cout << x << " ";
}
cout << endl;
}
}
return 0;
}
三面 技术面 8.10
30分钟就结束了,三面大概快速聊了下项目,然后就是闲聊:自我介绍+聊对自动驾驶的了解+聊项目/实习+反问。
项目和实习的话我聊到了之前实习的时候做的C++ profiling相关的一些东西。问到了Python的decorator,问我有没有用过Python的decorator它的原理是怎么样的,我说用过,原理是把一个函数作为参数传入到decorator里面去,然后可以在call function的前后做一些preprocessing和postprocessing,在unittest的时候有时候会用@patch来mock一些东西。然后面试官问我有没有写过decorator,我说我写过一个decorator来应对数据库连接并发数过多,类似BBR的congestion control,第一次连接失败等1s,第二次等2s,第三次等4s,以此类推。
我对自动驾驶了解不多,就聊了一下一些宏观和偏市场应用的,聊了下蔚来、小鹏、特斯拉之类的在做的事(只能硬着头皮上了)。
面试官问我了解自动驾驶系统吗,我说不知道,然后我在反问的时候问了下面试官这个问题。
我在简历上写我去过美国,他问我去美国有什么体会吗,这一部分主要是在闲聊。
意向书 8.13

查看13道真题和解析