The cause of

2021-03-21, FROM 8:00 p.m. to 10:00 p.m., I participated in the first round of written test of Tencent, with the direction of front-end /UI. After two hours of answering, I finally made three out of five questions. I was not satisfied with the result of my own written test. In the following I briefly explain the interview five questions, their failure, and from the interview to understand the truth.

Want to write a copy of the article, but there are too many, afraid that they have been dragging down to write their own new bar.

Sharing of written test process

The Tencent written test was conducted on niuke.com and lasted two hours. The written test consists of five programming questions. Before the test, you need to log in in advance to confirm the candidate’s identity, and check your camera, etc., and then the previous integrity guarantee, you can wait for the test. At the beginning of the exam, he will give you two examples to help you figure out how to input and output data in ACM mode. When the two hours are up, there will be an automatic queue to submit the papers.

It is recommended that you log in ahead of time to familiarize yourself with the process, such as how to submit code in ACM mode. However, the code can be copied to local debugging, how to copy to local debugging, etc., need to familiarize yourself in advance.

The written test checking

First problem: achieve infinite scrolling

DOM and javascript

Code gouge complete

When the div slider is less than 100px from the bottom, insert an element into it to scroll indefinitely.

Question1. Vercel. App I realized the answer.

Experience to solve the problem.

This problem is not difficult, but when write the code, because not too familiar with the scrollTop, scrollHeight, clientHeight, etc., so the final code had not, the browser will get stuck. Maybe it has something to do with my implementation and judgment system. And then I was in a panic at the beginning, and I made all the mistakes I could.

const scrollTop = container.scrollTop;
const contentHeight = container.scrollHeight;
const height = container.clientHeight;
const shouldTrigger = contentHeight - height - scrollTop <= distance

Copy the code

I recommend copying ngok code to local debug immediately if it is not easy to debug.

Number two: the minimum number of steps for a positive integer n to become zero

The transformations he can make:

  1. n – 1
  2. If n is a multiple of 2: n / 2
  3. If n is a multiple of 3: n / 3

Data range:

  • Count: 1 to 10000
  • N: 1 to 2 to the 31st

Enter the demonstration

2
10
10
Copy the code

The output demonstration

4
4
Copy the code

My answer:

  1. Answer 1 does not run directly because it reads data from the standard input stream output stream (browser).
  2. The function version can be run directly.

Dynamic programming dp pruning

At first glance, I thought this problem was a simple dynamic programming, but I never passed the written test.

Now I understand. This is a simple dynamic programming problem that requires pruning. We can see that the maximum value of n can be 2 to the 31st, so if we go straight from the top down without pruning it will definitely burst the stack. Of course, this question can not be bottom-up, because the amount of data is too large.

We start from the top down, and then use memos to record the data. If it’s a multiple of 2 or a multiple of 3 you don’t have to calculate n minus 1.

Question three: 01 backpack?

I have a matrix with r rows and c columns. Select the values in the matrix so that the columns add to C to maximize the addition of values. Each line can be selected only once.

Problem 4: Evaluate the value of an operational expression

Enter the demonstration

"1 + 4/2-1"
Copy the code

The output demonstration

2
Copy the code

I think he’s taking a javascript API (eval) test, because you can only use javascript.

So I just ran eval.

Problem 5: Convert Chinese numeric strings into numbers

Data range: less than 100 million

The discovery of a pattern

  1. Enter one: “one thousand three”

    Output one: 1300

  2. Input 2: “one thousand three hundred and one”

    Output two: 1301

  3. Enter three: “twelve”

    Output 3:12

  4. Input 4: “one thousand three twenty one thousand three hundred and twenty-one”

    Output 4:13211321

This problem does not test data structure, test can discover the law, solve the problem. I saw the problem before the exam, but didn’t look closely at how they solved it.

Finally, I went through a lot of trouble to write it.

Here are the answers

Ideas:

  1. We need to convert text to numbers, so we need a mapping.
  2. Tens of millions are units, so let’s map it, too, and pay attention to thinking about zero, which I’m treating as a unit rather than a number (special treatment) example: one thousand three hundred and one.
  3. Special case considerations: for example, the last number has no units, thirteen.
  4. The data range is within 100 million, so the unit can be specialized. Multiply the result of the transformation by 10000 as it occurs.

conclusion

My title is life needs a deadline. I said this because I was so nervous when I took the written test. The third of the five questions was supposed to be more difficult, but IN the last two hours I finished writing four questions. I think it has something to do with my lack of training. The lack of training I am talking about here means that I have not done enough homework, and more importantly, I did not set deadline for myself when I made leetcode. Usually do the problem slowly, has been in the debugging, really can not afford to see their problem solution. When AC is finished, I will simplify my own code, but these are not the most important. The most important thing is to have an environment that most closely resembles an interview. I can come up with the idea of doing the problem in the shortest time, and write the ac code in the fastest and most clear way. I don’t care if this is as simple as it gets.

Therefore, we need to set deadline for ourselves. When we go to the interview, we will not be so nervous in this real environment. For example, Leetcode has a mock interview, so you can go to mock interviews. Then the interviews are conducted on Niuke, so you can’t rely on LeetCode all the time. You also have to train on Niuke (although it’s not a very good platform, But LeetCode is good). Otherwise to their interview time like me platform are not familiar with the dead.

Then my experience is to brush the sword offer in Leetcode, and then I did some classic questions in Leetcode. For example, drab stack of rainwater, the maximum rectangular area, I can recite down. And then it’s said that the linked list exam is more, you can pay more attention to the linked list. There are so many leetcode questions, you can’t finish it in a short time, so focus on the key points and review all the knowledge points. I have an interview with Bytedance in a few days. Go for it.