当前位置:   article > 正文

Hulu面试(或许待更)

hulu面试

2022/1/5
首先是电面,时长一小时。
自我介绍+项目介绍+实习内容+中间穿插问题。
coding:反转链表、k个一组翻转链表(lc原题改进,不同之处在于不满k个也要反转,细节比较多)

#include <iostream>
using namespace std;
// 链表反转
struct ListNode{
    int val;
    ListNode* next;
    ListNode():val(0),next(NULL){}
    ListNode(int x,ListNode* next):val(x),next(next){}
};
ListNode* reverseList(ListNode* head){
    ListNode* prev = NULL;
    ListNode* curr = head;
    while(curr){
        ListNode* next = curr->next;
        curr->next = prev;
        prev= curr;
        curr = next;
    }
    return prev;
}
ListNode* NreverseList(ListNode* head,int N){
    ListNode* slow = nullptr;
    ListNode* fast = nullptr;
    ListNode* newhead = new ListNode();
    ListNode* curr=newhead;
    while(head){
        slow = head;
        fast = head;
        int count =N;
        while(count>1 && fast->next){
            fast = fast->next;
            count--;
        }
        head = fast->next;
        fast->next = NULL;
        curr->next = reverseList(slow);
        curr = slow;
    }
    curr->next = head;
    return newhead->next;

}
int main(){
    ListNode* head = new ListNode(1,NULL);
    ListNode* first = new ListNode(2,NULL);
    ListNode* second = new ListNode(3,NULL);
    ListNode* third = new ListNode(4,NULL);
    ListNode* fourth = new ListNode(5,NULL);
    ListNode* fifth = new ListNode(6,NULL);
    ListNode* sixth = new ListNode(7,NULL);
    ListNode* seventh = new ListNode(8,NULL);
    head->next = first;
    first->next = second;
    second->next=third;
    third->next= fourth;
    fourth->next = fifth;
    fifth->next = sixth;
    sixth->next = seventh;

    ListNode* newhead;

    int N =3;
    newhead = NreverseList(head,N);
    ListNode* curr = newhead;
    while(curr){
        cout<<curr->val<<" ";
        curr = curr->next;
    }

}


// 1,2,3,4,5,6,7,8   3  => 3,2,1,6,5,4,8,7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

面试官人很好,面试体验很好。
——————————————————————————
然后是一面,
coding:给定仅由0和若干个1组成的数组,仅修改两个0为1,让1和1之间的最小距离最大,值为多少?
/*
[0,1,0,1,0,1] min_dist = 1
[1, 0, 0, 0, 0, 0, 1] min_dist = 5
[0,0, 0, 1, 0, 0, 0, 0, 0, 1, ]
[1, 0, 1, 0, 1, 0, 1] min_dist = 1
[1, 1, 0, 0, 1, 0, 1] min_dist = 0
*/

——————————————————————————
然后是二面:
sql索引(这里整理一下)

c++中的static(这里也整理一下)

coding:连续子数组的最小和

连续子数组绝对值的最小和

后面的两轮个人原因因为自己真的状态不好,就到此为止了。

最后补充一道另一家公司的题目:
给出一个元素无序的数组,求出一个数,使得其左边的数都小于它,右边的数都大于等于它。要求时间复杂度为O(n)。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/227700
推荐阅读
相关标签
  

闽ICP备14008679号