2014-05-12 06:19 题目链接 原题: Given an input list of lists.. flatten the list. For e.g. {{,}, {}, {,}} ... Output should be {, , , , } 题目:给定一个二维数组,把它展开成一维数组. 解法:之前做了一道题,把维度不定的数组展开成一维数组.这题也能用那题的代码来解决. 代码: # http://www.careercup.com/question?id=54855212245…
2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说说思路吧.不知道这算什么类型的面试题,真遇到的话也算是倒了霉了.想了半天恍然大悟:原来是考察设计模式.查了相关资料后发现命令模式比较符合题意,所以就依葫芦画瓢写了个例子. 代码: // http://www.careercup.com/question?id=6366101810184192 int…
2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计一个支持并行读写并保证数据一致性的数据库锁. 解法:这是什么范畴的面试题?对于我这种完全没有相关项目经验的人,还真是无从下手.翻了书之后顺便重新复习了一下共享锁.互斥锁的概念.说白了,这些都是课本上的基础知识,可是毕业没多久就忘光了.看来知识不用,保质期比水果还短.然后我琢磨着锁的模型,写了个模拟的…
2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two arrays find the intersection of those two arrays. Besides using hash table can we attain the same time complexity that is O(m+n) by using some other ap…
2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you design the system so that when map longitudeDelta/latitdueDelta changed you add additional pins on map for regions that was not previously cover. In anoth…
2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中有一个偏重.给定一个不能给出具体重量,但可以比较轻重的天平,称2次找出那个重球. 解法:9个球三等分,称一次找出包含重球的那三个.3个球三等分,称一次找出重球. 代码: // http://www.careercup.com/question?id=5204967652589568 Answer:…
2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡着的人也看不见光,所以震动应该是更靠谱的.个人觉得做成手表戴在手上的时候,才能保证震动有用.这样,睡觉的时候就得戴着手表了. 代码: // http://www.careercup.com/question?id=5175246478901248 Answer: Deaf people can't…
2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书上,我自己回忆了一点.我想就算是面试官也不会一字一句地要求你背书的,对于要点掌握住就可以了. 代码: // http://www.careercup.com/question?id=5718181884723200 Answer: Process: . Basic element of resour…
2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } else { ) + func_fibonacci(n-)); } } 题目:求上面函数的复杂度. 解法:时间复杂度就是斐波那契数,空间也是. 代码: // http://www.careercup.com/question?id=5173689888800768 /* T(0) = 1; T(1) =…
2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best solution. 题目:给数组进行循环移位,给出最优解. 解法:首先要考虑n的范围,对于负数和超过数组长度的数,先进行取模操作.然后用三次反转数组就可以完成循环移位. 代码: // http://www.careercup.com/question?id=6282862240202752 #incl…
2014-05-11 03:37 题目链接 原题: You have three jars filled with candies. One jar is filled with banana candies, one jar is filled with lemon candies and one jar has a mix of both. All the jars are mislabelled (i.e. all the jars have wrong labels about what…
2014-05-11 02:56 题目链接 原题: Write a function called FooBar that takes input integer n and prints all the numbers upto n then print then print and , print "FooBar". Otherwise just print the number. ) should print as follows: Foo Bar Foo Foo Bar Foo…
2014-05-10 23:45 题目链接 原题: Arrange the numbers in an array in alternating order. For example if the array is [a1, a2, a3, a4.. ]arrange the array such that b1<=b2>=b3<=b4 and so on. Sampe Input: Sample Output: < > < > < 题目:给定一个数组,请调…
2014-05-10 23:26 题目链接 原题: what is the best,worst and average case complexity for fibonacci no.s ..explain? 题目:计算斐波那契数的最好.最坏.平均复杂度是多少? 解法:计算斐波那契数倒是有好多方法,不过平均复杂度是怎么个说法?我写了三种解法:1. 白痴级的二路递归,复杂度是指数级的.2. 普通的递推算法,复杂度是线性的.3. 矩阵陈法,用快速幂可以达到对数级的时间. 代码: // http:…
2014-05-10 22:58 题目链接 原题: Three points are given A(x1, y1), B(x2, y2), C(x3, y3). Write a method returning an array of points (x, y) inside the triangle ABC. 题目:给定三个点,找出所有这三点组成的三角形内的整点.(不能组成三角形也无所谓,结果为空即可.) 解法:出题者没有说是整点,但如果不是整点,就有无穷多个了.求整点的个数可以用Pick定…
2014-05-10 22:17 题目链接 原题: A draw method is given, write a function to draw a chess board. The Draw method, draws a square and has parameters row position, column position and color. 题目:给定一个draw()方法,请画出一个国际象棋盘.函数参数有行.列和颜色. 解法:这个题是想考察什么?没想太明白,先写个出来吧.我完…
2014-05-10 21:56 题目链接 原题: Suppose you get number of unique users every second from bing For eg, ,,,,,etc You need to write a web service method , such that it takes the input n, which then you need to ,, 题目:从n个数里找出m个最小的数. 解法1:题目虽然没有要求结果是否有序,也没有说算法是否是…
2014-05-10 20:31 题目链接 原题: Given an array of integers and a length L, find a sub-array of length L such that the products of all integers are the biggest. Example: Input: {, , -, -, }, Output: {-,-,} 题目:给定一个整数数组,其中包含正数.负数或者0.请找出乘积最大的子数组(子数组是连续的,子序列可以不…
2014-05-10 07:06 题目链接 原题: Suppose you have a collection of collection Eg : CEO-> Vps-> GMs ->.. CEO will contain collection of VP's, VP's will have collection of GM's and so on. Suppose you need to find a particular GM is the alias is given. Writ…
2014-05-10 06:51 题目链接 原题: "How would you find the number of gas stations in the United States?" *You cannot look up any concrete information (like the average number of gas stations per state), but you need to yield an accurate answer. 题目:你要如何搞清…
2014-05-10 06:38 题目链接 原题: What do you think is the next big thing in technology? For example, search engine is Google, social media is Facebook, etc. etc... 题目:你觉得下一个IT界的热点是什么?Google有搜索引擎,Facebook有社交网络等等. 解法:现在都在说移动互联网和可穿戴设备.貌似现在硬件的创新更加放得开了,看看各家巨头收购的…
2014-05-12 07:44 题目链接 原题: Given an array having unique integers, each lying within the range <x<, how numbers at a time in memory. 题目:一个数组里有16000个不重复的整数,所有元素都在1和20000之间.如果你一次至多能在内存里放1000个整数,你要如何排序整个数组? 解法1:这个题目表述是不是有问题?数组本身就是内存的数据吧?内存装不下还叫数组?既然所有元素都…
2014-05-12 07:27 题目链接 原题: Convert a number to a number 题目:把二进制数转化成四进制数. 解法:四是二的倍数,所以两位变一位就可以了. 代码: // http://www.careercup.com/question?id=24313662 #include <iostream> #include <string> using namespace std; string baseConvert2To4(string num) {…
2014-05-12 07:17 题目链接 原题: Given below is a tree/trie A B c D e F a<b<e<>>c<>d<f<>>> above string represents the following trie/tree (visualize) and assume that there exisits a serialize method that performs above. Now,…
2014-05-12 07:10 题目链接 原题: Write a thread safe data structure such that there could be only one writer at a time but there could be n readers reading the data. You can consider that incrementing or decrementing a variable is an atomic operation. If mo…
2014-05-12 06:56 题目链接 原题: A link list contains following elements struct node{ int data; node* next; node* random; } Given head of such a linked list write a function who copies such a linked list and returns the head of the new list. So if in the or…
2014-05-12 06:42 题目链接 原题: Write your own regular expression parser for following condition: az*b can match any or more Z's between. for e.g. azb, azzzb etc. a.b can match anything between a and b e.g. ajsdskjb etc. Your function will have to paramete…
2014-05-12 06:27 题目链接 原题: Find the max height of a binary tree. 题目:计算二叉树的最大高度. 解法:最大高度?高度不就是最深的叶子节点到根节点的路径长度吗?我就当是高度吧,递归解决. 代码: // http://www.careercup.com/question?id=5672369481842688 #include <algorithm> #include <iostream> #include <sstr…
2014-05-12 06:12 题目链接 原题: Write a function to retrieve the number of a occurrences of a substring(even the reverse of a substring) in a string without using the java substring() method. Ex: times (dc, cd). 题目:写一个函数来统计模式串在文本中出现的次数,不过这次模式的反转也算数.比如“abcd…
2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, which is to find a shortest path from a starting node back to the starting node and visits all other node exactly once. 题目:如何用Dijkstra算法来解决TSP问题?(谁会出这种…