谷歌面试经历

与谷歌的缘分是始于半年前的Codejam,当时做它只是为了T-shirt,最终倒在online 2-round(前1000有T-shirt,我1500左右)。

 

八月下旬接到谷歌中国的HR打来的电话,邀请我投简历。

 

1st Phone Interview - Google

9月27日 17:00 p.m.

先是简短自我介绍。

然后两道题目结束。(面试时需要在online docs写代码,面试官可以看到你写的实时代码)

Problem 1:

Given a binary tree, check whether it is a complete binary tree.

这是我当时写的伪代码:

const int maxn=10005;
struct {
    int lef, rig;
}node[maxn];

bool bfs(int root){
    queue<node>q;
    q.push(node[root]);
    node head, next;
    int flag=0;
    while(!q.empty()){
        head=q.front();
        if(flag){
            if(head.lef!=NULL||head.rig!=NULL)
            return false;

}
        if(head.lef==NULL)
            flag=1;
        else 
            q.push(node[head.lef]);
        if(flag){
            if(head.rig!=NULL)
            return false;

}

if(head.rig==NULL)

    flag=1;

else 

    q.push(node[head.rig]);


}

return true;
}

Problem 2:

Bowen's question:
Given a set of person labeled from 1 through N. Given some items to show the relationship between them.
There are two kinds of relationship:
1. X Y Friend, means X and Y are friend.
2. X Y Enemy, means X and Y are enemy.
Two rules for relationship:
1. If X and Y are friend, Y and Z are friend, then X and Z are friend.
2. If X and Y are enemy, Y and Z are enemy, then X and Z are friend.
Given a set of queries, each has two number X Y, calculate the relationship between X and Y (Friend, Enemy or No relationship).

先给他讲了思路,然后写了第一种关系的代码

当时写的伪代码

int p[N+5], depth[N+5];  

void init(){
    for(int i=1; i<=N; i++){
        p[i]=i;
        depth[i]=0;

}
}

int find(int x){
    if(p[x]!=x)
        p[x]=find(p[x]);

return p[x];    
}

void union_set(int x, int y){
    x=find(x);

y=find(y);

if(depth[x]>depth[y])

    p[y]=x;

else p[x]=y;

if(depth[x]==depth[y])depth[y]++;
}

int main(){

}



HR通知我二面的时候,说一面面试官对我评价挺好的。


 2st Phone Interview - Google

2012/10/16 7:30 a.m.

这次是个在美国出差的资深工程师,由于时差时间定在一大早。

上来又是让我自我介绍,说了无数遍,我就随便说了下。

第一个问题,让我讲一下做过的项目,我说没有,PASS。。。。

第二个问题,给一个二叉树,转化成线索二叉树。先是不理解题意,理解了又想了好久。

(当时写出来的伪代码)

#include<stack>
using namespace std;
struct node{
    int lef, rig, pre, next;
}bt[MAXN];
int root;
stack<int> s;
void dfs(int x){

if(bt[x].lef!=NULL)

dfs(bt[x].lef);

s.push(x);   
    if(bt[x].rig!=NULL)
        dfs(bt[x].rig);
}

void solve(){
    s.clear();
    dfs(root);
    int next=NULL;
    int tmp,
    while(!s.empty()){
        tmp=s.top();
        s.pop();

bt[tmp].next=next;
        next=tmp;
        bt[tmp].pre=s.top();
       

}
}


 

第三个问题:求逆序数。忘了线段树求逆序数的方法,想了很久,他提示用归并,我就稀里糊涂的写了个。

伪代码:

int merge_sort(int a[], int lef, int rig){
    int mid = (lef + rig) /2;

if(lef==rig)return 0;

if(lef==rig-1){

    if(a[lef]>a[rig]){

swap(a[lef], a[rig]);

return 1;

}

    else return 0;

}

int tmp=merge_sort(a, lef, mid)+merge_sort(a, mid+1, 

rig);

int t1=mid+1;

int res=0;

for(int i=lef; i<=mid; i++){

    while(t1<=rig&&a[i]>a[t1]){

        t1++;

}

res+=t1-mid-1;   

}

排序(a+lef, a+rig);//O(n)复杂度

return tmp+res;
}


面试完自我感觉很差,这些简单题都想了那么久,而且代码写的很挫,写的时候还各种粗心。归根结底还是我实力不足。

大概当天晚上五点多,HR打来电话,问我面试情况,然后告诉我被拒了,还安慰了我两句,告诉我过两年想来了还可以再找她。

知道被拒之后,挺难受的,但也是解脱,毕竟和百度已经签了,而且百度给我做研发,毁约总是不好的。

毕业之前应该不会再去面其他公司,好好把握最后的大学时光吧。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值