A Za, A Za, Fighting...
坚信:勤能补拙
Google面试题
来源:
http://coolshell.cn/articles/3345.html
Software Engineer
Why are manhole covers round? (陈皓:为什么下水井盖是圆的?这是有N种答案的,上Wiki看看吧)
What is the difference between a mutex and a semaphore? Which one would you use to protect access to an increment operation?
A man pushed his car to a hotel and lost his fortune. What happened? (陈皓:脑筋急转弯?他在玩大富翁游戏?!!)
Explain the significance of “dead beef”.(陈皓:要是你看到的是16进制 DEAD BEEF,你会觉得这是什么?IPv6的地址?)
Write a C program which measures the the speed of a context switch on a UNIX/Linux system.
Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7.(陈皓:上StackOverflow看看吧,经典的问题)
Describe the algorithm for a depth-first graph traversal.
Design a class library for writing card games. (陈皓:用一系列的类来设计一个扑克游戏,设计题)
You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write a the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message so that Eve cannot read your phone number?(陈皓:协议+数字加密,我试想了一个,纸条上可以这样写,“Bob,请把我的手机号以MD5算法加密后的字符串,比对下面的字符串——XXXXXX,它们是一样的吗?”)
How are cookies passed in the HTTP protocol?
Design the SQL database tables for a car rental database.
Write a regular expression which matches a email address. (陈皓:上StackOverflow查相当的问题吧。)
Write a function f(a, b) which takes two character string arguments and returns a string containing only the characters found in both strings in the order of a. Write a version which is order N-squared and one which is order N.(陈皓:算法题,不难,不说了。一个O(n^2)和一个O(n)的算法复杂度)
You are given a the source to a application which is crashing when run. After running it 10 times in a debugger, you find it never crashes in the same place. The application is single threaded, and uses only the C standard library. What programming errors could be causing this crash? How would you test each one? (陈皓:和随机数有关系?或是时间?)
Explain how congestion control works in the TCP protocol.
In Java, what is the difference between final, finally, and finalize?
What is multithreaded programming? What is a deadlock?
Write a function (with helper functions if needed) called to Excel that takes an excel column value (A,B,C,D…AA,AB,AC,… AAA..) and returns a corresponding integer value (A=1,B=2,… AA=26..).
You have a stream of infinite queries (ie: real time Google search queries that people are entering). Describe how you would go about finding a good estimate of 1000 samples from this never ending set of data and then write code for it.
Tree search algorithms. Write BFS and DFS code, explain run time and space requirements. Modify the code to handle trees with weighted edges and loops with BFS and DFS, make the code print out path to goal state.
You are given a list of numbers. When you reach the end of the list you will come back to the beginning of the list (a circular list). Write the most efficient algorithm to find the minimum # in this list. Find any given # in the list. The numbers in the list are always increasing but you don’t know where the circular list begins, ie: 38, 40, 55, 89, 6, 13, 20, 23, 36. (陈皓:循环排序数组的二分查找问题)
Describe the data structure that is used to manage memory. (stack)
What’s the difference between local and global variables?
If you have 1 million integers, how would you sort them efficiently? (modify a specific sorting algorithm to solve this)
In Java, what is the difference between static, final, and const. (if you don’t know Java they will ask something similar for C or C++).
Talk about your class projects or work projects (pick something easy)… then describe how you could make them more efficient (in terms of algorithms).
Suppose you have an NxN matrix of positive and negative integers. Write some code that finds the sub-matrix with the maximum sum of its elements.(陈皓:以前见过一维数组的这个问题,现在是二维的。感觉应该是把二维的第一行的最大和的区间算出来,然后再在这个基础之上进行二维的分析。思路应该是这个,不过具体的算法还需要想一想)
Write some code to reverse a string.
Implement division (without using the divide operator, obviously).(陈皓:想一想手算除法的过程。)
Write some code to find all permutations of the letters in a particular string.
What method would you use to look up a word in a dictionary? (陈皓:使用排序,哈希,树等算法和数据结构)
Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?
You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you fine the ball that is heavier by using a balance and only two weighings?
What is the C-language command for opening a connection with a foreign host over the internet?
Design and describe a system/application that will most efficiently produce a report of the top 1 million Google search requests. These are the particulars: 1) You are given 12 servers to work with. They are all dual-processor machines with 4Gb of RAM, 4x400GB hard drives and networked together.(Basically, nothing more than high-end PC’s) 2) The log data has already been cleaned for you. It consists of 100 Billion log lines, broken down into 12 320 GB files of 40-byte search terms per line. 3) You can use only custom written applications or available free open-source software.
There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1]. Solve it without division operator and in O(n).(陈皓:注意其不能使用除法。算法思路是这样的,把output[i]=a[i]左边的乘积 x a[i]右边的乘积,所以,我们可以分两个循环,第一次先把A[i]左边的乘积放在Output[i]中,第二次把A[i]右边的乘积算出来。我们先看第一次的循环,使用迭代累积的方式,代码如下:for(r=1; i=0; i<n-1; i++){ Output[i]=r; r*=a[i]; },看明白了吧。第二次的循环我就不说了,方法一样的。)
There is a linked list of numbers of length N. N is very large and you don’t know N. You have to write a function that will return k random numbers from the list. Numbers should be completely random. Hint: 1. Use random function rand() (returns a number between 0 and 1) and irand() (return either 0 or 1) 2. It should be done in O(n).(陈皓:本题其实不难。在遍历链表的同时一边生成随机数,一边记录最大的K个随机数和其链接地址。)
Find or determine non existence of a number in a sorted list of N numbers where the numbers range over M, M>> N and N large enough to span multiple disks. Algorithm to beat O(log n) bonus points for constant time algorithm.(陈皓:使用bitmap,如果一个长整形有64位,那么我们可以使用M/64个bitmap)
You are given a game of Tic Tac Toe. You have to write a function in which you pass the whole game and name of a player. The function will return whether the player has won the game or not. First you to decide which data structure you will use for the game. You need to tell the algorithm first and then need to write the code. Note: Some position may be blank in the game। So your data structure should consider this condition also.
You are given an array [a1 To an] and we have to construct another array [b1 To bn] where bi = a1*a2*…*an/ai. you are allowed to use only constant space and the time complexity is O(n). No divisions are allowed.(陈皓:前面说过了)
How do you put a Binary Search Tree in an array in a efficient manner. Hint :: If the node is stored at the ith position and its children are at 2i and 2i+1(I mean level order wise)Its not the most efficient way.(陈皓:按顺序遍历树)
How do you find out the fifth maximum element in an Binary Search Tree in efficient manner. Note: You should not use use any extra space. i.e sorting Binary Search Tree and storing the results in an array and listing out the fifth element.
Given a Data Structure having first n integers and next n chars. A = i1 i2 i3 … iN c1 c2 c3 … cN.Write an in-place algorithm to rearrange the elements of the array ass A = i1 c1 i2 c2 … in cn(陈皓:这个算法其实就是从中间开始交换元素,代码:for(i=n-1; i>1; i++) { for(j=i; j<2*n-i; j+=2) { swap(a[j], a[j+1]); } },不好意思写在同一行上了。)
Given two sequences of items, find the items whose absolute number increases or decreases the most when comparing one sequence with the other by reading the sequence only once.
Given That One of the strings is very very long , and the other one could be of various sizes. Windowing will result in O(N+M) solution but could it be better? May be NlogM or even better?
How many lines can be drawn in a 2D plane such that they are equidistant from 3 non-collinear points?
Let’s say you have to construct Google maps from scratch and guide a person standing on Gateway of India (Mumbai) to India Gate(Delhi). How do you do the same?
Given that you have one string of length N and M small strings of length L. How do you efficiently find the occurrence of each small string in the larger one?
Given a binary tree, programmatically you need to prove it is a binary search tree.
You are given a small sorted list of numbers, and a very very long sorted list of numbers – so long that it had to be put on a disk in different blocks. How would you find those short list numbers in the bigger one?
Suppose you have given N companies, and we want to eventually merge them into one big company. How many ways are theres to merge?
Given a file of 4 billion 32-bit integers, how to find one that appears at least twice? (陈皓:我能想到的是拆分成若干个小数组,排序,然后一点点归并起来)
Write a program for displaying the ten most frequent words in a file such that your program should be efficient in all complexity measures.(陈皓:你可能需要看看这篇文章
Finding Frequent Items in Data Streams
)
Design a stack. We want to push, pop, and also, retrieve the minimum element in constant time.
Given a set of coin denominators, find the minimum number of coins to give a certain amount of change.(陈皓:你应该查看一下这篇文章:
Coin Change Problem
)
Given an array, i) find the longest continuous increasing subsequence. ii) find the longest increasing subsequence.(陈皓:这个题不难,O(n)算法是边遍历边记录当前最大的连续的长度。)
Suppose we have N companies, and we want to eventually merge them into one big company. How many ways are there to merge?
Write a function to find the middle node of a single link list. (陈皓:我能想到的算法是——设置两个指针p1和p2,每一次,p1走两步,p2走一步,这样,当p1走到最后时,p2就在中间)
Given two binary trees, write a compare function to check if they are equal or not. Being equal means that they have the same value and same structure.(陈皓:这个很简单,使用递归算法。)
Implement put/get methods of a fixed size cache with LRU replacement algorithm.
You are given with three sorted arrays ( in ascending order), you are required to find a triplet ( one element from each array) such that distance is minimum. Distance is defined like this : If a[i], b[j] and c[k] are three elements then distance=max(abs(a[i]-b[j]),abs(a[i]-c[k]),abs(b[j]-c[k]))” Please give a solution in O(n) time complexity(陈皓:三个指针,a, b, c分别指向三个数组头,假设:a[0]<b[0]<c[0],推进a直到a[i]>b[0],计算 abs(a[i-1] – c[0]),把结果保存在min中。现在情况变成找 a[i], b[0],c[0],重复上述过程,如果有一个新的值比min要小,那就取代现有的min。)
How does C++ deal with constructors and deconstructors of a class and its child class?
Write a function that flips the bits inside a byte (either in C++ or Java). Write an algorithm that take a list of n words, and an integer m, and retrieves the mth most frequent word in that list.
What’s 2 to the power of 64?
Given that you have one string of length N and M small strings of length L. How do you efficiently find the occurrence of each small string in the larger one? (陈皓:我能想到的是——把那M个小字串排个序,然后遍历大字串,并在那M个字串中以二分取中的方式查找。)
How do you find out the fifth maximum element in an Binary Search Tree in efficient manner.
Suppose we have N companies, and we want to eventually merge them into one big company. How many ways are there to merge?
There is linked list of millions of node and you do not know the length of it. Write a function which will return a random number from the list.
You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write a the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message so that Eve cannot read your phone number?
How long it would take to sort 1 trillion numbers? Come up with a good estimate.
Order the functions in order of their asymptotic performance: 1) 2^n 2) n^100 3) n! 4) n^n
There are some data represented by(x,y,z). Now we want to find the Kth least data. We say (x1, y1, z1) > (x2, y2, z2) when value(x1, y1, z1) > value(x2, y2, z2) where value(x,y,z) = (2^x)*(3^y)*(5^z). Now we can not get it by calculating value(x,y,z) or through other indirect calculations as lg(value(x,y,z)). How to solve it?
How many degrees are there in the angle between the hour and minute hands of a clock when the time is a quarter past three?
Given an array whose elements are sorted, return the index of a the first occurrence of a specific integer. Do this in sub-linear time. I.e. do not just go through each element searching for that element.
Given two linked lists, return the intersection of the two lists: i.e. return a list containing only the elements that occur in both of the input lists. (陈皓:把第一个链表存入hash表,然后遍历第二个链表。不知道还没有更好的方法。)
What’s the difference between a hashtable and a hashmap?
If a person dials a sequence of numbers on the telephone, what possible words/strings can be formed from the letters associated with those numbers?(陈皓:这个问题和美国的电话有关系,大家可以试着想一下我们发短信的手机,按数字键出字母,一个组合的数学问题。)
How would you reverse the image on an n by n matrix where each pixel is represented by a bit?
Create a fast cached storage mechanism that, given a limitation on the amount of cache memory, will ensure that only the least recently used items are discarded when the cache memory is reached when inserting a new item. It supports 2 functions: String get(T t) and void put(String k, T t).
Create a cost model that allows Google to make purchasing decisions on to compare the cost of purchasing more RAM memory for their servers vs. buying more disk space.
Design an algorithm to play a game of Frogger and then code the solution. The object of the game is to direct a frog to avoid cars while crossing a busy road. You may represent a road lane via an array. Generalize the solution for an N-lane road.
What sort would you use if you had a large data set on disk and a small amount of ram to work with?
What sort would you use if you required tight max time bounds and wanted highly regular performance.
How would you store 1 million phone numbers?(陈皓:试想电话是有区段的,可以把区段统一保存,Flyweight设计模式)
Design a 2D dungeon crawling game. It must allow for various items in the maze – walls, objects, and computer-controlled characters. (The focus was on the class structures, and how to optimize the experience for the user as s/he travels through the dungeon.)
What is the size of the C structure below on a 32-bit system? On a 64-bit? (陈皓:注意编译器的对齐)
struct foo {
char a;
char* b;
};
posted on 2011-07-14 10:13
simplyzhao
阅读(540)
评论(0)
编辑
收藏
引用
所属分类:
M_面试题集锦
只有注册用户
登录
后才能发表评论。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
相关文章:
数对之差的最大值
根据(1,5)随机数生成器,生成(1,7)之内的随机数
从n个items中随机选择m个的问题
Google面试题
扑克牌的顺子
C++基础题
顺时针打印矩阵
不用+、-、×、÷数字运算符做加法
和为n连续正数序列
跳台阶问题
网站导航:
博客园
IT新闻
BlogJava
知识库
博问
管理
导航
C++博客
首页
新随笔
联系
聚合
管理
<
2011年10月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
统计
随笔 - 209
文章 - 0
评论 - 7
引用 - 0
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔分类
A_排序(7)
(rss)
B_搜索(47)
(rss)
C_动态规划(25)
(rss)
D_贪心(1)
(rss)
E_数据结构(6)
(rss)
F_图算法(16)
(rss)
G_其他(42)
(rss)
M_面试题集锦(17)
(rss)
P_珠玑
(rss)
R_找工复习2011(42)
(rss)
Z_小小知识点(3)
(rss)
随笔档案
2012年2月 (1)
2011年10月 (7)
2011年9月 (14)
2011年8月 (14)
2011年7月 (15)
2011年6月 (9)
2011年5月 (6)
2010年11月 (6)
2010年10月 (28)
2010年9月 (30)
2010年8月 (40)
2010年7月 (32)
2010年6月 (7)
搜索
最新评论
1. re: 2011字符串-最长重复子串,后缀数组[未登录]
5123
--123
2. re: 2011找工复习计划
明年秋季开找工作,表示难望楼主项背,学习了!
--QWhy
3. re: 2011找工复习计划
同学你好厉害呀!
--QWhy
4. re: 2011分治-平面最近点对(附C++源代码)
好东西啊,非常感谢!写的很简洁
--co
5. re: 2011知识点 - 优先级反转
@simplyzhao
呵呵,我最近也在找工作,国庆后去Marvell面试,不知道博主有没有时间交流下。
我的邮箱就是我的用户名@gmail。
--williamwue
阅读排行榜
1. epoll方法实现non-blocking socket(4629)
2. 根据(1,5)随机数生成器,生成(1,7)之内的随机数(3424)
3. [Tips][Original] qsort应用于指针数组与二维数组(字符)的差异(2113)
4. 2011分治-平面最近点对(附C++源代码)(1125)
5. 2011知识点 - 优先级反转(925)
评论排行榜
1. 2011知识点 - 优先级反转(3)
2. 2011找工复习计划(2)
3. 2011分治-平面最近点对(附C++源代码)(1)
4. 2011字符串-最长重复子串,后缀数组(1)
5. 2011知识点-TCP 区分消息边界[zz](0)