由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问两道微软题
相关主题
google面试问题一道老题目
A facebook interview question请教一道题目
真慫阿, Facebook 1st phone interview,问个google面试题
向各位大侠请教几道面试题的思路liverampOA题目
问一个时间复杂度的问题,数组里取k个最大数老题目一问
说说4sum的复杂度吧phone interview question
CS algorithm question我花了一个小时才调通过这个程序
请教两道算法题考古到一道题
相关话题的讨论汇总
话题: elements话题: complexity话题: given话题: find话题: sum
进入JobHunting版参与讨论
1 (共1页)
a******t
发帖数: 34
1
given an array of n elements, find if there is a subset of 3 elements sum up
to value T
with time complexity O(nlgn).
Given a M*N matrix A in which all the elements in a row and all the elements
in a column are strictly
increasing. Find a path from the smallest element (ie A[0][0]) to the
largest element (ie A[M-1][N-1])
such that the sum of the elements in the path is maximum. Time Complexity O(
m+n). Use efficient space.
g*******y
发帖数: 1930
2
貌似两个都做不出来的。

up
elements
O(

【在 a******t 的大作中提到】
: given an array of n elements, find if there is a subset of 3 elements sum up
: to value T
: with time complexity O(nlgn).
: Given a M*N matrix A in which all the elements in a row and all the elements
: in a column are strictly
: increasing. Find a path from the smallest element (ie A[0][0]) to the
: largest element (ie A[M-1][N-1])
: such that the sum of the elements in the path is maximum. Time Complexity O(
: m+n). Use efficient space.

G**********s
发帖数: 70
3
1.版上讨论过,n^2 最佳了,nlgn不可能的
2.两边之和大于第三边,所以途径最多点的就是maximum把。
a******t
发帖数: 34
4
小尾羊
首先谢谢你的回答。
再次祝贺拿到Google offer.
s*****i
发帖数: 355
5
第一题能用辅助hashmap吗?排序以后两指针一头一尾,用T减去这两个数的和,查询差
值是不是在hashmap里

up
elements
O(

【在 a******t 的大作中提到】
: given an array of n elements, find if there is a subset of 3 elements sum up
: to value T
: with time complexity O(nlgn).
: Given a M*N matrix A in which all the elements in a row and all the elements
: in a column are strictly
: increasing. Find a path from the smallest element (ie A[0][0]) to the
: largest element (ie A[M-1][N-1])
: such that the sum of the elements in the path is maximum. Time Complexity O(
: m+n). Use efficient space.

B*****t
发帖数: 335
6
1. O(nlgn) can be achieved by using FFT under some conditions. But generally
the best algorithm to find a subset of 3 elements sum up
to a given value T is O(n^2). The relationship is like radix sort vs quick
sort. But I doubt the interviewers from MS would ask such kind of questions.
2. I don't think there is such kind of algorithms with O(m+n) complexity.
t*********n
发帖数: 1292
7
原来的讨论在哪儿啊?能给个链接吗?谢谢!
h**k
发帖数: 3368
8

这里需要考虑任何两个数的和,所以复杂度是O(n*n)

【在 s*****i 的大作中提到】
: 第一题能用辅助hashmap吗?排序以后两指针一头一尾,用T减去这两个数的和,查询差
: 值是不是在hashmap里
:
: up
: elements
: O(

b****r
发帖数: 1272
9
2. 只想到dp O(m*n)
有更好的法子?

up
elements
O(

【在 a******t 的大作中提到】
: given an array of n elements, find if there is a subset of 3 elements sum up
: to value T
: with time complexity O(nlgn).
: Given a M*N matrix A in which all the elements in a row and all the elements
: in a column are strictly
: increasing. Find a path from the smallest element (ie A[0][0]) to the
: largest element (ie A[M-1][N-1])
: such that the sum of the elements in the path is maximum. Time Complexity O(
: m+n). Use efficient space.

c******f
发帖数: 2144
10
mark
h*******x
发帖数: 12808
11
第一题,排序一下,是nlogn,然后用n次找两个数和为T-n3的算法,但是这样是n^2啊
?谁知道nlogn的啊

up
elements
O(

【在 a******t 的大作中提到】
: given an array of n elements, find if there is a subset of 3 elements sum up
: to value T
: with time complexity O(nlgn).
: Given a M*N matrix A in which all the elements in a row and all the elements
: in a column are strictly
: increasing. Find a path from the smallest element (ie A[0][0]) to the
: largest element (ie A[M-1][N-1])
: such that the sum of the elements in the path is maximum. Time Complexity O(
: m+n). Use efficient space.

1 (共1页)
进入JobHunting版参与讨论
相关主题
考古到一道题问一个时间复杂度的问题,数组里取k个最大数
请教两道CS题说说4sum的复杂度吧
算法题CS algorithm question
老问题了,网上竟然找不到答案请教两道算法题
google面试问题一道老题目
A facebook interview question请教一道题目
真慫阿, Facebook 1st phone interview,问个google面试题
向各位大侠请教几道面试题的思路liverampOA题目
相关话题的讨论汇总
话题: elements话题: complexity话题: given话题: find话题: sum