Meituan comments on the written examination questions of 2020 school enrollment system development direction

Time:2021-1-9

1 / 10 [question and answer]

Title Description

If the load of a virtual machine on the line is too high, how to quickly check the cause? Just introduce the idea and the Linux commands involved.

answer

The reasons for high CPU load: the increase of the number of full GC, the existence of bugs in the code (such as dead loops, improper use of regularization, etc.) may cause high CPU load.1. jps -v: View java process number2. top -Hp [Java process number]: view the most expensive data in the current processCPUThread of3. printf "%x\n" [step2Thread number in]: get the thread's16Hexadecimal representation4. jstack [Java process number] | grep -A100 [step3Results]: view the thread stack and locate the line of code.

2 / 10 [question and answer]

Title Description

Please briefly describe the hit rules of MySQL database union index, and give an example.

answer

1) MySQL union index follows the leftmost prefix matching rule, that is, matching from the leftmost column of the union index to the right until the matching termination condition is met. For example, the union index(col1, col2, col3),Where condition is col1=`a` AND col2=`b`That can hit the union index(col1,col2)Prefix part,Where condition is col2=`b` AND col3=`c`The union index cannot be hit because it does not match the leftmost prefix.2) The matching termination condition is the range operator(as>, <, between,Like et al)Or functions that cannot be indexed. For example, the union index(col1, col2, col3),Where condition is col1=`a` AND col2>1 AND col3=`c`, For range query on col2 column, matching will terminate, only col1 will be matched, not col2(col1, col2, col3).
3) The order in the where condition does not affect index hits. For example, the union index(col1, col2, col3),Where is col3=`c` AND col2=b AND col1=`a`, MySQL optimizer will optimize itself to hit the union index(col1, col2, col3).

3 / 10 [question and answer]

Title Description

What is a distributed transaction and what are the reasons for it? What are the solutions for distributed transactions? What are the advantages and disadvantages?

answer

Distributed things: a large operation is divided into many small operations. These small operations are located on their respective servers. Distributed things need to ensure that these small operations are either all successful or all failed.1.In order to solve the problem of inconsistent data in different database operations.2.applicationSOAWords.1.2PC: two phase submission2.3PC:Three stage submission3.Compensation services(TCC)1)Performance improvement,2)The data are consistent,3)Higher reliability

4 / 10 [question and answer]

Title Description

Please describe the request process of HTTPS.

answer

1)The client initiates a call to the serverHTTPSRequest to connect to the server443Port;2)The server side has a key pair, namely public key (digital certificate) and private key, which are used for asymmetric encryption. The server side keeps the private key and cannot disclose it. The public key can be sent to anyone;3)The server sends its own public key to the client;4)After receiving the public key of the server, the client checks its validity. If it is found that there is a problem with the public key, thenHTTPSIf the public key is qualified, the client will generate a client key, and then use the server's public key to asymmetrically encrypt the client key into ciphertext,HTTPSThe first time in historyHTTPEnd of request;5)Client initiatedHTTPSThe second inHTTPRequest to send the encrypted client key to the server;6)After receiving the ciphertext from the client, the server will use its private key to decrypt it asymmetrically. The decrypted plaintext is the client key, and then use the client key to encrypt the data symmetrically, so that the data becomes ciphertext;7)Then the server sends the encrypted ciphertext to the client;8)The client receives the ciphertext sent by the server, decrypts it symmetrically with the client key, and gets the data sent by the server. suchHTTPSThe second inHTTPRequest end, entireHTTPSTransmission complete.

5 / 10 [question and answer]

Title Description

What is transactional communication? Do you know the propagation types in spring transactions? How to use / specify propagation type?

1)Transaction propagation is used to describe how a transaction propagates when a method modified by transaction propagation behavior is nested into another method. It is often used to define how to continue execution when transaction nesting occurs.2)Spring defines7The details of the transaction propagation types are shown in the table below3~4There are three common types) PROPAGATION_REQUIRED: open a new transaction when there is no transaction, and join if there is one;) PROPAGATION_REQUIRES_NEW: force to open a new transaction and suspend an existing transaction (if any);) PROPAGATION_SUPPORTS: Join when there is a transaction, and execute in non transaction mode if there is no transaction;) PROPAGATION_NOT_SUPPORTED: execute in non transactional mode, suspend the current transaction (if any);3)This can be done in comments orXMLThe propagation type is specified in [email protected]Transactional(Propagation=xxx)

6 / 10 [question and answer]

Title Description

The difference between reactor and Proactor in io design.

1Reactor passively waits to indicate the arrival of an event and makes a response. There is a waiting process. Everything you do should be put into the listening event collection and wait for the handler to be available before operation. The implementation is relatively simple, and it is more efficient for the short-time processing scenario. However, the long-time operation of reactor processing will cause the blocking of event distribution and affect the subsequent event processing.2Proactor directly calls asynchronous read-write operations and returns immediately after calling, which realizes an active event separation and distribution model. This design allows multiple tasks to be executed concurrently, thus improving throughput. It can also execute long-time tasks (each task does not affect each other). Proactor has higher performance and can handle long-time concurrent scenarios, but Proactor implements logic At present, there are few operating systems that implement pure asynchronous operation, such as windowsIOCPHowever, due to the limitation of its Windows system used for server, its application scope is small at present/Linux system has limited support for pure asynchrony, and the mainstream of event driven application is still through select/Epoll.

7 / 10 large number addition

Link:www.nowcoder.com/questionTerminal/…

Read in two numbers in the form of string, and then output the sum of two numbers in the form of string.

Input Description:

Enter two lines for two numbers a and B,-109 <= a , b <= 109, in double quotation marks.

Output Description:

Output a+B in double quotation marks.

Example 1

input

"-26"
"100"

output

"74"

answer

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        String num1 = in.nextLine().split("\"")[1];
        String num2 = in.nextLine().split("\"")[1];
        int sum = Integer.parseInt(num1)+Integer.parseInt(num2);
        System.out.println("\""+""+sum+"\"");
    }
}

8 / 10 palindrome substring

Link:www.nowcoder.com/questionTerminal/…

Given a string, your task is to calculate how many palindromic substrings there are in the string (palindromic string is a string with the same forward reading and reverse reading).

Palindrome strings with different start or end positions are counted as different substrings even if they are composed of the same characters.

Input Description:

The input contains only one string and is no longer than1000

Output Description:

The output contains only one non negative integer, which represents how many palindrome substrings the input string has.

Example 1

input

abc

output

3

Example 2

input

aaa

output

6

answer

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.nextLine();
        int count = 0;
        StringBuilder sb=null;
        for (int i = 0; i < s.length(); i++) {
            for (int j = i; j < s.length(); j++) {
                sb = new StringBuilder(s.substring(i,j+1));
                if(sb.toString().equals(sb.reverse().toString())){
                    count++;
            }
            }
        }
        System.out.println(count);
    }
}

9 / 10 merge gold coin

Link:www.nowcoder.com/questionTerminal/…

There are n piles of gold coins in a row, and there are C [i] pieces in the I pile. Each merger will merge two adjacent piles of gold coins into one pile, and the cost is the sum of the two piles of gold coins. After n-1 merging, all the gold coins were finally merged into a pile. Please find out the lowest cost of merging gold coins into a pile.

Among them, 1 < = n < = 30, 1 < = C [i] < = 100

Input Description:

Enter a number on the first lineNIt means yesNInput the second line of heap gold coinNA number represents the number of gold coins in each pileC[i]

Output Description:

Output a numberSRepresents the minimum cost of merging into a pile

Example 1

input

4
3 2 4 1

output

20

Example 2

input

30
10 20 30 40 50 60 70 80 90 100 99 89 79 69 59 49 39 29 19 9 2 12 22 32 42 52 62 72 82 92

output

7307

answer

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] money = new int[n+1];
        int[] preSum = new int[n+1];
        for(int i = 1; i <= n; i++){
            money[i] = sc.nextInt();
            if(i == 1) {
                preSum[i] = money[i];
            }
            else {
                preSum[i] = preSum[i-1] + money[i];
            }
        }
        sc.close();

        int[][] dp = new int[n + 1][n + 1];
        for(int len = 2; len <= n; len++){
            for(int i = 1; i <= n - len + 1; i++){
                int j = i + len - 1;
                dp[i][j] = Integer.MAX_VALUE;
                int sum = preSum[j] - preSum[i - 1];
                for(int k = i; k < j; k++){
                    dp[i][j] = Math.min(dp[i][j],dp[i][k] + dp[k + 1][j] + sum);
                }
            }
        }
        System.out.println(dp[1][n]);
    }
}

Minimum unique prefix

Link:www.nowcoder.com/questionTerminal/…

Given a group of strings, find the smallest prefix for each string that can uniquely identify the string.

Input Description:

In the first line, enter an integer n to indicate the number of strings, followed by N lines, one string for each line, a total of n different strings. (2 <= n <= 100, string length not more than100

Output Description:

Output n lines, each line of a string, in turn, is the smallest uniquely identifiable prefix of each string

Example 1

input

5
meituanapp
meituanwaimai
dianpingliren
dianpingjiehun
mt

output

meituana
meituanw
dianpingl
dianpingj
mt

remarks:

If a stringSIs another stringTThe prefix of, thenSThe minimum recognizable prefix for isS

answer

import java.util.Scanner;  
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        String[] strings = new String[N];
        for (int i = 0; i < N; i++)
            strings[i] = scanner.next();
        scanner.close();
        for (String s : strings)
            System.out.println(unique(s, strings));
    }
    //Returns the shortest unique prefix of string s in string array strings
    private static String unique(String s, String[] strings) {
        //Prefix initial first character
        String prefix = s.substring(0, 1);
        for (String single : strings) {
            //Skip the string s itself
            if (single.equals(s)){
                continue;
            }
            //The prefix is contained by other strings and continues to increase the length
            while (single.indexOf(prefix) == 0 && prefix.length() < s.length()) {
                prefix = s.substring(0, prefix.length()+1);   
            }
        }
        return prefix;
    }
}

This work adoptsCC agreementReprint must indicate the author and the link of this article