很简单的面试问题

本帖于 2012-12-06 12:13:52 时间, 由普通用户 布衣之才 编辑

这几天我们在面试candidate for a sr. .net developer. 我们问了这样一个问题:

Given a sorted array of integers like:

[1, 3, 4, 7, 11, 14, 15, 19, 21].

 

Please complete the following function that searches for an integer in the array and returns the position if the number is found or -1 if not found:

 

int FindNumber(int[] array, int n)

{

    ......

}

 

No candidate has finished the function to our expection.  

看上去很简单的问题吗?

所有跟帖: 

binary search, is it the expectation? -胡说之- 给 胡说之 发送悄悄话 胡说之 的博客首页 (0 bytes) () 12/06/2012 postreply 12:26:31

yes, thanks. -布衣之才- 给 布衣之才 发送悄悄话 布衣之才 的博客首页 (82 bytes) () 12/06/2012 postreply 12:42:02

Shouldn't the array be sorted first before doing a binary search -ZhuZhuXia- 给 ZhuZhuXia 发送悄悄话 ZhuZhuXia 的博客首页 (0 bytes) () 12/06/2012 postreply 12:53:24

no, that was not what we wanted to test. -布衣之才- 给 布衣之才 发送悄悄话 布衣之才 的博客首页 (458 bytes) () 12/06/2012 postreply 13:11:54

回复:no, that was not what we wanted to test. -布衣之才- 给 布衣之才 发送悄悄话 布衣之才 的博客首页 (162 bytes) () 12/06/2012 postreply 21:23:22

回复:很简单的面试问题 -maymayw- 给 maymayw 发送悄悄话 maymayw 的博客首页 (99 bytes) () 12/06/2012 postreply 12:32:43

请您先登陆,再发跟帖!