一面
形式:
视频面试MicrosoftTeam,时长45min左右。
内容
- 英文自我介绍
- 讲自己最special的地方
- 做题:一维数组连续子数组的最小和
int Minsum(int[] arr){
if (arr == null || arr.length == 0) {
return 0;
}
int len = arr.length;
int tempsum = arr[0];
int minsum = arr[0];
int tempmin = 999999999;Integer.Max;
for(int i=1;i<len;i++){
if(tempsum > 0){
tempsum = 0;
}
tempsum += arr[i];
if (tempsum < minsum){
minsum = tempsum;
}
}
return minsum;
}
- 陈越姥姥第一堂课的内容,连续子数组最大和的变式,用于表现算法之美。
- 最优解O(n),直接前缀求和。
总结
- 面试官大概率ACM出生,对代码的敏感性很强,思维敏捷,逻辑缜密,全程领着我优化代码结构
- 微软比较追求代码之美,code elegant.
二面
形式:
视频面试MicrosoftTeam,时长45min左右。
内容
同上
- 做题:实现Windows下画图中油漆桶的功能
import java.utils.*;
public class Point{
int x;
int y;
int color;
void Point(int x, int y, int color){
this.x = x;
this.y = y;
this.color = color;
}
}
public void Mypaint(Point[][] mymap, Point pos){
if (mymap.length == 0 || mymap == null) {
return;
}
int xlen = mymap.length;
int ylen = mymap[0].length;
int color = pos.color;
bfs(mymap[pos.x][pos.y], color);
mymap[pos.x][pos.y].color = color;
}
public void judge(Point p, boolean[][] visited, Point[][] mymap, int xdirection, int ydirection, Queue<Point> myqueue){
int xlen = mymap.length;
int ylen = mymap[0].length;
if (p.x + xdirection >=0 && p.x + xdirection <xlen &&p.y + ydirection <ylen &&p.y + ydirection >=0 && !visited[p.x + xdirection][p.y+ ydirection] && mymap[p.x + xdirection][p.y+ ydirection].color == temp.color) {
visited[p.x + xdirection][p.y + ydirection] = true;
mymap[p.x + xdirection][p.y+ ydirection].color = color;
myqueue.add(mymap[p.x + xdirection][p.y+ ydirection]);
}
return;
}
public void bfs(boolean[][] visited, Point[][] mymap, Point p, int color){
Queue<Point> myqueue = new LinkedList<>();
Point temp;
visited[temp.x][temp.y] = true;
myqueue.add(p);
while(!myqueue.isEmpty()){
temp = myqueue.peek();
myqueue.poll();
judge(temp, visited,mymap,1,0, myqueue)
judge(temp, visited,mymap,-1,0, myqueue)
judge(temp, visited,mymap,0,1, myqueue)
judge(temp, visited,mymap,0,-1, myqueue)
}
}
总结
- 思路很简单DFS or BFS都可以,相比之下BFS好一些,一方面是图像大了之后不会因为递归导致栈溢出,同时更加符合应用场景一般都是四周膨胀;
- 写完之后一直被要求优化,能不能优雅简洁一些,一直被吐槽这样的代码不能在生产环境commit上去;
- 上面的代码相比面试当场已经精炼一些了,面试的时候写的更乱一些;
- 后续想到的优化并没有实现:color应该是RGB三通道的;泛型提升程序扩展性;传入参数的初始化处理和异常处理;
结果
大约一个礼拜后收到Thank letter.