Introduction
There were two phone interviews in the early selection phase, which I’ll skip here. First published at: https://www.jianshu.com/p/d5aa63a27172
First Interview
Chengdu, April 11
- Introduce your projects, what were the difficulties, and how did you solve them
- Introduce C++11 features
- Explain the fork function
- Explain the TIME_WAIT state
- Why does a TCP connection handshake require three steps
- Explain iterator invalidation. Does push_back cause iterator invalidation?
- Characteristics of red-black trees, explain
- Methods to resolve hash collisions
- Differences between processes and threads
- What thread models do you use
- Explain coroutines
- Explain the quicksort algorithm
- What is a stable sort, is quicksort stable, and why
- Derive the formula for the worst-case scenario of quicksort
- Why should a destructor be virtual
- Why can’t a constructor be a virtual function
- Questions printed on paper, testing: new[] objects, static members, what exactly a subclass constructor calls, differences between copy constructors and assignment operators, when the equals sign appears in a copy constructor, when an assignment operator is needed, deep copy vs. shallow copy, when virtual functions are called.
Below is one of the questions, please write the output:
#include <iostream>
using namespace std;
struct A{
A(){
local_var++;
}
virtual void func(){
cout << "A" << endl;
}
static int local_var;
};
int A::local_var = 0;
struct B : A{
B(){
local_var+=2;
}
virtual void func(){
cout << "B" << endl;
}
};
int main(){
A* a1 = new B[3];
cout << a1[0].local_var << endl;
a1->func();
A a2 = a1[0];
cout << a2.local_var << endl;
a2.func();
A a3;
a3 = a1[0];
cout << a3.local_var << endl;
a3.func();
}
What problem will occur in the following code?
#include <iostream>
using namespace std;
struct A{
virtual void func1(){
cout << a << endl;
}
void func2(){
cout << a << endl;
}
void func3(){
cout << "a" << endl;
}
int a;
};
int main(){
A * a = (A*)malloc(sizeof(A));
a->func1();
a->func2();
a->func3();
}
- The approach to a problem during the written test (previous Nowcoder test. The interviewer actually printed all my test answers and results, including multiple-choice and algorithm questions, how many times I submitted, how many times I failed). Testing when the virtual pointer is initialized.
- Randomly selected a question on paper. Given preorder traversal ABC and postorder traversal CBA, what is the inorder traversal? Draw out the two possible scenarios.
- The approach to the first algorithm question during the written test (previous Nowcoder test)
- There are 100 marbles, two players take turns, each person can only take 1-5 marbles, the person who cannot take any loses, what is the winning strategy?
- What have you been learning recently (server programming)? What did you learn before (TensorFlow)? How did you learn it? What do you think about TensorFlow’s powerful neural networks?
- Family situation.
- After leaving, wrote code in the lobby: find elements in char array a that are not in char array b, and put them in char array c. Here I forgot to convert char characters to unsigned char type.
Second Interview
Chengdu, April 13
- Self-introduction
- What are system calls? Which system calls have you used? Which system calls take a long time?
- Have you used gdb debugging? What is a conditional breakpoint?
- Difference between function pointers and pointer functions. Write an example.
- Write a fork call example by hand. In what situations have you used fork calls?
- Explain the connect function in UDP.
- What is an index? Is adding more indexes always better? (I admitted to looking at interview experiences for the index question, but came up with the follow-up question myself)
- Which questions from the last interview did you research afterward?
- There was a problem with your code in the last interview, do you know what it was?
- Where did you learn the answers to these questions? What have you been doing these two days?
- Some suggestions for you: look into gdb debugging, database knowledge, network programming, and practice more.
Aftermath
Received a phone call on April 20 confirming the offer from Tencent.