由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问道题
相关主题
sample 设计问题的linkHM 如果说你有很大潜力
求救: 打印binary tree收集的一些design问题
圣诞大礼- 已付费上百猎头公司的网址求教一道经典面题的解法
大量 SDEs opening (更新 2)贡献两道google面试题
管不住自己,怎么办?Level order traversal只让用一个Queue怎么做?
今天去面试有点受宠若惊给一个股票的time series,如何求past N days high?
有什么fresh CS MS丢人到找不到工作,灰溜溜回国的?问两个面试的题目, 概率和逻辑分析
大家帮我看看这是啥意思啊?一道老题但是以前的解好象都不对
相关话题的讨论汇总
话题: lattice话题: kth话题: numbers话题: find话题: hint
进入JobHunting版参与讨论
1 (共1页)
r**u
发帖数: 1567
1
Design an algorithm to find the kth number divisible by only 3 or 5 or 7 i.e
the only factors of these numbers should be 3,5 and 7.
g*******y
发帖数: 1930
2
this one is very classical, and good
hint: use three queues

.e

【在 r**u 的大作中提到】
: Design an algorithm to find the kth number divisible by only 3 or 5 or 7 i.e
: the only factors of these numbers should be 3,5 and 7.

H*M
发帖数: 1268
3
just a combination of 3,5,7 ba..can be multiple copies

.e

【在 r**u 的大作中提到】
: Design an algorithm to find the kth number divisible by only 3 or 5 or 7 i.e
: the only factors of these numbers should be 3,5 and 7.

H*M
发帖数: 1268
4
we can use a min_heap, push 3, 5, 7 first, then pop, multiply the popped one
with 3, 5, 7 each time and push the results.
But how to deal with the duplicates in the min_heap... seems there is a patt
ern of the repitition..

【在 H*M 的大作中提到】
: just a combination of 3,5,7 ba..can be multiple copies
:
: .e

H*M
发帖数: 1268
5
geniusxsy say say ba
how to use three queues

【在 g*******y 的大作中提到】
: this one is very classical, and good
: hint: use three queues
:
: .e

g*******y
发帖数: 1930
6
q1:{3}
q2:{5}
q3:{7}
如果q1的队首是当前最小的,出队,分别乘以3,5,7扔进q1 q2 q3
如果q2的队首是当前最小的,出队,分别乘以5,7扔进q2 q3
如果q3的队首是当前最小的,出队,乘以7扔进q3

【在 H*M 的大作中提到】
: geniusxsy say say ba
: how to use three queues

H*M
发帖数: 1268
7
very nice a! to avoid dups.
how did u come up with this idea...

【在 g*******y 的大作中提到】
: q1:{3}
: q2:{5}
: q3:{7}
: 如果q1的队首是当前最小的,出队,分别乘以3,5,7扔进q1 q2 q3
: 如果q2的队首是当前最小的,出队,分别乘以5,7扔进q2 q3
: 如果q3的队首是当前最小的,出队,乘以7扔进q3

r**u
发帖数: 1567
8
very clear. 谢谢

【在 g*******y 的大作中提到】
: q1:{3}
: q2:{5}
: q3:{7}
: 如果q1的队首是当前最小的,出队,分别乘以3,5,7扔进q1 q2 q3
: 如果q2的队首是当前最小的,出队,分别乘以5,7扔进q2 q3
: 如果q3的队首是当前最小的,出队,乘以7扔进q3

g*******y
发帖数: 1930
9
to be honest, I did this problem with a hint of using queue. My initial attempt w/o this hint ended up in a wrong direction (spatial lattice)
Besides, this problem is quite classical, I've seen it at least twice before (now it makes at least three times)

【在 H*M 的大作中提到】
: very nice a! to avoid dups.
: how did u come up with this idea...

H*M
发帖数: 1268
10
cool..where did u see it? just curious.
I am starting to look at questions in zhiyebei
any other websites we can get trained?

attempt w/o this hint ended up in a wrong direction (spatial lattice)
before (now it makes at least three times)

【在 g*******y 的大作中提到】
: to be honest, I did this problem with a hint of using queue. My initial attempt w/o this hint ended up in a wrong direction (spatial lattice)
: Besides, this problem is quite classical, I've seen it at least twice before (now it makes at least three times)

相关主题
今天去面试有点受宠若惊HM 如果说你有很大潜力
有什么fresh CS MS丢人到找不到工作,灰溜溜回国的?收集的一些design问题
大家帮我看看这是啥意思啊?求教一道经典面题的解法
进入JobHunting版参与讨论
g*******y
发帖数: 1930
11
职业杯上应该是有这题的。
本版精华区上很多题也应该做一遍

【在 H*M 的大作中提到】
: cool..where did u see it? just curious.
: I am starting to look at questions in zhiyebei
: any other websites we can get trained?
:
: attempt w/o this hint ended up in a wrong direction (spatial lattice)
: before (now it makes at least three times)

H*M
发帖数: 1268
12
duo xie geniusxsy!

【在 g*******y 的大作中提到】
: 职业杯上应该是有这题的。
: 本版精华区上很多题也应该做一遍

m******g
发帖数: 5
13

these are very good ones. Would you please tell me what the ZHiyebei is? I
am also looking for some training exercises...
thanks, HNM

【在 H*M 的大作中提到】
: cool..where did u see it? just curious.
: I am starting to look at questions in zhiyebei
: any other websites we can get trained?
:
: attempt w/o this hint ended up in a wrong direction (spatial lattice)
: before (now it makes at least three times)

n******r
发帖数: 1247
14
www.careercup.com

【在 m******g 的大作中提到】
:
: these are very good ones. Would you please tell me what the ZHiyebei is? I
: am also looking for some training exercises...
: thanks, HNM

f******h
发帖数: 122
15
题目都没有看懂,能不能麻烦哪位大侠把题目详细解释一下...:P

.e

【在 r**u 的大作中提到】
: Design an algorithm to find the kth number divisible by only 3 or 5 or 7 i.e
: the only factors of these numbers should be 3,5 and 7.

r**u
发帖数: 1567
16
such nums can be represented as: 3^i * 5^j * 7^k,
e.g., 3, 5, 7, 9, 15, 21, 25, ......
find the kth in this list.

【在 f******h 的大作中提到】
: 题目都没有看懂,能不能麻烦哪位大侠把题目详细解释一下...:P
:
: .e

h***r
发帖数: 726
17
catch the boazi from me!

【在 g*******y 的大作中提到】
: q1:{3}
: q2:{5}
: q3:{7}
: 如果q1的队首是当前最小的,出队,分别乘以3,5,7扔进q1 q2 q3
: 如果q2的队首是当前最小的,出队,分别乘以5,7扔进q2 q3
: 如果q3的队首是当前最小的,出队,乘以7扔进q3

m******g
发帖数: 5
18

Thanks, novaster

【在 n******r 的大作中提到】
: www.careercup.com
b***e
发帖数: 1419
19
You are playing a nice trick here. But still, the time complexity is O(n).
That is, you need O(2^k) time complexity assuming n is of k binary bits.
This is not nearly good enough.
I believe there's an algorithm polynomial to k, as laied out in the
following:
For illustration purpose, and without losing (too much) generality, let's
reduce the problem to 2 numbers: 2 and 3.
Given any n, where can try to see how many qualified numbers are smaller
than n. To do this, consider the lattice for the
g*******y
发帖数: 1930
20
The three-queue algo. can achieve O(k), where k stands for k-th qualified
number.
but I'm kinda confused by your notation of 'n', 'k'. The problem is to find
kth qualified number --> does this k have same meaning as yours?

.

【在 b***e 的大作中提到】
: You are playing a nice trick here. But still, the time complexity is O(n).
: That is, you need O(2^k) time complexity assuming n is of k binary bits.
: This is not nearly good enough.
: I believe there's an algorithm polynomial to k, as laied out in the
: following:
: For illustration purpose, and without losing (too much) generality, let's
: reduce the problem to 2 numbers: 2 and 3.
: Given any n, where can try to see how many qualified numbers are smaller
: than n. To do this, consider the lattice for the

g*******y
发帖数: 1930
21
其实我最初做这题,也是考虑的lattice,考虑空间整数点阵
一个斜面 with ln3*x + ln5*y + ln7*z = n
逐渐增大n,直观上就是把这个斜面向远离原点的地方平移,
所有被该斜面所包围在内的点数就是: 所有小于某个值(e^n)的符合条件的数的个数。
这样,当k很大的时候,容易很快的给出一个近似估计(令k=斜面包围的空间的体积=1/3*x_0*y_0*z_0,x_0为该斜面和x轴交点),因为lattice一个单位体积中有一个点。解出x_0,y_0,z_0,n,那么近似估计值就是e^n
x_0,y_0,z_0的量级都是k^(1/3)
要求精确解的话,需要在近似解(截面)附近搜索了,而截面的面积是O(k^(2/3)),所以我估计
最后算法能优化到 k^(2/3)
不过还是queue的方法elegant很多

.

【在 b***e 的大作中提到】
: You are playing a nice trick here. But still, the time complexity is O(n).
: That is, you need O(2^k) time complexity assuming n is of k binary bits.
: This is not nearly good enough.
: I believe there's an algorithm polynomial to k, as laied out in the
: following:
: For illustration purpose, and without losing (too much) generality, let's
: reduce the problem to 2 numbers: 2 and 3.
: Given any n, where can try to see how many qualified numbers are smaller
: than n. To do this, consider the lattice for the

b***e
发帖数: 1419
22
My time complexity calculation is wrong. Yours is right. Basically, I am
saying that we probably should start somewhere from the middle rather than
test from the beginning. That may boost the converge rate.

数。
=1/3*x_0*y_0*z_0,x_0为该斜面和x轴交点),因为lattice一个单位体积中有一个点。
解出
x_0,y_0,z_0,n,那么近似估计值就是e^n
以我估计

【在 g*******y 的大作中提到】
: 其实我最初做这题,也是考虑的lattice,考虑空间整数点阵
: 一个斜面 with ln3*x + ln5*y + ln7*z = n
: 逐渐增大n,直观上就是把这个斜面向远离原点的地方平移,
: 所有被该斜面所包围在内的点数就是: 所有小于某个值(e^n)的符合条件的数的个数。
: 这样,当k很大的时候,容易很快的给出一个近似估计(令k=斜面包围的空间的体积=1/3*x_0*y_0*z_0,x_0为该斜面和x轴交点),因为lattice一个单位体积中有一个点。解出x_0,y_0,z_0,n,那么近似估计值就是e^n
: x_0,y_0,z_0的量级都是k^(1/3)
: 要求精确解的话,需要在近似解(截面)附近搜索了,而截面的面积是O(k^(2/3)),所以我估计
: 最后算法能优化到 k^(2/3)
: 不过还是queue的方法elegant很多
:

1 (共1页)
进入JobHunting版参与讨论
相关主题
一道老题但是以前的解好象都不对管不住自己,怎么办?
微软面试题一道今天去面试有点受宠若惊
2D median problem有什么fresh CS MS丢人到找不到工作,灰溜溜回国的?
新鲜面试题大家帮我看看这是啥意思啊?
sample 设计问题的linkHM 如果说你有很大潜力
求救: 打印binary tree收集的一些design问题
圣诞大礼- 已付费上百猎头公司的网址求教一道经典面题的解法
大量 SDEs opening (更新 2)贡献两道google面试题
相关话题的讨论汇总
话题: lattice话题: kth话题: numbers话题: find话题: hint