由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 一道leetcode上没有的题
相关主题
请教个面试题careercup上这道题我竟然没看懂
leetcode上遇到的问题这题怎么做?
Leetcode为什么把所有的array都改成List了?算法题:两列找共同元素有O(n)的算法吗?
请教Leetcode 上的 Sudoku solverGiven an array of N integers from range [0, N] and one is missing. Find the missing number.
Google电话面试题目问道题,谁给个效率高点的解法
一道面试题看不懂a[i] + b[j] = c[k] 的题有靠谱的答案不?
[合集] Google电话面试题目菜鸟问个two sum的变型题
一道老题amazon 电面问题 求解答, 在线等
相关话题的讨论汇总
话题: array话题: search话题: integers话题: time
进入JobHunting版参与讨论
1 (共1页)
P****e
发帖数: 56
1
也有可能是我没刷到。
有一个class叫Searcher. 你要写其中两个function: preProcessData, search.
preProcessData takes in an array of positive integers, all unique, and you
can do whatever you want with the array (modify it, sort it, create another
data structure in this class to store its content, etc). And there's no
restriction on space or time complexity.
search takes in 2 integers, x,y. x and y are both in the original array. and
it must return the total number of elements in the array that are between x
and y, exclusive. But must do it in O(1) time.
Example:
array = [2,4,9,5,7,3]
preProcessData (array) <- do whatever you want
search(2,7) <- 3 (3,4,5 are between 2 and 7, exclusive). in O(1) time.
v******s
发帖数: 144
2
在preprocess用O(nlog(n))把所有x,y (x < y) 都存起来不就行了。怎么会有这样的题
v******s
发帖数: 144
3
x,y不应该在数组里吧,要不然就是一对一的查表
p*********g
发帖数: 2998
4
这种题非常坑跌的, 最直观的做法就是2层for loop,把数字按照string, integer ,
字符和数量存进map,然后拿的时候久是o(1), 但你这么写,估计过不了, 肯定有更好
的办法, 可能会有follow up question
v******s
发帖数: 144
5
应该先排序 n(log(n)),然后数和排序后的index 存到hash就行
search时 index 相减
G*****i
发帖数: 433
6
难道不就是记下每个数字的index,然后一减吗?
J**9
发帖数: 835
7
Sort array
hash array (element --- index)
O(1) to get two indices
p**r
发帖数: 5853
8
LC至少有5道题和你的题基本一样,
只是稍微变种而已。
btw,这题也太简单了,
至少2种方法可以搞定。
r*******y
发帖数: 270
9
改成x y不在array里也可以constant做
l*3
发帖数: 2279
10
how?

【在 r*******y 的大作中提到】
: 改成x y不在array里也可以constant做
1 (共1页)
进入JobHunting版参与讨论
相关主题
amazon 电面问题 求解答, 在线等Google电话面试题目
请教一道算法题一道面试题看不懂
问一道面试题目[合集] Google电话面试题目
Minimum number of moves to make an integer array balance一道老题
请教个面试题careercup上这道题我竟然没看懂
leetcode上遇到的问题这题怎么做?
Leetcode为什么把所有的array都改成List了?算法题:两列找共同元素有O(n)的算法吗?
请教Leetcode 上的 Sudoku solverGiven an array of N integers from range [0, N] and one is missing. Find the missing number.
相关话题的讨论汇总
话题: array话题: search话题: integers话题: time