Jingdong has two face-to-face discussions

I received a second phone call from JD.com. I felt that this interview had a certain breadth and depth. I also had some arguments with the interviewer. It was a very interesting interview, so I recorded it in detail.


Facial Sutra:

First of all, the interviewer asked me to introduce myself. After a total of about four or five phone interviews, I have encountered such a problem many times, but I still briefly expressed my skill stack and it was over. This In fact, a lot more could be said.

Then the interviewer asked about my learning process (I didn't understand what the interviewer meant by the learning process at first, but later I learned that it was my own educational experience). Then I expressed my status as a third-year software engineering student at Dalian University of Technology.

Then the interviewer asked me what my required courses were. I talked about computer networks, operating systems, data structures and algorithms, and compilation principles. The interviewer was very interested in my computer basics and said that my written test score was very high (Jingdong had a written test before), but in fact I only got AC two of the three algorithm questions on Jingdong.. Dingtian can only be 80 Now, maybe it's better to do multiple-choice questions? So the interviewer began to examine my computer foundation.

Interviewer: Do you understand common sorting algorithms?

Me: Well, have some understanding. Common sorting algorithms can be divided into three time complexities, O(n+k), O(nlog2n), and O(n^2). O(n^2) sorting such as bubble sort, O(nlog2n) sorting such as quick sort, merge sort, binary insertion sort, for comparison-based sorting algorithms, this time complexity can no longer be lower, then O(n +k) Sorting of time complexity such as bucket sorting, radix sorting, counting sorting (maybe the complexity of this place is too much. The interviewer asked me about the time complexity for a long time).

Interviewer: Well, I understand what you mean, you know more about sorting. Can you say something about common data structures?

Me: Can I give an example of how data structures are embodied in Java?

Interviewer: I think the emmm data structure should have nothing to do with the language...

Me: Well then, I thought you wanted to hear more about data structures in Java. Common data structures are simple linked lists, queues, stacks, and binary trees, and slightly more complex ones such as B+, B-, B*, red-black trees, and graphs.

Interviewer: Now there are 10w numbers, how do you find the largest number?

Me: Heap (don't know how to say this answer... fascinated). (At that time, my brain was a little twitchy, and this is quite confusing with the following questions related to data structures)

Interviewer: blablabla said something, generally speaking, don't you think the time complexity is a bit high?

Me: (suddenly realized) You can actually find the maximum value by traversing the O(n) time complexity once, updating the maximum value with a temp variable until all numbers are traversed.

Interviewer: (interrupting me) You don't need to be too detailed, it's just a bubbling, right? How to find the largest top 20 numbers for 10w numbers?

Me: In this place, I think the maximum heap can be used (the brain is pumped, why is the maximum heap), and this problem can be solved in O(nlog2n) time complexity.

Interviewer: (strangely) Why the max heap?

Me: You can build a maximum heap with 20 nodes. After traversing all the data, the node that stays in the heap is the top 20 (I still didn't respond at the time).

Interviewer: So if the elements in the heap are 1, 2, 3, ..., 20 now, and you have a 19 node, do you put it in or not?

Me: (I still haven't reacted that it is not the largest heap but the smallest heap) I think the root node of the heap can be replaced with 19, and then adjust the position to determine whether 19 is still in the heap in the end.

Interviewer: Then your behavior is embarrassing. Do you need to put each node in the heap and adjust it? Doesn't it feel very wrong?

Me: (still didn't respond) I think it is possible to encapsulate the data structure of this maximum heap and add the maximum and minimum properties.

Interviewer: Can you tell me the definition of max heap?

Me: (To be honest, I forgot how I answered it at the time, I was wrong)

Interviewer: No, the definition of max heap is like this, for a node, the value of its child nodes is not greater than his value of a complete binary tree. right?

I'm right...

Interviewer: (Maybe I can't guide me to the correct answer) Why don't you use the minimum heap in this place? Whenever you need to check whether a node can be put into the heap, why not just look at the value of this node and the value of the root node?

Me: (suddenly realized..) Hmm.. that's it

Interviewer: Then let's talk about time complexity. What do you think is the average complexity of this algorithm?

Me: The process of building the heap is O(n), and then the time complexity of putting in each node adjustment is O(nlog2n).

Interviewer: (surprised) Why building a heap is O(n), can you prove it?

我:(我也吃惊..那个一长串的求和公式化简就是O(n)线性时间复杂度,这个在电话里面说不清楚..听到这个问题我楞了一下)我觉得这个问题很难说啊..但是可以用数学公式证明建堆过程的确是O(n)时间复杂度。

面试官:不对,建堆过程应该是O(nlog2n)时间复杂度,你如果硬要说是O(n)你可以证明吗?

我:(这个怎么在电话里证明..有一些绝望)这个确实在电话里很难证明,但是我觉得建堆确实是O(n)时间复杂度。

面试官:不对,我可以明确地告诉你,建堆是O(nlog2n)时间复杂度,你下来可以查一下。

我:(还是坚持建堆是O(n)时间复杂度)我还是觉得建堆的确是O(n)时间复杂度,当然我可能记错了,但是我还是希望我们能下来确认一下,建堆的确是O(n)时间复杂度。

面试官:(我感觉面试官有些无奈了)你之前说过基于比较的排序时间复杂度上限是O(nlog2n),这样的话岂不是你自己的话就自相矛盾了。

我:(我也有点懵了,觉得不应该再争论下去,本质上还是自己知识不过硬)那可能我记错了...

面试官:(突然一愣)是不是你说的建堆和我说的建堆不一样,你是不是把建堆想成将20个元素放入到堆中但是不调整啊?那样的确是O(n),但是我们这里说的建堆是建好这个堆,不只是放进去。

我:(其实争论了挺久,文字上看不出来这么长的时间,我也有点动摇。本质上还是自己知识不过硬,我动摇了。)恩,那可能我建堆概念理解错了。

(我下来仔细确认了这个建堆时间复杂度的问题,并不能说谁对谁错。从空堆开始,依次插入各个关键码,这个时间复杂度确实是O(nlog2n)。但是事实上有一种叫做筛选法的建堆方法,完全二叉树大小为n,对于结点编号(从0开始作为第一个)为n/2-1的结点开始,判断这个结点为根的的子树是否满足最大堆性质。满足,不做调整;不满足,做出调整。直到从n/2-1到结点0,整个完全二叉树就变成了堆。时间复杂度为(2^i)*(log2n-i)从i=0到i=log2n进行求和,时间复杂度趋于线性,也就是O(n)。关键在于我们理解的建堆算法出现了差异,所以对建堆复杂度的理解产生了一些不一样的看法。但是由于本质上还是自己基础不扎实,不敢继续争论下去,所以与真理擦肩而过...)

面试官:好,那么现在我们达成了一个共识,建堆是O(nlog2n)时间复杂度,基于这个共识,我们来看下面的问题。10w数据,选出top 20,使用最小堆,时间复杂度是多少?

我:nlog2n。

面试官:详细一点,比如n是多少?

我:100000log2 20

面试官:好,那么如果前20个结点就是top20,时间复杂度是多少,以建堆时间复杂度为O(nlog2n)为基础。

我:O(n)   (我这个回答很粗...)

面试官:(可能还是想引导一下我的正确答案)前20个结点建堆时间复杂度是多少?

我:20log2 20

面试官:那后面10w-20个结点呢?

我:O(n)

面试官:那总的时间复杂度是不是20log2 20 + 99980?

我:是的。

面试官:好,那么我们接下来来看看计算机网络吧。你能说一下TCP的三次握手吗?

我:(回答不详细写了,这个问题太常见了)....

面试官:那你能说一下断开连接的四次挥手吗?

我:(同 略)....

面试官:嗯,那么比如我现在在浏览器敲入www.baidu.com,并且在搜索框中输入了词条,点击搜索,整个过程发生了什么呢?

我:首先会进行DNS解析,将www.baidu.com解析为一个IP地址...

面试官:(打断了我)什么是DNS?

我:DNS是域名解析协议,运行在53端口号,主机会对代理服务器发出递归的解析请求,然后这个代理域名解析服务器会向其他服务器发出迭代的解析请求。

面试官:好,那么DNS是一定会发生的吗?

我:不是的,存在浏览器缓存、主机缓存、服务器缓存,甚至还有Hosts文件。

面试官:嗯,事实上www.baidu.com这样的域名在代理服务器一定是有缓存的。那么接下来发生了什么呢?

我:域名解析出来了ip地址,同时也解析出来了端口号,主机就会向这个主机对于端口号建立连接,然后传输数据...

面试官:(打断了我)等一下,这样说的话所有用户都是连接同一个主机,像www.baidu.com这样的网站,一台主机根本不可能让他维持在6个9可用率上(这个我解释一下,就是99.9999%的可用率)。

我:(这个我是真的不了解,但是我还是猜了一下)这个我可能不太了解,但是我觉得这个ip每次解析出来对应的一定不是同一台主机,可能这是一个集群,只不过是通过了DNS解析返回了不同的ip,或者做了反向代理什么的。

面试官:blablabla(说了一堆东西....我其实记不太清了,但是我觉得面试官在这个方面应该是个专家...)

面试官:那现在假如建立了连接,服务器端发送完数据了,现在还要发送,会怎样呢?

我:我觉得这个主要是看这里是长连接还是短连接。HTTP头部有一个Connection字段,当为close的时候为短连接,为keep-alive的时候为长连接。短连接则需要重新建立连接传输数据,否则就在当前连接上传输数据。

面试官:恩。你自己做过一些项目吗?

我:blablabla (说了一点)

面试官:那现在给你一个真实场景,嘀嘀打车,你如果需要客户下单,然后司机接单,你来实现,会怎么实现?

我:(感觉可能面试官想考察我的高并发程序涉及思路)这是一个高并发场景吗?

面试官:不,就考虑最基础的。

我:那么我觉得可以用生产者-消费者模型来实现...

面试官:(再次打断了我)太粗糙了,说说细节。

我:将用户的唯一标识、出发时间、出发地点、到达地点包装成一个请求实体,放入到队列中,然后司机从队列中取出,返回一个已收到并且确认订单的信息。

面试官:(可能不太满意,但是还是没深究这个问题)那么这个请求你用什么协议来发送呢?

我:TCP

面试官:为什么是TCP?HTTP不好吗?比如现在微信,你觉得是用TCP吗?

我:(不敢乱说)我觉得不一定,可能是其他协议,但是一定有自己的方法保证传输的可靠性。

面试官:(我感觉他不满意)好吧,你后面想读研吗?

我:暂时没有这个打算(后面说了一些自己的看法)。

面试官:你的实习时间可以是多长?

我:都可以。

面试官:恩,那我的问题就问完了,你有什么想问我的吗?


我其实在面试的过程中一直觉得面试官思维敏捷,知识面很广,就忍不住问了一下面试官的履历...结果发现面试官08年毕业,在外企干了一段时间,自己创业过,百度干过三年,腾讯干过三年,后来积累了许多云相关的知识,想要做一些相关工作。自己也拿到了阿里云、腾讯云、京东云的offer,但是自己觉得阿里云和腾讯云都是体系很成熟了,于是选择了京东云,毕竟京东云是从16年才开始认认真真做起来的。然后面试官和我说了一下他的看法,他觉得自己还是想在一个技术不是那么成熟的地方认真做,而不是去一个技术很成熟的地方去修修补补。面试官在最后说了很多,确实也觉得面试官很有想法而且很厉害。最后面试就结束了。


感觉和这些优秀的前辈交流确实是一件很开心也很值得的事,通过一次面试得到了很多东西,看到了自己的不足,也看到了一位前辈的技术履历和独到的看法。


确认复试已通过,等候HR面。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324683070&siteId=291194637