s*******f 发帖数: 1114 | 1 int EarnMost(int prices[], int len){
if (!prices !! len < 1)
return 0;
int minp = prices[0];
int maxp = prices[0];
int ret = 0;
for (int i = 1; i < len; ++i){
if (prices[i] > maxp){
maxp = prices[i];
ret = maxp - minp > ret? maxp - minp:ret;
}else if (prices[i] < minp){
minp = prices[i];
maxp = prices[i];
}
}
return ret;
}
if [5,4,3,2,1], it returns 0, not -1. |
|
|
h********r 发帖数: 51 | 3 下面这个方法行不行? O(n), 模拟一次买卖的DP解法。大牛们看看对不对?
#include
#include
#include
void dump(int *x, int l) {
int i;
for (i = 0; i < l; ++ i) {
printf("%d ", x[i]);
}
printf("\n");
}
int main() {
int array[] = {3, 6, 8, 4, 5, 7, 9, 13, 15, 10, 6, 2, 7, 11, 8, 6};
int len = sizeof(array)/sizeof(int);
assert (len >= 4);
int *a = (int*)malloc(sizeof(int)*len);
int *b = (int*)malloc(sizeof(int)*len);
int *c = (int*)malloc(sizeof(... 阅读全帖 |
|
|
j********x 发帖数: 2330 | 5 要用google doc,有哪位高人有经验的介绍一下~ |
|
|
v***n 发帖数: 562 | 7 online coding interview多长时间? |
|
j********x 发帖数: 2330 | 8 很多办法都可以
最简单的hashing
另一种是用quicksort的partition,每次看两边sub array的长度n,找到n满足n%3==1
,然后这个数一定在这一边,O(n) |
|
|
|
h*********n 发帖数: 915 | 11 all three need complete code? if so it's challenging. |
|
j********x 发帖数: 2330 | 12 修改了一下,我默认算法题指的不是coding的题目。最后一个算法题不要写代码的,其
实写起来也不算难 |
|
c******o 发帖数: 534 | 13 nice。这也可以,真是什么方法都想得到啊
1 |
|
h*********n 发帖数: 915 | 14 yes, it's not hard. but given 45-min window, complete three with bug free is
hard, unless you have practiced them before.
anyway, it seems you did well. cong. |
|
r*******y 发帖数: 1081 | 15 if the array is 1 2 2 3 3
then 1^2^2^3^3 = 1
can we apply similiar idea to 1 2 2 2 3 3 3 ? |
|
j********x 发帖数: 2330 | 16 我以前看到别人这种做法,做面试题如同应试。。。 |
|
j********x 发帖数: 2330 | 17 I dont understand, xor does not work for number appears 3 times. There is no
similar approach to XOR works for 3 appearance. |
|
D***h 发帖数: 183 | 18 多谢分享。
他家是只能用Java么? 有没有问java细节题?
第一次那个电话面试只说算法,不用把code念给他听? |
|
j********x 发帖数: 2330 | 19 一面有一个简单的题目是要求念code的,其他2-3个题目都是算法题,给出思路
即可;
任何语言都可以,除非非常偏门
不考语言细节
他们开发绝大部分是java,这根面试没有关系
二面还是可以挑任何语言(我的面试官基本不动c/c++) |
|
l*********y 发帖数: 142 | 20 singleton class,给出一个thread safe并且exception safe的实现
请问这个怎么写? thread safe用double check的方法就好了,exception safe那? |
|
|
|
|
l*********y 发帖数: 142 | 24 看了wiki上的介绍,还算理解。
请问是下面这样吗?谢谢
class Singleton {
Singleton* GetInstance() {
if (! instance) {
pthread_mutex_lock();
if (! instance) {
instance = new Singleton();
}
pthread_mutex_unlock();
}
}
~Singleton() {
pthread_mutex_unlock();
}
private:
Singleton(){};
static Singleton* instance;
};
Singleton* Singleton::instance = NULL;
但是如果Singleton destructor被正常调用,pthread mutex这时是没有lock的
可以unlock吗... 阅读全帖 |
|
l***i 发帖数: 1309 | 25 This one is a bit strange. Since sorting gives O(nlogn) trivially.
Use partition with randomization will give O(n) in expected time. If you use
O(n) time algorithm to find median and do partition, then it is worst case
O(nlogn).
hashing is a bit cheating in my opinion. If you are allowed hashing, then
you can solve the problem with one element appear once and the other
elements can appear any number of two or more times. This defeats the
purpose of other elements appear exactly 3 times.
1 |
|
h*********n 发帖数: 915 | 26 为何dtor里解锁?没必要吧。
另外其实最简单的做法是在全局直接初始化:
Singleton::instance = new Singleton; |
|
|
h*********n 发帖数: 915 | 28 why not? it's a discussion, not a standard test. |
|
f*********5 发帖数: 576 | 29 u need to declare ctor as public if u want to do so
then everyone can call it to instantiate a new object |
|
h*********n 发帖数: 915 | 30 how about this?
Singleton::instance = getSingleton() |
|
f*********5 发帖数: 576 | 31 maybe it is better to add a
static void DeleteInstance()
then use the same logic to call below
delete instance; |
|
j********x 发帖数: 2330 | 32 Lazy initialization is needed
Hmm, don't miss the point here, it's a discussion to showcase your knowledge
, not your ignorance.... |
|
j********x 发帖数: 2330 | 33 Hmm, think again...
use
case |
|
h*********n 发帖数: 915 | 34 why lazy init is needed? what's the expense to init one in advance?
if the expense of lazy init is having a lock, it's hard to say if lazy is
worth.
the discussion is not only to show what you learn from the textbook but also
your analysis and understanding. it's an "interview", not an exam.
knowledge |
|
h*********n 发帖数: 915 | 35 expected O(n) good enough. but it would be perfect to point out the worst
case. |
|
j********x 发帖数: 2330 | 36 windows8 一大亮点是开机速度快。。。
减少initialization时间对提高app启动时间很有帮助。。。
also |
|
j********x 发帖数: 2330 | 37 面试官和我对partition的worst case以及如何优化有很明显的共识,实际上大家都知
道,不讲而已。基本上已经是常识性的东西了。 |
|
h*********n 发帖数: 915 | 38 then what would you think about again? |
|
|
j********x 发帖数: 2330 | 40 下周应该就要去了,有哪位高人搞过这家公司onsite的不吝赐教啊
介绍一下大概流程、内容、难度之类的。谢谢!!!! |
|
|
s******e 发帖数: 108 | 42 Given 2 range array, output the intersection array.
a: [1,5], [8,15], [30,90]
b: [2,7],[12,18],[80,100]
output:
[2,5],[12,15],[80,90] |
|
|
|
B*******1 发帖数: 2454 | 45 isn't it
output:
[2,5],[12,15],[80,90] |
|
|
l*********y 发帖数: 142 | 47 #include
#include
#include
#include
#include
#include
#include
|
|
j********x 发帖数: 2330 | 48 太傻比了。。。
(你问的问题比我简单多了),我遇到的都是些没啥深度的问题。。。
我问的问题比你简单多了。。。 |
|
f*********5 发帖数: 576 | 49 oracle,IBM,qualcomm
check what the otehrs applied,apply as well
such as palantir?
motorola?
google or groupon?
amazon or apple
what is this?
netflix?
what is this? |
|
f*********5 发帖数: 576 | 50 oracle,IBM,qualcomm
check what the otehrs applied,apply as well
such as palantir?
motorola?
google or groupon?
amazon or apple
what is this?
netflix?
what is this? |
|