2014-05-06 01:40 题目链接 原题: Give a N*N matrix, print it out diagonally. Follow up, if it is a M*N matrix, how to print it out. Example: print: 题目:按照题目示例给出的方式,输出一个矩阵. 解法:按题意写代码即可. 代码: // http://www.careercup.com/question?id=5661939564806144 #include <cs…
2014-05-03 22:10 题目链接 原题: Given a dictionary, and a list of letters ( or consider as a string), find the longest word that only uses letters from the string. [I didn't meet this question, what's the best solution?] 题目:给定一个字符串,和一个字典.从字典中找出一个最长的词,并且这个词…
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问题?(谁会出这种…
2014-05-08 21:33 题目链接 原题: largest number that an int variable can fit given a memory of certain size 题目:给定特定内存大小,请问int型的变量能表示的最大整数是多少? 解法:这个“Guy”出的题目总是这样表意不清.特定大小的内存是什么意思?他要说的是字长吧?16位int占两字节,32位以后int都占四字节.这样能表示的最大整数就是(1 << sizeof(int) * 8  - 1) - 1.…
2014-05-06 10:18 题目链接 原题: Given a ,) (,) (,), (,) should be returned. Some suggest to use Interval Tree to get this done in O(logn), but I did not understand how to construct and use the Interval Tree after reading its wiki page. Is there any other w…
2014-05-06 07:11 题目链接 原题: Find a shortest path ,) to (N,N), assume is destination, use memorization to cache the result. Here is my code. I am not sure if I am caching it right. 题目:给定一个N * N的矩阵,找出从(0, 0)到(n - 1, n - 1)的最短路径.此人在后面还贴上了自己的代码,从代码水平上看此人实力…
2014-05-08 23:18 题目链接 原题: If you have data coming in rapid succession what is the best way of dealing with redundant data? 题目:如果你有大量数据流入,如何处理冗余数据? 解法:又是“Guy”出的题,题意不清,没有情景.神马意思?做个Cache吧. 代码: // http://www.careercup.com/question?id=5680330589601792 //…
2014-05-08 22:55 题目链接 原题: Given a list of strings. Produce a list of the longest common suffixes. If it asks for longest common substring, then building a suffix tree should be the way to go. But how should we implement this if it is for longest comm…
2014-05-08 22:42 题目链接 原题: How would you split a search query across multiple machines? 题目:如何把一个搜索query分发到多个机器上? 解法:又是“Guy”出的题目.对query字符串算取数字签名,然后对集群的机器数量取模,就可以得到对应落在的机器了. 代码: // http://www.careercup.com/question?id=5377673471721472 // Answer: // The…
2014-05-08 22:27 题目链接 原题: What's the tracking algorithm of nearest location to some friends that are located in a grid region? 题目:在一个格点坐标的地图里,如何追踪到一个朋友附近最近的地标? 解法:我都不知道怎么翻译,这又是“Guy”出的一道莫名其妙的题目.但你不断遇到这种不知所云的题目时,很容易情绪暴躁.You just don't argue with a jerk…
2014-05-08 22:09 题目链接 原题: Implement a class to create timer object in OOP 题目:用OOP思想设计一个计时器类. 解法:我根据自己的思路,用clock()函数为工具,提供启动.停止.显示时长.重置四个方法. 代码: // http://www.careercup.com/question?id=5692127791022080 #include <ctime> #include <iostream> #incl…
2014-05-08 09:32 题目链接 原题: Given a binary tree, how would you copy it from one machine to the other, assume you have a flash drive. I believe we should write the binary tree to file and have the other machine de-serialize it. But how should we do it?…
2014-05-08 08:26 题目链接 原题: Given a preorder traversal, create a binary search tree in optimized time 题目:给定一个二叉搜索树的前序遍历,请重建这棵树.要求最优化算法. 解法1:这人每次出题都要求“最优算法”,自己写的代码却实在让人汗颜,让人觉得这家伙就是懒得思考,想从别人那儿问答案.前序遍历的顺序是“根左右”,那么根节点之后所有小于根的部分就是左子树,后面就是右子树了.怎么找这条分界线呢?可以顺着…
2014-05-08 05:16 题目链接 原题: Given a circle with N defined points and a point M outside the circle, find the point that is closest to M among the set of N. O(LogN) 题目:给定一个圆上的N个点,和一个在这个圆外部的点.请找出这N个点中与外部点最近的那个.要求时间复杂度是对数级的. 解法1:这位“Guy”老兄又出了一道莫名奇妙的题:1. 这些点…
2014-05-07 15:17 题目链接 原题: Given an array of n elements (a1,a2,..ai,...,an). You are allow to chose any index i and j, such that (i!=j) and allow to perform increment operation on ai = ai+ and decrements operation on aj = aj - infinite number of times…
2014-05-06 14:04 题目链接 原题: given an 2D matrix M, is filled either using X or O, you need to find the region which is filled by O and surrounded by X and fill it with X. example : X X X X X X X O O X X X O O X O X X X X Answer : X X X X X X X X X X X X…
2014-05-06 13:34 题目链接 原题: we have a random list of people. each person knows his own height and the number of tall people in front of him. write a code to make the equivalent queue. for example : input: <"Height","NumberOfTall",&quo…
2014-05-06 13:23 题目链接 原题: Finding a pair of elements from two sorted lists(or array) for which the sum of the elements is a certain value. Anyway solution that can do better than O(a.length + b.length)? 题目:给定两个有序的数组,如何从两数组中各选出一个元素使得两元素加起来等于某个目标值. 解法:…
2014-05-06 11:31 题目链接 原题: Find the k-th Smallest Element in Two Sorted Arrays. I followed the algorithm from this post, http://leetcode.com/2011/01/find-k-th-smallest-element-in-union-of.html But it does not handle the case where there are duplicates…
2014-05-06 07:56 题目链接 原题: Flatten an iterator of iterators ,], [,[,]], ], it should ,,,,,]. Implement hasNext() and next(). Note that the inner iterator or list might be empty. 题目:给定一个动态类型的数组,把其中的数组全部展开,成为一个一维数组. 解法:严格类型语言显然不允许这种数据,所以我用Python写了一版代码.…
2014-05-06 06:37 题目链接 原题: Given an array of (unsorted) integers, arrange them such that a < b > c < d > e... etc. 题目:给定一个无序的数组,调整元素顺序,使得数组满足a < b > c < d > e ... 这种形式. 解法:这题没有说明两点:1. 数组元素是否存在重复值. 2. 给定的数组经过调整后是否一定有解.如果确定有解,那么我有两种方法…
2014-05-06 01:49 题目链接 原题: Modify the following code to add a row number for each line is printed public class Test { public static void main(String [] args){ printParenthesis(3); } public static void printParenthesis(int n){ char buffer[] = new char[…
2014-05-06 00:45 题目链接 原题: What would happen if you have only one server for a web cache (a web browser cache whose key is url and value is the loaded content of the webpage) but huge numbers of clients? And how would you solve it? Assume the cache is…
2014-05-06 00:17 题目链接 原题: Given a -D matrix represents the room, obstacle and guard like the following ( is room, B->obstacle, G-> Guard): B G G B calculate the steps from a room to nearest Guard and set the matrix, like this B G G B Write the algor…
2014-05-04 00:10 题目链接 原题: Write a function return an integer that satisfies the following conditions: ) positive integer ) no repeated digits, eg., (valid), (invalid) ) incremental digit sequence, eg., (valid) (invalid) ) the returned integer MUST be…
2014-05-03 23:35 题目链接 原题: For a given node in binary search tree find a next largest number in search tree. 题目:给定一个二叉搜索树的节点,找出此节点在树中的中序后继节点,也就是比它大的最小节点. 解法:右子树向左走到底,左祖先走到顶向右.草稿纸上一画图就清楚了. 代码: // http://www.careercup.com/question?id=5205167846719488 st…
2014-05-03 23:18 题目链接 原题: Insert a element in a sorted circular linked list 题目:题意简单明了,向一个有序的循环单向链表中插入元素,使得链表仍然有序. 解法:由于是循环链表,所以表尾指向表头.链表只能顺序访问,不额外添加数据的情况下就没法以对数的时间进行查找了.有几个边缘情况需要考虑:1. 链表为空 2. 插入到链表头 3. 插入到链表尾.考虑到各种可能情况,就能做出这题. 代码: // http://www.caree…
2014-05-03 21:57 题目链接 原题: Many sticks with length, every time combine two, the cost is the sum of two sticks' length. Finally, it will become a stick, what's the minimum cost? 题目:有很多根长度不同的棍子,每次选择其中两根拼起来,每次拼接的代价为两木棍长度之和.问把所有棍子拼成一根最少需要花多大代价. 解法:描述这么麻烦,…
http://ac.jobdu.com/problem.php?pid=1534 题目1534:数组中第K小的数字 时间限制:2 秒 内存限制:128 兆 特殊判题:否 提交:1120 解决:208 题目描述: 给定两个整型数组A和B.我们将A和B中的元素两两相加可以得到数组C.譬如A为[1,2],B为[3,4].那么由A和B中的元素两两相加得到的数组C为[4,5,5,6].现在给你数组A和B,求由A和B两两相加得到的数组C中,第K小的数字. 输入: 输入可能包含多个测试案例.对于每个测试案例,…
Google的面试题在刁钻古怪方面相当出名,甚至已经有些被神化的味道.这个话题已经探讨过很多次,而科技博客 BusinessInsider这两天先是贴出15道Google面试题并一一给出了答案,其中不少都是流传很广的,因此让人感到不过瘾,不少人兴奋地表 示“让难题来得更猛烈吧!”,于是今天又出了续篇,再次贴出了另外15道Google的面试题,但却没有给出答案. 怎么样?下边先来热热身,再来看看你有没有可能去Google工作吧! 第一题:多少只高尔夫球才能填满一辆校车?(职位:产品经理) 解析:通…