Friday, December 4, 2020

Value of 30 minutes: Google mock onsite interview - hard level algorithms

 Dec. 3, 2020

Introduction

I just could not believe that last few weeks I have challenged myself with so many algorithms. Google onsite interview is such a big deal, and I suddenly started to think about solving another 50 hard level algorithms, and it feels so good to solve so many algorithms as a software programmer. 

30 minutes  - one hard level algorithm

I just could not believe that it is possible for me to learn more hard level algorithms. I just need to spend 30 minutes, understand the problem, and read top voted discussion post, and then copy idea and code, write a C# solution. 

Every 30 minutes I should be able to learn one hard level algorithm. 

Coding is fun. Once I build a good habit to practice algorithm, I will solve another 50 hard level algorithm in short future. 

I just could not believe that I will be a super talent programmer. No high pay job, but it is so entertaining. I will definitely transfer this skill to work on stock investment. 

Bravo! good job! keep working hard. 

Celebrate 591 mark on Leetcode.com



Thursday, December 3, 2020

Google AI: CS PhD 2018 北美找工作小结

 Here is the article. 


Tips for me:

  1. Leetcode premium
  2. Google tagged algorithms
  3. Google team match is hard and it depends on luck sometimes

个人背景

美国University of Maryland CS PhD, 浙大计算机本科,PhD主要研究方向是deep learning/ information retrieval/NLP. 之前有过一些实习经历,在Google/Microsoft/Comcast AI Lab呆过。总体再回头看实习经历对找工作非常加分,基本上所有的面试都对我在Comcast实习的一段经历非常感兴趣,有时候一轮面试就只聊我实习期间做的项目(语音搜索和NLP相关)。还有一些IR/NLP领域灌水论文。另外最近几年ML/AI/NLP/IR 方向确实很火,能拿到这些不错的Offer很大程度上跟自己做的方向很有关系。

简历也是很重要的一关,基本保证了你的面试官对你的第一印象,建议大家可以去参考一些大神的简历看看。保证重要的Project/Publication/Experience写在最前面,这些也是你可能要重点准备的面试经历,我有好些电面基本上一轮就只聊我简历上的经历。

Coding

虽然我自己拿的大部分offer都是research scientist title, 但是无论是swe还是rs, coding真的很重要!!我面的这些偏research职位(Google, FB, MSR)都有几轮是coding面试,好的coding能力基本算是基本功了。我的准备过程也基本上靠leetcode了,从去年10月份开始刷题,刷到陆陆续续1月份,总共刷了大概前400道题的样子。在一边实习一边赶论文的情况下刷题确实非常痛苦,那段时间基本都是晚上十二点到家,不过坚持下来再回头看看还是非常值得,也希望和大家共勉。。

个人经验是刷题不一定要全刷完,但是保证自己完全理解一道题很重要,每次AC了之后我会对比下别人提供的参考解法,看看怎么样能从coding style/思路上优化自己的code, 基本保证每道题的写法是最优的,和最后AC的时间都是在前20%的样子。另外强烈建议买一个leetcode会员(这点钱和你最后拿到的offer实在是算不上什么),在每个公司面试前期有针对性的刷完有这个公司tag的所有题,这个对某些喜欢考题库的公司太有帮助了。。。我刷题总共刷了两轮,第一轮是每一道题老老实实做,第二轮选择性的挑了一些题做,其他题基本是在脑里过一遍,觉得有思路了就不写了。还有一点建议是刷题的时候记录一些你觉得非常经典或者自己一开始没做出来的题,方便你在第二轮刷题的时候有针对性的复习。

面试经验

Facebook: fb的面试流程还是非常中规中矩的,基本上是一轮电面+onsite, onsite总共五轮。我是两轮coding+一轮ML system design+一轮research+一轮和manager聊天。可能因为我的简历比较match,面我的面试官全是Facebook Research下面NLP组的人,可能正常来看大部分人是三轮coding。面试时候放轻松,能够和面试官很自然的沟通,碰到不会的题面试官会给一些hint,确保自己理解了这些hint。还有一个面试技巧可能会比较有用,可以善于和面试官拉进距离,我当时FB面试manager就是我们实验室毕业的,还有一个面试官是JHU毕业的来UMD给过talk,还有一个认识我导师,面试的时候有的面试官可能会主动和你透露这个,你可以顺便聊一下你们可能会有的一些共同经历,对于调节面试氛围还是很有帮助的。。

Google Research: 因为我之前在google实习过两次,所以没有电面直接onsite了。当时我的HR一度不回我邮件,本来想早点安排onsite的,结果拖了将近一个月才安排上,直到我FB offer deadline当天晚上十点才拿到google offer。。。Google给Offer的流程和其他公司不太一样,onsite -> team match -> committee decision. 所以即使你过了onsite并不能直接拿到offer, 可能要额外安排个2-3周team match的时间,保证自己能Match上想去的组。建议大家安排google面试多预留一个月左右。

Google面试我是先过了一轮technical onsite, 四轮coding+1轮research,基本上碰不到leetcode原题,有两轮应该是leetcode hard难度。碰到不会的不要太紧张,我有一道DP题没答上来最后还是拿到offer了。后面又和google research聊了一轮,主要是research+ML面了。因为当时FB催的紧,只聊了一个组就接offer了,所以也导致当时没match上特别想去的组。


----

面试准备:
主要参考了之前的两篇帖子(https://zhuanlan.zhihu.com/p/35435776和https://www.1point3acres.com/bbs/thread-530358-1-1.html),写得都非常棒,到今年也非常适用。ML/DL/NLP的基础需要好好复习一遍,我个人主要看Stanford CS229的lecture notes和李航老师的书。然后就是老老实实练习coding,熟练掌握各种二分,理解递归,bfs/dfs,双指针,树/堆/队列/图,DP等等。以二分为例,一定掌握模板,清楚二分的条件可以用各类计数条件(i.e. 大于/小于)来表示。最后再准备一下自己的research,如果面试官对你发的paper感兴趣,那基本都聊具体的实现和intuition,外加怎么结合到他们工作中。举个例子,如果你做过一些text generation,可能会从基本的language model,copy mechanism问起,过渡到怎么增加diversity,怎么引入knowledge,怎么做control。如果不聊paper,那就会考ML/DL基础知识,比如花式问一下BERT,Optimizer,Logistic Regression,EM。下面详细说一说对每个公司的体会。

Algorithms: Past interview algorithms - FANG

 1. 给一堆二维坐标,这些坐标点能组成一条线,求输出最少的点能还原这条线

2. 利口耳期酒,需要输出所有的完全平方数的数字,而不是多少个
3. 第一象限 给一堆点 让你找一个最小正方形能把包含的离原点最近的k个点,followup是找这样的长方形
4. excel类似的功能,需要支持set和get,
- set 就是给你一个col key和它的value, 它的value可以是一个int,也可以是一个reference,指向其他的column
- get 就是给你col key 需要你能resolve它的value


2. 二维空间,给一堆平行于坐标轴的长方形,如果两个长方形相交,就算是属于一个group,求问有几个group。做法就是Union Find,相交的长方形就union为一个group
3. 给一堆各种颜色的球以及个数,比如绿球200个,蓝球300个,红球500个,装在一个不透明的袋子里,让你写一个函数模拟从袋子里拿球再放回去的操作,函数返回拿到球的颜色
4. 酒似遛的变体,stack的模拟操作,这个stack push的rule是必须先放k, 才能放k+1,输入是0到n的permutation,代表pop出stack的顺序,问你给定的输入是否能实现
5. 设计,群聊,侧重点在于清楚的描述你设计的系统每个组建的功能,以及组建之间的通信,以及数据结构

 刷题网:意思琪琪

2. BQ:  team has different opions.  handle when one teammate leave during project.   handle un-resonable request/task from manager.

3.刷题网:其义务

4. most challenging proj.  刷题网:伊尔无九  

5. 2-d 01 矩阵 找最大陆地面积,0=水 1=地,陆地只能上下左右连接,斜着不算连接.
follow

第一轮:类似吾儿霸,就用了个壳,负载平衡follow up 1, 如果这里面的权重可以改, 怎么搞,要最好的complexity

follow up 2, 怎么测试,现实场景如何验证这个算法

第二轮: 有一数组都是一个个字符串,如果有一个字符串满足一个pattern,假设你有这个检查符合pattern的方法存在, 输出给定前后半径的所有字符串
follow up 1, 把数组换成数据流
应该有follow up2,没太记清楚,主要我也没有时间写了

面的l4, 狗屎运比较偏简单;
走过路过,求好心人施舍点大米😂
(没有设置限制,如果看不到可能是论坛默认。。试试手机版)

----
第1轮:李寇 意思二三; follow-up:还是取数组头和尾k次,新加入multiplier int[k], 每次也从multiplier 按序取出数相乘算结果,求max,例子:k=2, array [3,2,1,4], multiplier [1,2], 第一次取结果:4*1, 第二次取 3*2, 总共10;用的dfs + memorization

第2轮:最近常见的简单雇主树结构;给adjacent list (有向图)
问1: 什么情况下valid:graph 中只有一个disjoint set并且没有cycle, 不在意是否indegree>=2
问2: Valid 下求某个人的分数,即此subtree的count
问3: Validate given graph,用topology sort

1~4
- behavior 就是一般的题目,比如如何handle意见不同的情况。我是结合我实际情况回答的。总之一个原则:communication solves all the conflicts
- 三零一,还有一个ez的题目,具体我不太记得了。
- TicTacToc用android写的变种,我用了一些jetpack的东西,比如viewmodel和livedata
- android写service。算法997?还有一个现出的题目dp,这个我好像当时现场推出来,没见过原题。

5. 三叔,一个ez的题目,然后来了一个我没见过的题目。估计这轮弱。
如果有人知道请告诉下我。
大意是有1~n,可以组合成1,[1,2],[2,1],[1,2,3],[2,1,3],[3,2,1]...
如果把结果放在一个1d的array里,结果是什么?
我用了一个很naive的做法。但是貌似不符合要求。

第一轮利口846
第二轮利口1182 要求pre compute o(n),follow up二维color矩阵,要求pre compute o(mn),之后query o(k),k为query次数
第三轮bq
第四轮利口16

第一轮1240 given a rectangle x*y, minimum numbers of squares to fit in the rectangle第二轮 design a parking lot
第三轮 flip an array of 1, 0. minimum moves for flipping all. O(n)
第四轮 要斯而散 还有一个follow up,问增加一个array of K len, 每次选的数字要乘以对应的arrayK 里的数,求最大sum


第三轮:
给一个matrix,每个row只能选一个数,如果选第i行第j个元素,第i+1行第j+1的元素,那这两个元素之间有penalty: (j + 1 - j) = 1; 让求最后最大和是多少。思路: dp可以是O(mn^2)的m是行数,n是列数。大哥问能不能优化时间到O(mn),其实不太知道,大哥疯狂带着我做,最后一个for loop是O(n)可以用两个left[] 和 right[]预处理最大数。


给一个Oncall表 {张三:1 - 5, 李四: 5 - 7, 王五: 2 - 10} 这个格式是 “谁:什么时候”
              要求返回一个格式为“时间段:谁(们)”的表。比如上面的例子的return就是:
              1 - 2 张三
              2 - 5 张三 王五
              5 - 7 李四 王五
              7 - 10 王五
              return type没有规定,总之这个return能找某时间段有谁在Oncall

第三轮: 国人大哥。人很nice. 一直鼓励我,引导我。给两个string, 叫他们old和new吧,比较他们,已知old是通过改变了一个substring变成new的,分析出old是怎么变成new的。
              return三个东西,变化的种类(增加,减少,替换),变化的开始位置(some index in the old string), 变化的部分是什么(从什么变成什么)

              例子1: old: "aaabb"    new: "aaaccbb"
                           old通过在index = 3 的位置增加了一个"cc"变成new
              例子2: old: "aaaccbb"   new: "aaaddbb"
                           old通过在index = 3的位置把"cc"替换为"dd"变成new
              例子3: old: "aaaccbb"   new: "aaac1234"
                           old通过在index = 4的位置把"cbb"替换为"1234"变成new
              需要自己去多问clarification questions。问的越多信息越多,比如讨论return type

题目内容:让我写一段代码来返回一个迷宫,没了。其他基本啥也没给,不是他不给信息,而是本身就不给什么限制,自由发挥。和面试官讨论能获得好的方向,比如,Input是什么, 迷宫要怎么表示,这个迷宫有几个解等等。
               input: 迷宫的宽,迷宫的高,起点,终点
               output: 一个设计好了的迷宫

酒肆刘 -- follow up, O(1) space

拔散散 -- 变体,如果给的index, source不match就throw,有overlap也throw。 因为都两个case都throw,我认为time complexity是O(S), visiting each char const time, 面试官似乎不太同意-- follow up, 把loop对换,用原string做main loop,two pointers搞定

只有一个根的DAG, 求最长路径长度
-- followup, 多个根
-- followup, 求最长路径

第一轮: 算法 给你一包色子, 每个色子只有两个面, 点数从1-6. 两个色子如果有一端的点数相等就可以连起来. 比如4-1 和6-1 可以连成6-1-1-4 (色子可以左右置换后连) 求给定的这包色子中 能连起来最长的色子数是多少

1. 世界杯淘汰赛阶段,每个球队夺冠的概率。
已知有个表格知道16强两两之间胜负的概率,以及一个16强对阵表。
求输入任意一个球队,返回这个球队最终夺冠概率。
2. 知道两条rule, #1 朋友的朋友是朋友, #2 敌人的敌人是朋友。
给你一串输入:  1 2 F, 2 3 F,  4 5  E,  5 6 E, 等等。。。  
前面两个数字表示两个人,第三个f, e 表示关系。
根据两条rule,构建出所有隐藏的关系。
3. 已知
    “key1” -> "3489"  
    "key2" -> " %key1% is awesome!"
    .....
   给任意一个statement = “ %key1% !!!!! %key2% !!!!!!”  把其中%% 里面的内容替换成value。 注意多层嵌套替换
4. 一个二叉树,把所有子节点的value挪到根节点需要多少move。  
move 的定义: 子节点的一个value,移动到上一层算一个move,再移动到上一层,又算一个move。
follow up, 如果要求每个子节点必须保留value=1,其余都move到根节点,需要多少move

Leetcode 1194 and 979
465. Optimal Account Balancing

Actionable Items

It is so much fun to go over those interview algorithms. I do learn a few good algorithms. I think that I should break into more blogs about those algorithms. I like to learn one by one. 

Wednesday, December 2, 2020

The Best Recruiter at Google | Talent Connect San Francisco 2014

 Here is the link. 

With more than 2 million applications a year, Google has become the most sought-after workplace in the world. Laszlo Bock, Senior Vice President, People Operations at Google, reveals the secrets and pitfalls of Google's "self-replicating talent machine," and how any organization can become a great place to work. Continue your talent acquisition transformation at Talent Connect 365: http://linkd.in/1s8SWeG

This talk suggests: > Never compromise on quality (it will kill culture and drive away the best) > Use science, structured interviews (to kill bias) > Give them a (bigger) reason to join (meaning) my further notes: 1) set a high standard (don't compromise, stay the course) 2) remove hiring managers from the hiring decisions (eliminate critical bias) 3) Use Assessment (Interviews aren't reliable ) 4) Job criteria: Cognitive Ability (problem solver, curious) , Leadership, Culture Fit, Role-related knowledge (a little confusing because he said "interviews are unreliable") 5) Structured interviews (same for everyone) -- hypotheticals/situational & behavioral 6) How you can Convince them to join: comes down to MEANING in Life (then the sales pitch for Google started and they almost lost me) 7) Find out how to meet your target market and creatively (around 28:00) <Job v. Career v. Calling> --> 1/3 see it as a calling <4X results if you can find a way to inspire meaning in people's work>

Hiring manager - avoid bias -> tend to hire friends, nephew, and important client's child.

High quality people - how to assess people? Get feedbacks - interview people very well - perform very well

Average - 

Googleyness - bring something new to the organization 

Intellectual humility 

People bring new things to us 

Figure out the rest - you have those three things 

Generalist - not specialist 

Clear standards - some easy grader, tough grader - Love people, every person looks great ...

Structure interviews - Every candidate gets same algorithms similar 

quality response - 

Give candidates the meaning to join 

  1. Set a high bar for quality and never compromise
  2. Assess candidates objectively ... science FTW
  3. Give candidates a reason to join

Leetcode premium: Google - time period - last 6 months - Frequency

 Dec. 2, 2020

Introduction

It is the first day of marathon. I will go over over 50 hard level algorithm and over 50 medium level algorithm on Leetcode premium, Google related algorithms. 

Hard work is needed



Data, Structure, and Science in Hiring at Google | Kerry Cathcart, Staffing Program Manager

 Here is the link. 

Invest early - hiring is the art

data analysis, scientific approach for hiring 

New research and new experience

Four E: 

  1. process is efficiency, effective, hiring right people
  2. candidate - user experience
  3. process - equitable - fair, not biased
Hiring committee

Four attributes:
  1. Role related knowledge - day one - varies, level, communication skills, code - day one 
  2. General cognitive ability - complex problem at workplace, figure out root cause 
  3. Leadership - being a great leader, ability to lead a team - take ownership at work, influence the change, rally the peers around, see a problem and speak up 
  4. Good or bad on behaviors 
  5. Google culture unique and good ...

6:59 PM/ 40:19 

ownership 

Googleyness 

- Google culture - concrete - what to look for in the interview process 

culture fit - not really explain why

  1. behaviors - 
  2. seek out feedback to improve
  3. ambiguity - wait for more info, or figure out what to do
13.05
Two kinds of questions to ask 

Behavioral 
Hypothetical 

Behavioral 
- Past focused
- Often begin with "Tell me about a time when "
- Useful to understand the impact a candidate has had in previous roles

Hypothetical 
Future focused
Often begin with "Image that..."
Useful to assess capacity for innovation in Google context

Dig into ...
What steps 
What resources
What do you do differently? 

Feedback - team member does not perform 
Drill up the information
What kind of information you gather? 
Think about assess the candidate

Rubics - assess 

Prioritize a portfolio of projects, cross organization 

Trap - first decent candidate to see
General hire or no hire - 
very detail interview feedback - take notes of specific answers 

Test candidate to get things done - company wide initiative 

20:00/ 40:19
Making hiring decisions by committee 
Benefits for Google long term 
Double down this - unconscious bias training - fairly and consistently 
My team - senior lead - feedback and continue to improve 

Keep the hiring trend and leadership - hiring is every one's job, not recruiter's 
Senior leaders - hiring committee - quality of work

Research shows three things to improve: 
  1. Duration of the process, how quickly it can give the offer to the candidates
  2. Candidate knows what to expect and how to prepare for the interview
  3. Candidate knows how to make impact for the company 

24% -> 48%, talk about experience about family and friends. 
Leverage you can improve - 
what to expect and how to perform in the interview 
Really benefits - concrete how to make contributions 
This is really you can do for us. 

How to measure candidate's experience? 
80% - not offer a job - recommend to the friends - 

Tuesday, December 1, 2020

7 benefits to go to office to work

Dec. 2, 2020

I like to talk about good things about working in the office instead of working remotely. 

I think that life is so beautiful to walk to office building, and then start to enjoy the art of lighting. 

Taking selfie

I need to take some selfie since I am aging. It is most challenge life to build wealth and play stock market in 2020. My weight just went up to 200 lb, I did not notice since I was too busy with so many things. 

I like to slow down and enjoy the weather, and all I can enjoy as a software programmer. 

Fitness is very important and there are so many ideas I can try to work on my weight control as well. 

I will load 7 selfies and talk about one benefit each time. 

Fact 1: 

It is my 10th year to work on the same building. I know that it is so important for me to appreciate what I have. Since March 2020, over 10 million people in USA lost their job. 

Fact 2: I remembered that I had hard time to live with hay fever, coughing and sneezing. I did not spend enough hours (40 hours+ at least) to work on hay fever research, and I scared people in the office. I could not go to work since I may sneeze unexpectedly. I decided to take two weeks vacation and learn how to improve hay fever issues in March, 2020. That is a lot of reading and studying, a lot of hours reading and study. 


Fact 3: After I took 2 weeks vacation break, I went back to work; and after one or two weeks, I got another complaint. I need to work on it again. I took another week vacation to figure out. 










I think that lighting is to serve people and make space more efficient for business an leisure use. The art of lighting is to choose good design of various products, and then serve people in different ways, my favorite lights are in-graded, wine-rack, and pendant lights from ceilings. 

  1. Daily commute - good exercise, close to nature
  2. Office environment - comfortable place to work on projects
  3. Compared to home office, there are more collaboration at office
  4. More time to take breaks, more time to walk
  5. Eat more healthy lunch
  6. ...
  7. ...

What is get measured, what is to be worked on: My Google 14 set mock interview performance on leetcode.com

Leetcode discuss: 317. Shortest Distance from All Buildings

 Here is the link. 

First practice - C# - BFS - Queue - Case studies - Easy to follow

Nov. 30, 2020
It is a hard level algorithm. I chose to write the solution using BFS algorithm.

Case study
Sometimes there is no solution.

For example,
case 1:
1 , 1, 0
1, 0, 0
There is no way to access the building (0,0) position building. Return should be -1. So it is important to record how many buildings in total first, and then record how many buildings are accessible starting from the position with value 0. Compare two numbers, if any building is not accessible, return -1.

case 2:
How to set visited in the matrix, and make sure to avoid revisit the same position?
1 0 1
0 0 1
0 0 1

Space complexity should not be big concern. I prefer to use a copy of given matrix grid to pass into function to run BFS, and the value will be changed to mark visited.

Two concerns in my design, first is to do not count the same building more than once. The tip is to change the building value 1 to -1, so it can not be counted more than once.

Secondly it is ok to change value 0 to -1 as a way to mark visited land, same value as visited building. No worry about sharing the same value.

Let me walk through one search and see if it can be optimized.

Start from (0, 1) position since the value is 0, and then calculate the smallest distance to any building if it is accessible using BFS. BFS is very powerful tool to ensure the smallest distance is found first and it can be recorded properly.

Add integer array {0, 1, 0} to the queue, and then start BFS search; Dequeue {0, 1, 1}, the position in the matrix is (0,1), and the distance is 0. Check the position is building or not. If it is, then mark visit the building, add distance to total distance, return since it is not allowed to cross the building. If it is land, then add four possible neighbors into Queue, increment distance with value 1.

It is important to walk through the steps by hand, so it is easy to spot issues in the design.
Second step is to add four neighbors of (0, 1) to the queue, third step is to dequeue one by one those four positions.

Left neighbor is with value 1, one building is found, distance+=steps, and mark (0,0) with value -1.
Right neighbor is with value 1, another building is found, distance+=steps, and mark (0, 2) with value -1.
Down neighbor is with value 0, continue to search it's found neighbors.
Up neighbor is out-of-range.

Skip more details afterwards.
I do not think that it is needed to prune the algorithm if all buildings are found. Just let BFS search all possible paths and naturally end.

How to have a smoothly practice?
I have to work on my attention not to mix variables under stress, one tip is to reuse same variable, this way is to avoid mixing variables.

I wrote DFS first, and then I noticed that it did not work. It took me less than a few minutes to change them using Queue. But I do think that I have to pay more attention before I write the code. Think more carefully.

Additional checkings include the following:

  1. All buildings are found starting any position with 0 value in the given matrix;
  2. Distance is updated if one building is found;
  3. Make matrix a copy to pass as a function argument, easy to mark visit using -1, avoid duplicate count of same building;
  4. Avoid index-out-of-range error, do not declare valid checking variable after out-of-range check. Since only if it is in the range, then it is safe to check valid value; Put all checkings in one giant statement.
  5. I mixed row and col with x and y in my outOfRangeEtc, better to reuse row and col.
public class Solution {
    public int ShortestDistance(int[][] grid) {
            if(grid == null || grid.Length == 0 || grid[0].Length == 0)
                return 0; 
        
            var rows = grid.Length; 
            var columns = grid[0].Length; 
        
            var buildingCount = 0; 
            for(int row = 0; row < rows; row++)
            {
                for(int col = 0; col < columns; col++)
                {
                    if(grid[row][col] == 1)
                    {
                        buildingCount++; 
                    }
                }
            }
        
            // make sure buidling found == buildingCount
            // distance - BFS - minimum
            var minDistance = Int32.MaxValue; 
        
            for(int row = 0; row < rows; row++)
            {
                for(int col = 0; col < columns; col++)
                {
                    var current = grid[row][col];
                    if(current != 0)
                        continue; 
                
                    var found = 0;                 
                    var distance = 0; 
                
                    var gridCopy = new int[rows][];
                    for(int row1 = 0; row1 < rows; row1++)
                    {
                        gridCopy[row1] = new int[columns];
                    }
                
                    for(int row1 = 0; row1 < rows; row1++)
                    {
                        for(int col1 = 0; col1 < columns; col1++)
                        {
                            gridCopy[row1][col1] = grid[row1][col1];
                        }
                    }
                
                    runBFS(gridCopy, row, col, ref found, ref distance);
                
                    if(found == buildingCount)
                    {
                        minDistance = Math.Min(minDistance, distance);
                    }
                }
            }
        
            return minDistance == Int32.MaxValue? -1: minDistance; 
        }
    
        private void runBFS(int[][] grid, int row, int col, ref int found, ref int distance)
        {
            var rows    = grid.Length; 
            var columns = grid[0].Length; 
        
            var queue = new Queue<int[]>(); 
            queue.Enqueue(new int[]{row, col, 0});

            while (queue.Count > 0)
            {
                var count = queue.Count;

                for (int i = 0; i < count; i++)
                {
                    var node = queue.Dequeue();

                    var x = node[0];
                    var y = node[1];
                    var steps = node[2];

                    var outOfRangeEtc = x < 0 || x >= rows || y < 0 || y >= columns ||
                     grid[x][y] == 2 || grid[x][y] == -1;
                    if (outOfRangeEtc)
                    {
                        continue;
                    }

                    if (grid[x][y] == 1)
                    {
                        grid[x][y] = -1;
                        distance += steps;
                        found++; 
                    }
                    else
                    {   // mark visit
                        grid[x][y] = -1;

                        queue.Enqueue(new int[] { x, y - 1, steps + 1 });
                        queue.Enqueue(new int[] { x, y + 1, steps + 1 });
                        queue.Enqueue(new int[] { x - 1, y, steps + 1 });
                        queue.Enqueue(new int[] { x + 1, y, steps + 1 });
                    }
                }
            } 
        }
}


14 set Google mock onsite interviews - Leetcode

 Dec. 1, 2020

Introduction

It is the first time I learn the value of $150 US dollars value. I paid subscription, and then I took the time to complete 14 set of Google mock onsite interviews. I failed and learned so many algorithms in less than one month. 

14 set Google mock onsite


What do I learn most from Google onsite preparation?

 Dec. 1, 2020

Introduction

I am thinking about what I learn most from Google onsite interview preparation. I just could not believe that I want to get an offer after three Amazon onsites, two facebook onsite, my first Google onsite. Time is up, and I just cannot finish another 14 set Facebook mock onsite interviews, over 10 Microsoft mock interviews, and 10 Amazon mock onsite interviews. 

What do I learn most from Google onsite preparation?

I just could not believe that I spent first five months to learn how to invest. I like to show my Leetcode submission history. 


I will figure out in last week preparation. It is my favorite project to work on. 

How to Lead 60,000 Employees | Laszlo Bock, Google's Former People Chief

 Here is the link. 

Laszlo Bock is a Senior Advisor at Google and the author of "Work Rules!" During his tenure at Google, he led Google's people function, and was responsible for attracting, developing, retaining, and delighting "Googlers." Under his leadership, Google was named the Best Company to Work For more than 30 times around the world, and received over 100 awards as an employer of choice. In 2010, Bock was named "Human Resources Executive of the Year" by HR Executive Magazine. At a special IVY Ideas Night in 2015, Bock shared insights from his new book and talked about the essentials of good leadership. IVY is the world's first Social University. To learn more, please visit www.ivy.com.


Transparency

collaborate, not driven by the fear

take the person out-of-job - open things up