由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - liverampOA题目
相关主题
向各位大侠请教几道面试题的思路find longest subarray with the equal number of 0's, 1's
这个怎么弄?longest subarray with numbers arranged as a seq
一道老题目问两道微软题
请教一道题目贡献一道某 virtualization 大公司online coding test 的题
刚电面完,分享两个题目amazon 电面题
Random Array number, Find longest consecutive sequence大家看一下这道google面试题
来做一个暴力题details 2nd smallest element in an array
how to obtain a subarray whose sum is a specific given number?问一道老题
相关话题的讨论汇总
话题: len话题: min话题: max话题: maxindex话题: minindex
进入JobHunting版参与讨论
1 (共1页)
c******a
发帖数: 14
1
上周写了liveramp的OA题,分享给大家:)
之前也看了大家的许多面经,回馈一下。
两道题比较第二道比较新。
1) Given an array A, find the index p, in which A[0] + A[1] +...+ A[p-1] = A
[p+1] + A[p+2] +.. + A[n-1]. Time complex O(n)
2) Given an array A, find the longest subarray which biggest element minus
smallest element not less than 1.
e********2
发帖数: 495
2
第二题要么无解,要么整个array?

A

【在 c******a 的大作中提到】
: 上周写了liveramp的OA题,分享给大家:)
: 之前也看了大家的许多面经,回馈一下。
: 两道题比较第二道比较新。
: 1) Given an array A, find the index p, in which A[0] + A[1] +...+ A[p-1] = A
: [p+1] + A[p+2] +.. + A[n-1]. Time complex O(n)
: 2) Given an array A, find the longest subarray which biggest element minus
: smallest element not less than 1.

c******a
发帖数: 14
3
数组的顺序不能变,例如:A = [ 3, 5, 7,7,6], 最长的应该是[7, 7, 6]

【在 e********2 的大作中提到】
: 第二题要么无解,要么整个array?
:
: A

g********i
发帖数: 770
4
这个是no more than 1吧,用sliding window做。
j**********3
发帖数: 3211
5
他家的oa限时么?要求多久以内做完?
b***e
发帖数: 1419
6
这个用sliding window的确可以做到线性,但是很难。

【在 g********i 的大作中提到】
: 这个是no more than 1吧,用sliding window做。
f********y
发帖数: 156
7
大概这样做:
use an array len[ ] to keep track of the longest subarray ending at A[i]
use {min, minIndex } and {max, maxIndex} to keep track of current min/max
and their indices.
if A[i] > max + 1, then update max and clear min; set len[i] = 1
if A[i] < min -1, then update min and clear max; set len[i] = 1
if A[i] is between min and max, then set len[i] = len[i-1] + 1
if A[i] == max + 1 && minIndex < maxIndex, then min = max; max = A[i],
len[i] = len[i-1] + (maxIndex - minIndex)
if A[i] == min -1 && minIndex > maxIndex, then max = min; min = A[i], len[i
] = len[i-1] + (minIndex - maxIndex)
第一遍走完,len[ ] 就设好了;第二遍遍历 len[ ] 找最大值

【在 b***e 的大作中提到】
: 这个用sliding window的确可以做到线性,但是很难。
b***e
发帖数: 1419
8
Are you assuming each number is an integer?
Anyways, the general approach requires sliding window max/min algorithm,
which is non-trivial. I think this problem is too hard for an interview
question.

[i

【在 f********y 的大作中提到】
: 大概这样做:
: use an array len[ ] to keep track of the longest subarray ending at A[i]
: use {min, minIndex } and {max, maxIndex} to keep track of current min/max
: and their indices.
: if A[i] > max + 1, then update max and clear min; set len[i] = 1
: if A[i] < min -1, then update min and clear max; set len[i] = 1
: if A[i] is between min and max, then set len[i] = len[i-1] + 1
: if A[i] == max + 1 && minIndex < maxIndex, then min = max; max = A[i],
: len[i] = len[i-1] + (maxIndex - minIndex)
: if A[i] == min -1 && minIndex > maxIndex, then max = min; min = A[i], len[i

1 (共1页)
进入JobHunting版参与讨论
相关主题
问一道老题刚电面完,分享两个题目
问个google面试题Random Array number, Find longest consecutive sequence
Given an array of N integers from range [0, N] and one is missing. Find the missing number.来做一个暴力题
问题:Find the minimum number of "swaps" needed to sort an arrayhow to obtain a subarray whose sum is a specific given number?
向各位大侠请教几道面试题的思路find longest subarray with the equal number of 0's, 1's
这个怎么弄?longest subarray with numbers arranged as a seq
一道老题目问两道微软题
请教一道题目贡献一道某 virtualization 大公司online coding test 的题
相关话题的讨论汇总
话题: len话题: min话题: max话题: maxindex话题: minindex