深入解析:5年社招后端面试经验分享,涵盖百度、阿里等大厂面试要点与技巧

面试经历概述

在2023年底参加了一些面试,遗憾的是他未能记住所有细节,但仍然分享了不少有价值的内容。本文将从他的视角出发,以第一人称叙述,内容的真实性和技术性值得信赖。

百度面试经历

云雨雪的第一场面试在百度进行。此时,他的简历与职位描述高度契合,HR的热情让他难以拒绝。面试采用百度自研的如流会议软件,提供了良好的编程环境。面试主要围绕日志分析和大数据技术栈展开,云雨雪在紧张中忘记记录具体的面试细节。

一面时印象深刻的题目是关于在内存不足的情况下,如何从一个庞大的日志文件中找出Top N个搜索词。以下是他的解决思路:

import java.io.BufferedReader;  
import java.io.File;  
import java.io.FileReader;  
import java.util.*;

public class Baidu {  
    public static List<String> findTopNWords(File inputFile, int n) {  
        List<String> topNWords = new ArrayList<>();  
        Map<String, Integer> wordCountMap = new HashMap<>();  
        
        try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) {  
            String line;  
            while ((line = reader.readLine()) != null) {  
                String[] words = line.split("\\s+");  
                for (String word : words) {  
                    wordCountMap.put(word, wordCountMap.getOrDefault(word, 0) + 1);  
                }  
            }  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  

        PriorityQueue<Map.Entry<String, Integer>> maxHeap =  
                new PriorityQueue<>((e1, e2) -> e2.getValue().compareTo(e1.getValue()));  
        for (Map.Entry<String, Integer> entry : wordCountMap.entrySet()) {  
            maxHeap.offer(entry);  
        }  
        
        for (int i = 0; i < n && !maxHeap.isEmpty(); i++) {  
            topNWords.add(maxHeap.poll().getKey());  
        }  
        
        return topNWords;  
    }  

    public static void main(String[] args) {  
        File inputFile = new File("D:/topn.txt");  
        int topN = 10;  
        List<String> topNWords = findTopNWords(inputFile, topN);  
        System.out.println("TopN搜索词列表:");  
        for (String word : topNWords) {  
            System.out.println(word);  
        }  
    }  
}

云雨雪表示,百度的面试过程严谨,问了很多与Elastic Search相关的技术问题,整体面试体验令人满意。虽然面试时间紧迫,他还是顺利通过了第一轮,并在第二天接到了二面的通知。

在二面中,问题的设置以场景题和项目讨论为主。他记得的一道代码题是关于生产者消费者模型的实现:

import java.util.Queue;  
import java.util.concurrent.*;  
import java.util.concurrent.atomic.AtomicInteger;  

public class ProducerConsumerExample {  
    public static void main(String[] args) {  
        Queue<Integer> queue = new ConcurrentLinkedQueue<>();  
        ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 100, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1000));  
        AtomicInteger ai = new AtomicInteger(0);  

        for (int i = 0; i < 2; i++) {  
            executor.submit(new Producer(queue, ai));  
        }  
        for (int i = 0; i < 2; i++) {  
            executor.submit(new Consumer(queue));  
        }  
        executor.shutdown();  
    }  

    static class Producer implements Runnable {  
        private final Queue<Integer> queue;  
        private final AtomicInteger value;  

        public Producer(Queue<Integer> queue, AtomicInteger value) {  
            this.value = value;  
            this.queue = queue;  
        }  

        @Override  
        public void run() {  
            while (true) {  
                int val = value.incrementAndGet();  
                System.out.println("Produced: " + val);  
                queue.offer(val);  
                try {  
                    Thread.sleep(1000);  
                } catch (InterruptedException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
    }  

    static class Consumer implements Runnable {  
        private final Queue<Integer> queue;  

        public Consumer(Queue<Integer> queue) {  
            this.queue = queue;  
        }  

        @Override  
        public void run() {  
            while (true) {  
                Integer value = queue.poll();  
                if (value != null) {  
                    System.out.println("Consumed: " + value);  
                }  
                try {  
                    Thread.sleep(10);  
                } catch (InterruptedException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
    }  
}

在经过二面后,HR告诉云雨雪很遗憾职位已经满员,而他得知这一消息的原因是百度正面临裁员。尽管如此,他依然感觉百度的面试体验非常良好。

阿里面试经历

在阿里健康的面试中,自我介绍和项目分享结束后,面试官直接给了云雨雪一沓试卷,云雨雪感到有些压力,因为这通常意味着面试官对他的经历并不满意。面试的主要内容是五道题目,包括两道代码题、一道场景设计和两道SQL题。以下是其中一道代码题的实现:

System.out.println(Arrays.toString(bubbleSort(new int[]{64, 34, 25, 12, 22, 11, 90})));  

private static int[] bubbleSort(int[] array) {  
    int n = array.length;  
    for (int i = 0; i < n - 1; i++) {  
        for (int j = 0; j < n - i - 1; j++) {  
            if (array[j] > array[j + 1]) {  
                int temp = array[j];  
                array[j] = array[j + 1];  
                array[j + 1] = temp;  
            }  
        }  
    }  
    return array;  
}

在场景设计题中,云雨雪被问及百万订单的分流策略,这部分他回答得不够理想。他意识到,面试官更希望从实际经验出发,不只是理论分析,因此需要改进这一方面的准备。

在SQL题方面,他感到有些生疏,因其多用ORM框架,面对简单的联表查询时略显紧张。尽管如此,他还是努力完成了题目。

阿里二面

有时面试的结果令人意外,云雨雪在自我介绍后又被问及与JD相关的具体技术问题,但他发现自己对这些内容没有足够的准备。他列举了一些一致性方案,数据倾斜的处理方法等,但由于与JD不符,最终未能通过。