Hulu日常实习面经 (SDE/RSDE)
Hulu日常實(shí)習(xí)面經(jīng) (SDE/RSDE)
一面
時(shí)間:2019年4月17日 地點(diǎn):校內(nèi)電話(huà)面試 形式:電話(huà)里交流問(wèn)題,網(wǎng)頁(yè)上寫(xiě)代碼 時(shí)長(zhǎng):1 hour
先簡(jiǎn)單問(wèn)了簡(jiǎn)歷上的項(xiàng)目,面試官是做JavaEE的,簡(jiǎn)歷上寫(xiě)的大多是CV的項(xiàng)目,所以面試官問(wèn)的不多,就問(wèn)了7分鐘。然后就是寫(xiě)代碼:鏈表的歸并排序,要求時(shí)間復(fù)雜度O(nlogn),空間復(fù)雜度O(1). (這是一道LeetCode Medium的題,題目鏈接:148. Sort List) 先說(shuō)思路,面試官覺(jué)得思路ok開(kāi)始寫(xiě)代碼,是在一個(gè)叫nova的共享頁(yè)面上寫(xiě)的,能看到共享者的光標(biāo),面試官的光標(biāo)會(huì)follow你的代碼。我用的Java寫(xiě)的,核心代碼是mergeSort和merge兩個(gè)方法,其他是自己寫(xiě)的測(cè)試代碼:
package firstInterview;class ListNode {int val;ListNode next;public ListNode(int val){this.val = val;} }public class Solution {public static ListNode mergeSort(ListNode head){if (head == null || head.next == null){return head;}ListNode fast = head.next, slow = head;// Compute mid node of list using fast & slow pointer// Every time slow pointer goes 1 step while fast pointer goes 2 steps// Mid node is stored in slow pointerwhile (fast != null){fast = fast.next;if (fast != null){fast = fast.next;slow = slow.next;}}ListNode h2 = mergeSort(slow.next);slow.next = null;ListNode h1 = mergeSort(head);return merge(h1, h2);}public static ListNode merge(ListNode h1, ListNode h2){ListNode p1 = h1, p2 = h2, newHead = new ListNode(0), h = newHead;// newHead: use an auxiliary head for new listwhile (p1 != null && p2 != null){if (p1.val < p2.val){ListNode tmp = p1;p1 = p1.next;h.next = tmp;h = h.next;}else{ListNode tmp = p2;p2 = p2.next;h.next = tmp;h = h.next;}}while (p1 != null){ListNode tmp = p1;p1 = p1.next;h.next = tmp;h = h.next;}while (p2 != null){ListNode tmp = p2;p2 = p2.next;h.next = tmp;h = h.next;}h.next = null;return newHead.next;}/*** generate list from array for debugging* @param arr*/public static ListNode genListFromArray(int[] arr){ListNode head = new ListNode(0), ptr = head;// head: use auxiliary head for new listfor (int i: arr){ptr.next = new ListNode(i);ptr = ptr.next;}return head.next;}/*** print list for debugging* @param head*/public static void printList(ListNode head){ListNode ptr = head;while (ptr != null){System.out.print(ptr.val + " ");ptr = ptr.next;}System.out.println();}public static void main(String[] args){final int[] arr = {4,5,9,1,0,10};ListNode head = genListFromArray(arr);ListNode newHead = mergeSort(head);printList(newHead);} }以上代碼是我面試復(fù)盤(pán)時(shí)候潤(rùn)色過(guò)的,當(dāng)場(chǎng)寫(xiě)的代碼找鏈表中點(diǎn)用的是兩次遍歷,在面試官的提醒下想到了快慢指針并修改了代碼。
大概2周后收到拒信~~
總結(jié)
以上是生活随笔為你收集整理的Hulu日常实习面经 (SDE/RSDE)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 中国车联网行业市场现状分析及投资趋势预测
- 下一篇: 亿阳信通笔试题