PUA in interview of leetcode 200 number of islands | page cache | in Arts Week 11

Time:2020-12-6

ARTS

Arts is an activity launched by Chen Hao in the geek time column. The aim is to keep learning through sharing.

Each person writes arts once a week: algorithm is an algorithm problem, review is to read an English article, technique / tips is to share a small technology, share is to share a point of view.

This week’s content

This week’s arts you’ll see:

  1. Leetcode 200 number of islands seems to be seeking connected domains, but it is actually sweeping mines?
  2. What exactly is page cache?
  3. Have you ever encountered PUA in an interview?

Algorithm

This week we are going to talk about leetcode 200 number of islands. This is a question of finding “connected domains”, that is, how many regions of 1 are surrounded by 0.

One thing to note is that traversing the entire matrix is unavoidable, and an “island” may contain multiple ones. Therefore, how to avoid repeated calculation of an island? A simple way is to find an island and mark all its nodes as 0. In this way, we can avoid the island being counted repeatedly.

So how to mark a found island as 0? The simplest way to answer this question is DFS. After a point is found to be 1, DFS the “up, down, left, right” of this point until no 1 is found.

func numIslands(grid [][]byte) int {
    var ans int
    if len(grid) == 0 {
        return ans
    }
    nc, nr := len(grid), len(grid[0])
    var dfs func(c, r int)
    //Through depth first traversal, set the same island to 0
    dfs = func(c, r int) {
        grid[c][r] = '0'
        if c > 0 && grid[c-1][r] == '1' {
            dfs(c-1, r)
        }
        if c < nc-1 && grid[c+1][r] == '1' {
            dfs(c+1, r)
        }
        if r > 0 && grid[c][r-1] == '1' {
            dfs(c, r-1)
        }
        if r < nr-1 && grid[c][r+1] == '1' {
            dfs(c, r+1)
        }
        return
    }

    //Mine clearance!
    for c := 0; c < nc; c++ {
        for r := 0; r < nr; r++ {
            if grid[c][r] == '1' {
                ans++
                dfs(c, r)
            }
        }
    }
    return ans
}

Review article recommendation

This week, I read some content related to page cache. Of course, most of them are “popular science”. For example, the following page cache, the affair between memory and files

When you use the free command to view the memory usage of the system, you will generally get six columns of data:
total used free shared buffers cached.

Here, we only care about the last two columns, namely buffers and cached. Buffers represents the cache pages used by the block device, and cached represents the cache pages occupied by ordinary file data.

In fact, when we talk about caching, we actually need to consider three parts. They are:global_page_state(NR_FILE_PAGES) total_swapcache_pages i.bufferram.

global_page_state(NR_FILE_PAGES)As the name implies, represents the total number of cached pages.

total_swapcache_pagesIt refers to memory pages that are not associated with any files, such as memory pages requested by the running code through malloc(). If the above memory pages need to be paged, the data in these memory pages will be written to swap cache. Swap cache will associate one or more output devices, such as bare disks or files.

i.bufferramIt is the penultimate column buffers of the free command

The last column of free, cached, can be calculated by the formulaglobal_page_state(NR_FILE_PAGES) – total_swapcache_pages – i.bufferramGet it.

Tip programming skills

What is skill?

Share flash

PUA is originally meant to refer to men who use certain “means” to accost women. Because these “means” often use some “bullying” or “demeaning” methods to “tame” each other, PUA has gradually become a group of people shouting and beating in the past two years. And PUA itself has gradually become more universal, and even become a network buzzword, which generally refers to the behavior of deliberately belittling others. Sometimes it is used as a verb, such as “I was PUA in the interview.”.

Recently, I tried to attend several interviews. I have to admit that I still lack in knowledge accumulation, both in breadth and depth. However, I may not be able to make a proper preparation for the interviewer.

Obviously, in one or two interviews, the interviewer is obviously not “properly” prepared. The way to quickly judge such an interviewer is to see if he can comment on your answers, and whether he can dig deeper according to your answers to find the boundary of your knowledge reserve. If an interviewer has no in-depth understanding of the question he is asking, or does not have the knowledge of the supervisor, then he can only judge by what is “beyond the content” of your answer. For example, whether you use some uncertain modal particles, or the tone you express, etc., or the interviewer really tests “feeling” to make a judgment.

If you also meet in the interview, just deny your ability, but not his negation according to the specific explanation. It is strongly recommended to ask the interviewer directly: can you point out which question did not meet your requirements and why? Of course, if the interviewer really depends on his feelings, he will probably find a way to refuse to answer this question. At this time, you can choose to be tough, and you must tell the interviewer which question has a problem. You can also choose to give up the struggle, because whether you just or not, the end result is a waste of an hour.

Reading list of the week

  • Geek time MySQL actual combat 45
    09 | how to choose between normal index and unique index?
  • Page Cache, the Affair Between Memory and Files
  • Go context
    The cancelctx type holds a channel of its own, which is used for closing notification. It also holds the cancel method of all children to close the done channels of all children. This will eventually form a tree structure.
    The advantage of this is to avoid all CTX using the same done() function, because using the same done() means everyone competing for the same lock.
  • The difference between buffers and cached displayed by free command
    Describes the last two columns of the free commandbuffersandcachedWhat is the difference.