Skip to main content

字节跳动-国际电商二面8.26

·147 words·1 min
WFUing
Author
WFUing
A graduate who loves coding.

无自我介绍,然后简单问简历里你觉得哪些是你的亮点。说了中间件。

  1. 问kafka怎么实现可靠性?
  2. 问怎么设计一个批处理订单的rpc接口?
  3. 问redis的分布式锁?
  4. 问分库分表注意点
  5. 问项目细节,怎么设置价格的mysql变量?

sql题

SELECT name, AVG(score) AS average_score
FROM scores
GROUP BY name
ORDER BY average_score DESC;

算法题,秒了

import java.util.Arrays;
import java.util.Comparator;

public class VersionComparator {

    public static void main(String[] args) {
        String[] versions = {"1.45.0", "1.5", "6", "3.3.3.3.3.3.3"};
        Arrays.sort(versions, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return compareVersions(o1, o2);
            }
        });
        
        System.out.println("Sorted versions: " + Arrays.toString(versions));
    }

    private static int compareVersions(String v1, String v2) {
        String[] vals1 = v1.split("\\.");
        String[] vals2 = v2.split("\\.");
        int length = Math.max(vals1.length, vals2.length);

        for (int i = 0; i < length; i++) {
            // Convert the substring to integers to compare
            int val1 = i < vals1.length ? Integer.parseInt(vals1[i]) : 0;
            int val2 = i < vals2.length ? Integer.parseInt(vals2[i]) : 0;

            if (val1 < val2) {
                return -1;
            } else if (val1 > val2) {
                return 1;
            }
        }
        return 0;
    }
}