2020 Autumn Recruitment Xiaomi Software Development Written Test Questions

Question structure

10 single choice
10 multiple choice
2 programming

Single-choice and multiple-choice questions, the difficulty is not high but basic.

programming questions

1. Determine whether the password meets the requirements:
Give a line of password: each password is separated by a space
(1) if it has uppercase, lowercase, symbols, and numbers at the same time, then output 0;
(2) if the length is not between 8-120, then output 1;
(3) If the type does not meet the output, that is, if it does not meet the condition of (1), then output 2;

2. Leetcode 79 Original Title: Word Search
Given a 2D grid and a word, find out if the word exists in the grid.

Words must be formed alphabetically, through letters in adjacent cells, where "adjacent" cells are those that are horizontally or vertically adjacent. Letters in the same cell are not allowed to be used repeatedly.

train of thought

The first question is regular, but the type should be written separately, just mark 4 states.
The second question DFS+ backtracking, the key point is to unify capitalization.

the code

1. It only passed 83%. The problem is that the symbol forgot how to express it. The symbol directly else is fine. .
100% code posted by others.

#include <bits/stdc++.h>

using namespace std;

int Process(string &code) {
    
    
	int n = code.length();
	if (n < 8 || n>120) return 1;
	bool num = false, symbol = false, D = false, X = false;
	for (int i = 0; i < n; ++i) {
    
    
		if (num == true && symbol == true && D == true && X == true) return 0;
		if (code[i] >= '0' && code[i] <= '9') num = true;
		if (code[i] >= 'a' && code[i] <= 'z') X = true;
		if (code[i] >= 'A' && code[i] <= 'Z') D = true;
		else symbol = true;
	}
	return 2;
}

int main()
{
    
    
	vector<string> str;
	string s = "";
	while (cin >> s) {
    
    
		str.emplace_back(s);
	}
	vector<int> ret;
	for (auto &s : str) {
    
    
		ret.emplace_back(Process(s));
	}
	for (auto &v : ret)
		cout << v << "\n";
}

2. It should be 100% AC, but there is something wrong with Xiaomi's question, and I didn't notice it in the announcement less than half an hour ago. . It's a bit embarrassing.
Written in python.

class Solution:
    def exist(self, board: List[List[str]], word: str) -> bool:
        row = len(board)
        col = len(board[0])

        def helper(i, j, k, visited):
            #print(i,j, k,visited)
            if k == len(word):
                return True
            for x, y in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
                tmp_i = x + i
                tmp_j = y + j
                if 0 <= tmp_i < row and 0 <= tmp_j < col and (tmp_i, tmp_j) not in visited \
                and board[tmp_i][tmp_j] == word[k]:
                    visited.add((tmp_i, tmp_j))
                    if helper(tmp_i, tmp_j, k+1, visited):
                        return True
                    visited.remove((tmp_i, tmp_j)) # 回溯
            return False
        
        for i in range(row):
            for j in range(col):
                if board[i][j] == word[0] and helper(i, j, 1,{
    
    (i, j)}) :
                        return True
        return False

Guess you like

Origin blog.csdn.net/qq_32301683/article/details/108478456