Validate if given string is a number.

1. C实现atoi: string转成int,这个函数最基本的要考虑益处和符号。这里不太清楚怎么判断整数溢出了。。

int myatoi(const char* str)
{
	int i = 0;
	int sign = 1;
	
	if(*str == '-')
	{
		sign = 0;
		str++;
	}
	while(*str)
	{
		i = i*10 + *str - '0';
		str++;
	}

	if(sign == 0)
		i *= -1;

	return i;
}

2. arraylist里面有乱序的数字,如何找出两个数字使得和为0, O(n), 如何找出三个数字和为0, O(n^2), 四个数字和为0,O(n^2), 如何找出五个数字和为0。

  参考:http://blog.csdn.net/v_july_v/article/details/6419466

  三个数时的方法:http://stackoverflow.com/questions/2070359/finding-three-elements-in-an-array-whose-sum-is-closest-to-an-given-number

  要是用c++, 可以用<unordered_map> 和 <unordered_set>

  这里有一篇各种c++ hashtable 的 library的对比:http://attractivechaos.wordpress.com/2008/08/28/comparison-of-hash-table-libraries/

  c++ map 的用法:http://www.kuqin.com/cpluspluslib/20071231/3265.html

ContractedBlock.gif ExpandedBlockStart.gif 2sum
void twoSum(int *arr, int size)
{
unordered_map
<int,int> hashmap;

for(int i=0; i<size; ++i)
{
hashmap.insert(unordered_map
<int,int>::value_type(arr[i],1));
}

for(int i=0; i<size; ++i)
{
if(sum-arr[i] != arr[i])
{
if(hashmap.count(sum-arr[i]))
{
cout
<<sum-arr[i]<<" and "<<arr[i]<<endl;
return;
}
}
}
cout
<<"There is no pair which sum is"<<sum<<endl;
}

3. Top million word counts in a very large data set like web.

  a. use hashmap ... 

4. design recommendation engine for jobs

  a. content-base

  b. collaborative

5. Check if an element is present in a completely sorted 2D array.

详细的:http://www.ihas1337code.com/2010/10/searching-2d-sorted-matrix-part-ii.html

6. Validate if given string is a number.

7. Implement put and take in a blocking queue.

8. Design LRU Cache

9. Design a hang man online application.

  答案:

    1. Grouping of words by different categories like fruits, auto parts etc.
    2. Grouping of words based on difficulty
    3. Each word is associated with length of it's characters. dup chars are counted as one and this could be optional like property or a param to consider while determining difficulty level.
    4. TBD: Establish rule on how many guesses has to be given to each difficulty level.
    3. User chooses right group or intersection of the group.
    4. Show user empty positions or some symbol representing total characters in the word.
    5. Users get N chances based on difficulty level to guess word right.
    6. User have to start guessing from beginning of the word. Logic checks from the beginning.
    7. User may get a word bigger than number of guesses lenthwise. In this case program is giving hint that some characters may repeat.
    8. Accept input from user as one char
    9. Show user right gusses by replacing symbols with his character choice.
    10. If guess is not right then he looses one guess from N
    11. Repeat steps from 8 until user's selection matches the word OR he/she runs out of guesses

10. What was the most challenging project?

11. Introduce yourself and experience.

12. You have two sets. How can you find the intersection?

void intersection(int a[], int b[], int aSize, int bSize)
{
int aI = 0;
int bI = 0;

while (aI<aSize && bI<bSize)
{
if (a[aI] < b[bI])
{
aI
++;
}
else if (a[aI] > b[bI])
{
bI
++;
}
else
{
cout
<<a[aI]<<" ";
aI
++;
bI
++;
}
}
cout
<<endl;
}

  

13. Given a unbounded non-block queue, implement a blocking bounded queue

  参考:http://www.glassdoor.com/Interview/Given-a-unbounded-non-block-queue-implement-a-blocking-bounded-queue-QTN_142935.htm

14. Give an array that has only the values 1, 2 or 3, sort the array in place.

  参考:http://www.glassdoor.com/Interview/Give-an-array-that-has-only-the-values-1-2-or-3-sort-the-array-in-place-QTN_142936.htm

15. which project you did before you like most?

16. consider a B2C website like Amazon, which will receive thousands requests from buyer per minutes. How will you design the "shop cart " component for it? where should the customs' shop cart data stored?

17. Problem using a Trie data structure to find all possible words occurring in a data set. Output should be a set containing all words that occur in data set.

18. implement a O(1) min function for Stack. 

19. Find a mean value in an array.

double meanValue(int a[], int size)
{
	double sum = 0;

	for(int i=0; i<size; ++i)
	{
		sum += a[i];
	}

	return sum/size;
}

20. Explain how hashmap is implemented, particularly the put() method.

21. write a function and return true or false if there is a pair of number that sum up as 10.

22. How to desgin Hash_map or table?

23. What do you need to implement equals method?

24. Find the Kth hisghest element in a given array.

25. Randomize an array. 参考:Knuth shuffle - http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

26. How do you search thrgough huge flatfile?

27. Simulate a deadlock situation in your code.

28. Doubly linked list in java.

29. Question about approaches to locking a hash table and how to optimize for a very large table.

30. Given a list of numbers, find the contiguous sublist that has the largest sum.

31. Given a grid of size m by n, write an algorithm that computes all paths from 0,0 to m,n such that you can always step horizontally or vertically but cannot reverse.

  参考:http://www.glassdoor.com/Interview/Given-a-grid-of-size-m-by-n-write-an-algorithm-that-computes-all-paths-from-0-0-to-m-n-such-that-you-can-always-step-horiz-QTN_26831.htm

32. How to get a concise summary from a user's Specialties?

33. Reverse a single linked list.

34. Design a function to determine whether a graph is bipartite.

35. Explain about scalability for web applications.

  参考:http://www.royans.net/arch/what-is-scalability/

36. int fibonacci(int);

int fib_iteration(int n)
{
	if (n==0 || n==1)
		return n;
	
	int fn, fn1 = 1, fn2 = 0;

	for (int i=2; i<=n; ++i)
	{
		fn = fn1 + fn2;
		fn2 = fn1;
		fn1 = fn;
	}
	return fn;
}

int fib_recursion(int n)
{
	if (n==0 || n==1)
		return n;

	return fib_recursion(n-2) + fib_recursion(n-1);
}

最后补充:http://www.careercup.com/page?pid=linkedin-interview-questions

转载于:https://www.cnblogs.com/sungwoo/archive/2011/07/14/2105896.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值