Hulu日常实习面经 (SDE/RSDE)
生活随笔
收集整理的這篇文章主要介紹了
Hulu日常实习面经 (SDE/RSDE)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Hulu日常實習面經 (SDE/RSDE)
一面
時間:2019年4月17日 地點:校內電話面試 形式:電話里交流問題,網頁上寫代碼 時長:1 hour
先簡單問了簡歷上的項目,面試官是做JavaEE的,簡歷上寫的大多是CV的項目,所以面試官問的不多,就問了7分鐘。然后就是寫代碼:鏈表的歸并排序,要求時間復雜度O(nlogn),空間復雜度O(1). (這是一道LeetCode Medium的題,題目鏈接:148. Sort List) 先說思路,面試官覺得思路ok開始寫代碼,是在一個叫nova的共享頁面上寫的,能看到共享者的光標,面試官的光標會follow你的代碼。我用的Java寫的,核心代碼是mergeSort和merge兩個方法,其他是自己寫的測試代碼:
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);} }以上代碼是我面試復盤時候潤色過的,當場寫的代碼找鏈表中點用的是兩次遍歷,在面試官的提醒下想到了快慢指針并修改了代碼。
大概2周后收到拒信~~
總結
以上是生活随笔為你收集整理的Hulu日常实习面经 (SDE/RSDE)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国车联网行业市场现状分析及投资趋势预测
- 下一篇: 亿阳信通笔试题