当前位置:   article > 正文

阿里技术专家十五问,真题面试刀刀见肉,走进面试间(答案解析)_技术专家评审面试题目及答案解析

技术专家评审面试题目及答案解析

引言

2020阿里巴巴专家组出题,等你来答:

在这里插入图片描述

题目:如何判断两个链表是否相交

出题人:阿里巴巴新零售技术质量部

参考答案

$O(n^2)$: 两层遍历,总能发现是否相交

$O(n)$: 一层遍历,遍历完两个链表,如果两个链表的最后一个结点指针相同,则相交,否则不相交

题目:一颗现代处理器,每秒大概可以执行多少条简单的MOV指令,有哪些主要的影响因素?

出题人:阿里巴巴出题专家:子团/创新产品虚拟化&稳定性资深技术专家

参考答案

及格: 每执行一条mov指令需要消耗1个时钟周期,所以每秒执行的mov指令和CPU主频相关。

加分: 在CPU微架构上,要考虑数据预取,乱序执行,多发射,内存stall(前端stall和后端stall)等诸多因素,因此除了cpu主频外,还和流水线上的效率(IPC)强相关,比较复杂的一个问题。

题目:如何实现一个高效的单向链表逆序输出?

出题人:阿里巴巴出题专家:昀龙/阿里云弹性人工智能负责人

参考答案:下面是其中一种写法,也可以有不同的写法,比如递归等。供参考。

typedef struct node{
    int           data;
    struct node*  next;
    node(int d):data(d), next(NULL){}
}node;

void reverse(node* head)
{
    if(head == NULL){
        return;
    }

    node* pleft = NULL;
    node* pcurrent = head;
    node* pright = head->next;

    while(pright){
        pcurrent->next = pleft;
        node *ptemp = pright->next;
        pright->next = pcurrent;
        pleft = pcurrent;
        pcurrent = pright;
        pright = ptemp;
    }

    while(pcurrent != NULL){
        cout<< pcurrent->data << "\t";
        pcurrent = pcurrent->next;
    }
}
  • 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
class Solution<T> {

    public void reverse(ListNode<T> head) {
       if (head == null || head.next == null) {
           return ;
       }
       ListNode<T> currentNode = head;
       Stack<ListNode<T>> stack = new Stack<>();
       while (currentNode != null) {
           stack.push(currentNode);
           ListNode<T> tempNode = currentNode.next;
           currentNode.next = null; // 断开连接
           currentNode = tempNode;
       }

       head = stack.pop();
       currentNode = head;

       while (!stack.isEmpty()) {
           currentNode.next = stack.pop();
           currentNode = currentNode.next;
       }
    }
}

class ListNode<T>{
    T val;
    public ListNode(T val) {
        this.val = val;
    }
    ListNode<T> next;
}
  • 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

题目:已知 sqrt (2

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

闽ICP备14008679号