background

After spending the New Year in Beijing, I am ready to see the opportunity and also want to know the market conditions. I didn’t send too many resumes, only directed to tiaotiao education department, Douyin, Kuaishou, Ali, these companies. Headlines and Ali’s resume are missing, so there must be too few highlights. Only The KUaishou resume passed, Kuaishou is three rounds of technical surface + a round of HR surface, the first two rounds of technology are relatively smooth, to the third round but lost, very sad O (╥ : ╥) O. I’m not thinking about changing jobs right now. I’ll wait until the second half of the year and then I’ll refine it.

The quick interview is a video interview, which is not supported on weekends, but you can choose the evening time, which I have scheduled at 9 PM these times. The video interview was conducted through The website, and here are the questions I remember from each round. I won’t answer some iOS basics.

One side

1. Recursively write an algorithm that computes the sum from 1 to 100.

func sum(value: Int) -> Int {
    if value <= 0 {
        return 0
    }
    var number = value
    return value + sum(value: number - 1)}// The calculation process
let result = sum(value: 100)
print(result)
Copy the code

After writing the algorithm, I asked several questions, which are the basis of the algorithm:

  • What is the time complexity of the algorithm
  • What are the disadvantages of recursion
  • Can I do that without recursion, can I get down to order one?

2. What is the function of property? What are the keywords?

3, how to find the property of the superclass?

4, NSArray, NSDictionary should be how to choose keywords?

5, copy and muteCopy what is the difference, deep copy and shallow copy what is the meaning, how to achieve deep copy?

What have you ever done with Runtime? How is method exchange implemented in Runtime?

Let’s talk about KVC and KVO. Does KVC call setter methods?

8. What is the function of __block

9. Tell me what you know about the COMMUNIST Party of China (GCD). What methods does it have and what does it do?

10. Do you know about binary trees?

The interviewer wants to follow up with this question. I said I didn’t, and there was no follow-up.

Second interview

The difference between ARC and MRC. How does iOS manage reference counts? When does the reference count increase by one and when does the reference count decrease by one?

2. What happens when [object AutoRelease] is executed under MRC?

3. How does CoreAnimation draw images? Can frame be obtained during the animation process?

4. What do you know about Runlop?

5, OC how to achieve multiple inheritance?

That was not a good answer. In fact, by means of message forwarding, protocol and category can implement multiple inheritance indirectly.

6. What do you know about design patterns and how one of them is used?

7, is there any open source library let you use very comfortable, talk about the place that makes you comfortable.

I said RxSwift here, and then I talked about the observer pattern and responsive programming. The interviewer then asked what should be done to implement a logic like RxSwift with OC. My answer is to combine KVO with some properties that need to be observed, listen through KVO, and then call back through block.

8, a 100*100, RGBA PNG image decompressed after how much memory space.

RGBA > FFFFFFFF > 4 bytes

(100 * 100 * 4) / 1024 = 39KB

9, algorithm problem

Given a number arR, determine whether all the numbers in the array arR appear only once.

This is not required to write, said to provide ideas on the line. The solution I gave at the time was to use a dictionary to store the handy elements in the convenience array, and if the new element is in the dictionary later in the convenience procedure, it means that there are repeated numbers. The time complexity is order n.

I also asked if there was any way to optimize it, and I came up with the idea of turning the array into a Set and comparing it to the original array to see if the number of the two sets changed.

10. I introduced myself to him that I used Swift more often, and then asked him about the differences between Swift and OC, as well as the advantages and disadvantages of each.

Why did you leave? What are your career plans?

On three sides

1, given an array of ints, use the elements in the array to form a maximum number, since numbers can be very large.

Input: [3,30,34,5,9] output: 9534330Copy the code

This is Problem 179 from LeetCode, medium difficulty. Interviewer let the train of thought first, then go to do the problem. Just to be clear, I haven’t done this problem before. At that time, the idea was to use the bubble method for sorting. The premise of sorting was to complete the loop of fewer digits, for example, the comparison of 3 and 30 became the comparison of 33 and 30, the comparison of 34 and 4 became the comparison of 34 and 44, and then the result was integrated into string output from large to small.

But it turns out that it’s not that easy, because if you’re going to have two and three digits, you’re going to have to have the least common multiple of the digits, and you’re going to have to convert them all into six digits. After struggling for five minutes, I just did it.

If you add some Swift higher-order functions, you can write:

func largestNumber(_ nums: [Int]) -> String {
    let sort = nums.map {"\ [$0)"}.sorted { (lStr, rStr) -> Bool in
        return lStr + rStr > rStr + lStr
    }
    let result = sort.joined()
    if result.prefix(1) = ="0" {
        return "0"
    } else {
        return result
    }
}
Copy the code

The func findFile (dir: String suffix: String) -> [String] method is used to retrieve the desired file by entering the folder directory and suffix.

For example, if you want to retrieve a TXT file or an MP4 file in a file, just pass in dir and suffix. Now there are some requirements, such as retrieving TXT in UTF8 format or MP4 in H264 encoding. There are also some requirements, such as finding files that have been updated in the last week. How can you optimize this class to meet these requirements?

The first thing that comes to my mind is that it is impossible to complete so many requirements in one method, and different methods need to be broken down according to different scenarios. However, these are all file operations, and there is a common method that is to retrieve files. This method requires passing in the file directory, and then recursively returns all file paths in the current directory. The external invocation logic for different scenarios is done with an enum, with different values corresponding to different types of the same range.

The interviewer is more concerned about how to write the internal shared file retrieval, he said how to do if there are too many sub-files, how to optimize. I’m a little confused, looking for a file is at least to go through again, too many subfiles, this should be unable to optimize ah. It got stuck for a while, but then he gave a hint about whether or not you could do it with a block, return the file path out, and let the external decide whether or not the current file is available, and finally the external calling class looks like this.

// My plan
//func findDir(_ dir: String) -> [String]
/ / block
func findDir(_ dir: String, block: ((String) -> Bool))
Copy the code

I think it’s ok to return the contents of the directory with a block, at least not all the files in the directory are held by one object, and the previous setup is to verify the benefits of the block scheme.

In fact, after thinking about this problem is not what difficult, this writing method has written, but at that time is not to think, maybe the front circle of the fowing to me with a bias, said the loss is not loss, more efforts in the future.

conclusion

On the whole, the interview questions of Kuaishou are simpler than those of iOS I have seen elsewhere. The first interview is mainly about basic knowledge, the second interview is more comprehensive and allows me to talk about some technical understanding, and the third interview is more practical.

Although the algorithm has three rounds, but relatively simple, even if you can’t write it out, you can also have ideas. Of course, writing it out is definitely a plus, so when you’re preparing for the interview, you should read it. Algorithm related, sorting, array, binary tree, these are the key categories.