字节2面(伪)凉经
一面面试官人确实挺好的。二面的题不难,但是问的比较有深度,还是基础太差了
一面:
-
IO多路复用
-
进程和线程
-
进程通信的方式
-
四次挥手过程
-
ConcurrentHashMap
-
笔试题
(1)32GB的文件,1GB内存,怎么实现排序
(2)拓扑排序
二面:
栈实现队列
-- 正确性证明(实在不知道这个正确性是怎么证明)
-- 时间复杂度优化(优化后,但是不知道怎么计算)
-- 时间复杂度计算
--多线程环境下顺序保证
再贴一个优化后的代码吧
public class MyQueue {
Deque<Integer> stack1;
Deque<Integer> stack2;
/**
* Initialize your data structure here.
*/
public MyQueue() {
stack1 = new LinkedList<>();
stack2 = new LinkedList<>();
}
/**
* Push element x to the back of queue.
*/
public void push(int x) {
stack1.push(x);
}
/**
* Removes the element from in front of queue and returns that element.
*/
public synchronized int pop() {
if(!stack2.isEmpty())
return stack2.pop();
while (!stack1.isEmpty())
stack2.push(stack1.pop());
return stack2.pop();
}
/**
* Get the front element.
*/
public synchronized int peek() {
if(!stack2.isEmpty())
return stack2.peek();
while (!stack1.isEmpty())
stack2.push(stack1.pop());
return stack2.peek();
}
/**
* Returns whether the queue is empty.
*/
public boolean empty() {
return stack1.isEmpty() && stack2.isEmpty();
}
}