2014-05-02 08:29 题目链接 原题: Write a function for retrieving the total number of substring palindromes. For example the input is 'abba' then the possible palindromes= a, b, b, a, bb, abba So the result . Updated at //: After the interview I got know tha…
2014-05-02 10:47 题目链接 原题: Given an unordered array of positive integers, create an algorithm that makes sure no group of integers of size bigger than M have the same integers. Input: ,,,,,,,, M = Output: ,,,,,,,, 题目:给定一个未排序的长度为N的整数数组,和一个正整数M.请设计算法,将N…
2014-05-02 10:40 题目链接 原题: Sink Zero in Binary Tree. Swap zero value of a node with non-zero value of one of its descendants so that no node with value zero could be parent of node with non-zero. 题目:把二叉树中的值为0的节点尽量往下沉,保证所有值为0的节点绝不会有非0的子节点. 解法:我写的算法是O(n…
2014-05-02 10:07 题目链接 原题: Mapping ' = 'A','B','C' ' = 'D','E','F' ... ' = input: output :ouput = [AAD, BBD, CCD, AAE, AAF, BBE, BBF, CCE, CCF] 题目:电话的数字按键和字母有个映射关系,给定一串数字,请给出所有可能的字符映射方式. 解法:此人也不给个描述,搞的下面一堆人来猜题意.这个题目的意思是说,对于给定的数字串,有多少种不同的映射方式.像“112” ->…
2014-05-02 09:59 题目链接 原题: Group Anagrams input = ["star, astr, car, rac, st"] output = [["star, astr"],["car","rac"],["st"]); 题目:给定一堆字符串,设法把anagram都排在一起. 解法:自定义一个comparator,互为anagram的两个字符串在排好序以后是相同的.根据这个规则…
2014-05-02 09:54 题目链接 原题: You have two numbers decomposed in binary representation, write a function that sums them and returns the result. Input: , Output: 题目:做二进制加法. 解法:字符串就行了,不需要额外开辟数组.string对象本身就是一个vector,也就是一个数组喽. 代码: // http://www.careercup.com…
2014-05-02 09:40 题目链接 原题: Given a number N, write a program that returns all possible combinations of numbers that add up to N, =N) For example, ,,,},{,,},{,},{,}} 题目:给定一个正整数N,求出所有的由正整数加起来等于N的可能组合(加数保持升序).比如N = 4的时候,结果是{{1,1,1,1},{1,1,2},{2,2},{1,3}}…
2014-05-02 07:49 题目链接 原题: Given a set of n points (coordinate in 2d plane) within a rectangular space, find out a line (ax+by=c), from which the sum of the perpendicular distances of all the points will be minimum. This can has a general usecase like…
2014-05-02 07:37 题目链接 原题: // merge sorted arrays 'a' and 'b', each with 'length' elements, // in-place into 'b' to form a sorted result. assume that 'b' // has 2*length allocated space. // e.g. a = [1, 3, 5], b = [2, 4, 6] => b = [1, 2, 3, 4, 5, 6] /…
2014-05-02 07:18 题目链接 原题: boolean isBST(const Node* node) { // return true iff the tree with root 'node' is a binary search tree. // 'node' is guaranteed to be a binary tree. } n / \ a b \ c 题目:检查一棵二叉树是否为二叉搜索树. 解法:二叉搜索树,就是每个节点的左边全都小于它,右边全都大于它.如果真的对于每…
2014-05-02 07:06 题目链接 原题: Given an array of randomly sorted integers and an integer k, write a function which returns boolean True if a pair of numbers exists in the array such that A[i] + A[j] = k and False otherwise. Provide an O(N) and an O(N log…
2014-05-02 03:37 题目链接 原题: A string is called sstring if it consists of lowercase english letters and no two of its consecutive characters are the same. You are given string s of length n. Calculate the number of sstrings of length that are not lexico…
2014-05-02 03:19 题目链接 原题: Given a sequence of numbers A() ..A(n), find the continuous subsequenceA(i)..A(j) for which the sum of elements is maximum. condition: we should not select two contiguous numbers 题目:此人的描述简直就是自相矛盾,我的第一念头是这人肯定是个草包,题目都看不懂就从别的地方…
2014-05-02 02:33 题目链接 原题: Given the following by grid ,): , , , , , , , , null we need to find ,) and follow the cell locations from that cell, to the cell it indicates and keep on doing the same for every cell. 题目:有一个3乘3的矩阵,从每个方格可以跳到其它方格,也可能无法继续跳.如果…
2014-05-02 02:28 题目链接 原题: I/P: N, k O/P: all subset of N with exactly K elements. eg: I/p: N = , K = O/p: 题目:从N个数中选K个,输出所有选法. 解法:递归解决. 代码: // http://www.careercup.com/question?id=6204973461274624 #include <vector> using namespace std; class Solution…
2014-05-02 01:05 题目链接 原题: bool anaStrStr (string needle, string haystack) { } Write a function that takes strings , search returns true if any anagram of string1(needle) is present in string2(haystack) 题目:写一个字符串匹配的函数,但是要求只要能在文本里找到模式的anagram,就返回true.…
2014-05-02 00:59 题目链接 原题: Given a normal binary tree, write a function to serialize the tree into a string representation (returning the string), and also a function to deserialize a serialized string into the original binary tree. 题目:给定一棵二叉树,请设计序列化和…
2014-05-02 00:30 题目链接 原题: Given two arrays of sorted integers, merge them keeping in mind that there might be common elements in the arrays and that common elements must only appear once in the merged array. 题目:归并两个已排序的数组,重复元素只能在归并的结果里出现一次. 解法:题意很清晰,…
2014-05-02 00:22 题目链接 原题: Given a matrix consisting of 's. 题目:给定一个01矩阵,找出由1构成的连通分量中最大的一个. 解法:四邻接还是八邻接也不说,我就当四邻接了.这种Flood Fill问题,可以用BFS或者DFS解决. 代码: // http://www.careercup.com/question?id=5998719358992384 #include <vector> using namespace std; class…
2014-05-01 02:30 题目链接 原题: Given a matrix of letters and a word, check if the word is present in the matrix. E,g., suppose matrix is: a b c d e f z n a b c f f g f a b c and given word is fnz, it is present. However, gng is not since you would be repe…
2014-05-01 02:13 题目链接 原题: Design question: Say you have hacked in to a network and can deploy your bot thousands of machines, how would you design your bot so that all the machines work together to download a website, say wikipedia. There should be l…
2014-05-01 01:50 题目链接 原题: Microsoft Excel numbers cells ... and after that AA, AB.... AAA, AAB...ZZZ and so on. Given a number, convert it to that format and vice versa. 题目:微软的Office Excel对于每行每列的命名方式是1, 2, 3, ..., 26, AA, AB, ..., ZZ, AAA, ..., ZZZ.请…
2014-05-01 01:32 题目链接 原题: Given a linked list where apart from the next pointer, every node also has a pointer named random which can point to any other node in the linked list. Make a copy of the linked list. 题目:给定一个单链表,每个链表除了next指针以外,还有一个random指针,随…
2014-05-01 01:23 题目链接 原题: WAP to modify the array such that arr[I] = arr[arr[I]]. Do this in place i.e. with out using additional memory. example : ,,,} o/p = a = {,,,} Note : The array contains to n- integers. 题目:给定一个长度为n的数组,由0至n - 1的排列组成.请做这样的变换,ar…
2014-05-01 01:00 题目链接 原题: Given a matrix with 's. What is the maximum area of the rectangle. In . How: If you see above the . 题目:给定一个‘0’.‘1’构成的矩阵,找出其中全部由‘1’构成的子矩阵中面积最大的一个. 解法:这是Leetcode上有的题目,请参考我的题解LeetCode - Maximal Rectangle. 代码: // http://www.care…
2014-05-01 00:45 题目链接 原题: input [,,,] output [,,,] Multiply all fields except it's own position. Restrictions: . no use of division . complexity in O(n) 题目:给定一个整数数组,将个元素变为其他元素的乘积,例如[2, 3, 1, 4]变为[12, 8, 24, 6].限制不准用除法,而且时间复杂度为线性级别. 解法:用一个额外的数组能够完成O(n…
2014-04-30 16:12 题目链接 原题: The beauty of a number X is the number of 1s in the binary representation of X. Two players are plaing a game. There is number n written on a black board. The game is played as following: Each time a player chooses an intege…
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-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有社交网络等等. 解法:现在都在说移动互联网和可穿戴设备.貌似现在硬件的创新更加放得开了,看看各家巨头收购的…