算法题库1

1. Google: Write a code to merge N sorted array.
 
2. Microsoft: Reverse linked list by block
    eg. block size is 3 and linked list is 1 2 3 4 5 6 7 8
          output is 3 2 1 6 5 4 8 7
 
3. Google/Tencent: 总共25匹马,每次只能5匹一起跑,那么最少跑几次才能比出第1、2、3名?
    不得使用timer之类的东西,只能靠一个场上跑来分名次。
 
4. Anonymous: 求m个字符串中重复n次字符串的最长的那个
    eg. abcd, bcde, sbbcdd, vbcx
    m = 4, n = 3 output is bcd
 
5. Microsoft: Given a input string find the longest substring which appears more than once in the string?
 
6. Microsoft: 一个包含n个整数的一维数组,找出第k大的数(k<=n).
 
7. Anonymous: 设计一种数据结构,不用队列/堆栈能够层次遍历一颗树.
 
8. Microsoft: 给一个字符串,求出该字符串的最长回文子串.
 
9. Microsoft: 求正数数组内和为指定数字的合并总数.
    eg. 5 5 10 2 3, 指定数字为15
    15 = 5 + 10 = 5 + 10 = 5 + 5 + 2 + 3 = 10 + 2 + 3
 
10. Google: Given n lines in a panel, find how many intersection points are there(count in the duplicated intersection point).
 
11. Google/Microsoft: realize the function of random shuffle.
 
12. Google: 有一个无限输入流,(假设空间不成问题)给一个解决方案,使得能在任何一个时间点上都能取得当前的Median.
 
13. Microsoft: 给两个数组,分别存储的是对一棵树的前序遍历和中序遍历,根据这两个数组构建出这棵二叉树.
 
14. Google: 包含一个或多个{2,3,5}因子的叫丑数,比如2,4,5,15都是,17不是,找出第n个丑数.
 
15. Google: 给100万个数(32位整型),设计一个方案来计算着100万个数含二进制1的个数,综合时间和空间复杂度的考量.
 
16. Google/Baidu: Find pervert pairs
      eg. 1 2 5 3 4 7 8 6
      pervert pairs: <5,3> <5,4> <7,6> <8,6>
 
17. Google: 有一个M*N个格子组成的房间,一个机器人要从房间的左上角走到右下脚,机器人每次只能右移一格或下移一格,求机器人一共有多少种走法,给出程序.
 
18. Microsoft: Implement Stack with Push() Pop() and Mininum() operation in O(1).
 
19. Google: Given an array a[n], build another array b[n], b[i] = a[0]*a[1]*...*a[n-1]/a[i], no division can be used, O(n) time complexity.

20. Amazon: find BST of max size in a binary tree (should be a sub tree).

21. Microsoft: How do you implement a linked list without using dynamic memory allocation? use an array as a linked list.

22. Yahoo: 找出最长0,1对数相同的子串
      eg. 01100111 --> 011001    110000011 --> 1100 / 0011

23. Yahoo: given a word,convert it into a pallindrome with minimum addition of letters to it. Letters can be added anywhere in the word.
      if yahoo is given result should be yahoohay.

24. Amazon: Suppose you have a file on disk which does not fit in main memory, how will you sort it? 
      Optimizing time and the number of reads/writes. Mention exactly how many reads/writes you would need.

25. Google: given a 3 number discrete random number generator, how can you design a 5 number random generator? 
      What is the average number of trials necessary?

26. Google: 两个排序数组中求第k大的sum(a+b).

27. Amazon: 求一个数组的最大递增子序列(不要求连续).

28. Bloomberg: Write an algorithm to find the number of six digit numbers where the sum of the first three digits is equal to the sum of the last three digits.

29. Microsoft: 二维平面上给出一个多边形,按点的顺时针顺序表示,多边形可以是凸多边形也可以是凹多边形。 给出一个点,判断这个点是否在这个多边形内部.

30. Microsoft: 判断二叉树B是否为二叉树A的子结构,实现判断函数.

31. Google: 两个大小相同的排好序的数组,A和B,如何找出两个数组的中数.

32. Microsoft: 两个单项链表彼此相交,求他们第一个交节点.

33. Google:  在一个字符串中找到第一个只出现一次的字符。如输入abaccdeff,则输出b.

34. Microsoft: 找出带环单链表的环起始节点.

35. Anonymous: 以排好序的数组,找出数组最长等差数列的长度
      eg. 1 3 5 6 8 9 10 12 13 14
      最长等差数列为6 8 10 12 14

36. Google: Given an array of elements find the largest possible number that can be formed by using the elements of the array.
      eg. 10 9->910    2 3 5 78->78532

37. Google: 两个数组,就地(不用额外空间)找出合并后第k大的数.

38. Microsoft: Write a function to validate a BST.

39. Facebook: Given an array of size n, find all the possible sub set of the array of size k(all the subsets must be of size k).

40. Microsoft: Given a BST, print all nodes lying between two values, inclusive of these values. Write test cases for same.

41. Google: 二维平面上有若干点,求出一条直线能穿越最多的点.

42. Microsoft: 找出BST上任意节点的下一个节点.
      NODE* Next(NODE* pRoot, NODE* pToFind)

43. Google: 给定一个未排序数组,找出其中最长的等差数列. O(N*N)

44. Google: 在一个数组中寻找三个数,使得它们的和为0.

45. Amazon: 最简捷的方法判断一个数是否为2的幂.

46. Google:  两个排好序的数组A, B.和一个数c, 求a + b = c, a属于A, b属于B.

47. Google: given a number n... print a spiral matrix in O(1) space example if n=5 the op should be:
      25 24 23 22 21
      10 09 08 07 20
      11 02 01 06 19
      12 03 04 05 18
      13 14 15 16 17

48. Amazon: given an array with positive and negative numbers find the first continuous subarray that sums to 0.

49. Adobe: Given an array A[i..j] find out maximum j-i such that A[i]<a[j] in O(n) time.

50. Facebook: 写一个自己的 double sqrt(double x), 满足一定精度就可以了.

51. Facebook: 反转单向链表.

52. Facebook: Write a Program to rotate a N * M matrix by 90 degrees.

53. Anonymous: 对于正数数组A[n], 找出A[i] = A[x]+A[y]的A[i]的最大值.

54. Anonymous: 有一个元素个数为2n的数组a,找出这样数量相等(均为n个元素)的两个子数组a1,a2, 使a1中所有元素的和sum1与a2中所有元素的和sum2的差值最小,即|sum1-sum2|最小.

55. Google: 给你一个32位的number,把它按位逆序 : 1101001 ==> 1001011.

56. Google: 一个range的序列,如[1,3], [2,6], [8,10],[15,18],写程序合并有重叠的range,比如上面的序列合并为[1,6], [8,10], [15,18].

57. Amazon: 将字符串abcde12345 inplace的转换为a1b2c3d4e5.

58. Google: 给一个整数,表示成n个整数的平方和,n最小, 求n.
      eg. 10017 = 100^2 + 4^2 + 1    n = 3

59. Facebook: 实现atoi函数. 15min

60. Facebook: Implement division without using multiplication or division. It should work most efficient and fast.

61. Morgan Stanley: how to sort 100 numbers given using memory size sufficient for 20 elements only(like array of size 20)?

62. Facebook: How will you implement your own rand() such that it returns an integer from 0 to n-1 with equal probability?

63. Linkedin: Write a function that would return the 5th element from the tail (or end) of a singly linked list of integers, in one pass, and then provide a set of test cases against that function (please do not use any list manipulation functions that you do not implement yourself).

64. Amazon: Design an OO parking lot.What classes and functions will it have. It should say, full, empty and also be able to find spot for Valet parking.The lot has 3 different types of parking: regular, handicapped and compact.

65. Amazon: Given 2 rectangles with top left and bottom right coordinates for each rectangle, return 1 if they have a common area otherwise return -1.


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值