Spring moves have begun. Have you started to prepare? In order to help everyone get better offers, Lucifer opened up**Spring moves rush**Column.

Our prey today is**Nail and Tencent**。 Let’s take a look at the difficulty of these two algorithms!

<!– more –>

Video address:https://www.bilibili.com/vide…

## Nail nail

- Comparison version No. (Likou question no. 165. Comparison version No.)

One traversal is enough. The only thing to pay attention to is to complete and then compare (logical completion is enough, not necessarily physical completion). The time complexity is $o (M + n) $, where m and N are the lengths of two version numbers respectively

- Random string generation (randomly generate a string with length of 8, which can only be lowercase letters and numbers. Letters and numbers can be repeated, but the generated random string cannot be repeated)

Randomly generate a character with a length of 8 and store it in the hash table. Judge whether it is already in the hash table after the next generation. If it exists, it indicates that it has been generated before. Continue to generate. Note that this algorithm may reject all the time, and the code will loop indefinitely.

- Log reporting (implementation effect: no data is reported, and data is reported in batches every 100ms)

Maintain a window. When there is data in the window, the request for batch upload is triggered. The length of a window is 100 m (may be greater than) for all requests

## tencent

- String inversion

Double pointers at the beginning and end. You can constantly exchange the characters of the two pointers.

- The penultimate number of the linked list

Speed double pointer typical topic.

- Design to find the n-th power of a number

A typical dichotomous topic. No suggestions. Look at my dichotomous handout. My brush shop or official account search.**Dichotomy**All right.

- LRU algorithm

It’s a little difficult. This problem is very common and difficult. It’s recommended to brush it. I’ve written the solution before. Let’s throw it directly to you146. LRU caching mechanism

I gave JS, go, PHP and python 3. Do you have your food?

- Tear it by hand, that is, the given coordinate position and current face direction (nswe) of a trolley, input the forward steering and forward steps, and output the coordinate position and face direction of the trolley.

No difficulty, direct simulation.

- List addition

Linked list and array are not different in nature, but the specific operation is different. Therefore, it is OK to master the basic operation of linked list. What are the basic operations of the linked list? What needs attention? myLinked list topicsIt’s all summarized for you. It’s recommended to read.

- Leetcode 1567 is the length of the longest subarray whose product is a positive number.

The title is: give you an integer array nums ， Please find the length of the longest subarray whose product is a positive number. The subarray of an array is an array composed of zero or more consecutive numbers in the original array. Please return the length of the longest subarray whose product is a positive number.

This problem is to find**successive**With positive product**Longest**Subarray length. A primary school knowledge is needed here. The multiplication of two numbers with the same symbol is a positive number, and the multiplication of two numbers with different symbols is a negative number (do not consider 0 first). Therefore, one-dimensional DP + one-layer cycle can be used directly.

Defines the state positive [i] as ending with nums [i]**The length of the longest subarray whose product is a positive number**, negative [i] is the end of nums [i]**The length of the longest subarray whose product is negative**So the answer is max (positive).

Next, traverse nums and discuss the different values of nums [i]:

- nums[i] > 0

$$

positive[i]=positive[i−1]+1

$$

$$

negative[i]=\left\{

\begin{aligned}

negative[i-1] + 1 & & negative[i-1] > 0 \\

0 & & negative[i-1] = 0 \\

\end{aligned}

\right.

$$

- nums[i] < 0

$$

negative[i]=positive[i−1]+1

$$

$$

positive[i]=\left\{

\begin{aligned}

negative[i-1] + 1 & & negative[i-1] > 0 \\

0 & & negative[i-1] = 0 \\

\end{aligned}

\right.

$$

- nums[i] == 0

$$

negative[i]=positive[i] = 0

$$

There are two general routines for status definition:

- Use a two-dimensional array to define DPI and define DPI
- Use two one-dimensional arrays to define DP1 [i] and DP2 [i]

The ideas of the two methods are the same, but the actual operation is different. I personally prefer the second. For example, for stock questions, I like to define a buy and a sell array. Another example is the swing array. I like to define an up and a down array.

In addition, if the topic is not limited to continuous, two-layer loops and one-dimensional DP (rolling array optimization) are required.

## summary

Personally, I think the difficulty of algorithm problems is medium. They are very conventional. There are no difficult problems or unexpected knowledge.

In addition, I set up a spring recruit group. You can ask questions you won’t meet in the interview. Those who want to enter the group can reply to the WeChat in the background of the official account.**Spring move**Join the group.

Finally, I wish you a lot of offers.