由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - One Microsoft interview question
相关主题
请问哪里有题库?问一个merge k sorted array的问题
一个特别的inplace merge two sorted arrays问一道F家面试题
一个小公司面经partition array problem
问一道老题MS a0, a1, ..., b0, b1... 问题
请教两道算法题[合集] 请教个经典面试题的变种
问个算法题8amazon tel interview
Find the K largest element in a sorted M*N arrayFind Median Of Two Sorted Arrays
再问一个算法题。lc新题,贴个刚写的solution
相关话题的讨论汇总
话题: sum话题: microsoft话题: question话题: arr话题: interview
进入JobHunting版参与讨论
1 (共1页)
s******n
发帖数: 57
1
Question:
Give an array like [-128, -35, -13, 0, 12, 67, 98], find two element which
the sum is
closest to 0.
solution:
http://www.careertea.com/techforum/post.aspx?PostID=5095
f*********i
发帖数: 197
2
The solution costs O(nlogn) for sorting
However, since this array is already sorted, there is an O(N) approach
public static int array_sortedArray_find_close_to_zero(int[] arr){
int first=0,last = arr.length-1;
int sum = arr[first]+arr[last];
int min_to_0 = Math.abs(sum);
while(first sum = arr[first]+arr[last];
if(Math.abs(sum) min_to_0 = Math.abs(sum);
if(sum>0)
last--;
else if(sum<0)
first++;
else
return 0;
}
return min_to_0;
}
1 (共1页)
进入JobHunting版参与讨论
相关主题
lc新题,贴个刚写的solution请教两道算法题
请教一道题目问个算法题8
一个算法题:Selecting median of three sorted arraysFind the K largest element in a sorted M*N array
一道google题再问一个算法题。
请问哪里有题库?问一个merge k sorted array的问题
一个特别的inplace merge two sorted arrays问一道F家面试题
一个小公司面经partition array problem
问一道老题MS a0, a1, ..., b0, b1... 问题
相关话题的讨论汇总
话题: sum话题: microsoft话题: question话题: arr话题: interview