收集整理的大公司面试中与编程相关题目

【本文内容全部从网络收集整理而来,不代表本人观点】

=======================================

M(B) http://www.mitbbs.com/article_t/JobHunting/32119951.html

1.  print binary tree level by level; solve it w/o using a queue
2. 给file path做normalization的老题,就是考虑 ./ ../啥的, 用stack做就行了;
题面完全是那个老印自己设计的,我一开始完全不知道他要干嘛。  后来面多了有经验
了,我想遇到这种估计给vague problem的, 应该一开始就跟他反复问清楚input /
output都需要考虑哪些情况。。。

===================================

1. write a function to calculate the cube square root of x
2. given a set of elements, all possible subset
3. prefix search -- given a set of words, and a prefix, find the words
starting with the prefix
4. anagram bucket - anagram means different words with the same character
set, e.g., 'cat' and 'act' are anagram . Given a set of words, group them by
anagram.

=========================================


1. iterator with filter, 跟这个帖子的 2A一样
http://www.mitbbs.com/article_t/JobHunting/32079701.html


2. 一个看似复杂的题目, 给一个类似keyboard的input UI, 好比说
ABCDEFG
HIJKLMN
....

当需要输入一个word的时候,光标总是从A开始,移动到第一个字母、再移动到第二个
字母、再移动到第三个字母。。。。。

given an input word,求算对应的光标怎么move的-- 其实就是先做好一个hashmap,
知道每个字母对应的坐标位置, 通过坐标的差值就知道怎么move的了

3。一个desgin 题目,手机里一个maze里撞球的游戏---拨一下球就一直移动到撞墙
为止。

设计用什么data structure, 用什么算法找 start 到exit的路径

4. 问了一些java 问题,static什么意思啥的, static Arraylist是什么意思,然后
就是fib数列一系列刨根问底。

recursion 解法复杂度分析; dynamic programming/ constant space version

5.具体的细节有点忘记了//orz
跟dictionary of words, prefix 什么的有关系。 我记得是给一个list of words,
prefix给那些词建立index.  好比如果apple, bee, cat这三个词, 分别用a/b/c 当
key建立index就可以;  如果是apple bee cat cedar, 就需要ca ce给cat/cedar建立
index

=======================
1.2D sorted array里面search for a target value, 版上也有讨论的

2. distributed 算法找中值:  N个machine, 每个machine有M 个 4byte int, 设计一
个算法找median

3. fork题目。  我不懂fork是啥,面试的费了好大力气给我讲这是什么意思orz, 怎
么利用fork得到一个pid  & 从parent process里面分裂一个child process。  child
process里看到的pid跟parent process里面的pid不一样。

题目的要求是,用fork 分裂出两个child process, 这样分裂 L level就好比一个L
depth binary tree, 象print treenode一样  print出pid
4. 这个题目
http://www.mitbbs.com/article_t0/JobHunting/32091541.html

--

================================

G:http://www.mitbbs.com/article_t/JobHunting/32119891.html

G,onsite
==========
1. Three coke machines. Each one has two values min & max, which means if
you get coke from this machine it will load you a random volume in the range
[min, max]. Given a cup size n and minimum soda volume m, show if it's
possible to make it from these machines.

比如三台machine(50, 100), (100, 200), (500, 1000). n=110, m=40, yes. n=90, m
=40, no. n=100, m=60, no.
第一题讨论了很久,后面代码写完base case有问题,又讨论很久。。。。我不知道该
怎么解释,我不是举了个例子嘛。就是说我去接可乐我可以选任何一台机器,不限次数
,但要保证打的可乐不会溢出我的杯子,而且最后要大于等于m毫升比如。
def getCoke(min, max, m, n) :
    if (n<0 or m>n) :
          return False

    for i in xrange(3) :
          if (m<=min[i] and n>=max[i]) or getCoke(min, max, m-min[i], n-max[
i])
                 return True

   return False

我觉得这是对的。
这题就是一个完全背包问题,每个coke machine的下限是value,上限是重量,杯子的最
大容量就是包的容积。看打包之后的value总值能不能超过那个给定值。

===========


2. n*m grids. How many ways from (0,0) to (n,m).

这题简单,我把递归非递归都写了一遍。
===========
3. Given a sorted array, make a balanced binary search tree.
=============================
4. n 2D integer points. Find an point so that the total distances from each
one to this point are minimal. Distance of (x1, y1) and (x2, y2) is defined
as |x1-x2| + |y1-y2|.

这题挺郁闷的,觉得面试官不给力。。我说可以化解为一维的问题因为x,y
independent,他问了我半天为什么。
我的想法是求出所有x的median和所有y的median,定义他们为点c,然后找所有的点中
距离点c最近的一点就是结果
min(sum(|x-xi|)+sum(|y-yi|)) = min(sum|x-xi|) + min(sum|y-yi|)

x跟y不是没关系的吗,随便取啊。。那个要求的点不需要是这n个点里面的。。。。

那道数学题我上来就降成一维,跟他说independent把式子写给他看他还是继续问什么
,我觉得我有点被问急了,因为很简单啊,过了一会才想到可以用反证法跟他讲。

就是把所有点按x排序, 取median的x值Xm
把所有点按y排序, 取median的y值Ym

答案就是(Xm, Ym)

=============================
5. About Inheritance & polymiorphism. A class, like LinkedList in Java,  has
two methods add & addall. Write a subclass to count how many times "add" is
called.

Be careful about how "addall" is implemented.

这题中间犯了个小错误,后面又讨论了下怎么处理多线程。

最后一题考点在哪呢? 不就是重载add函数??

如果它的addAll没有call add呢,这样那个count也要加n~ 可能我题没说清楚,大概是
这个list每次insert一次count就加一吧。。
===================


======================================

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值