由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 一道有意思的Google面试题
相关主题
贴两个比较tricky,又常被问到的面试题leetcode: largest rectangle in histogram求帮助
今天一道面试题主动跪了问一道C++ template的面试题
请教一道算法题问一个linkedin的面试题
出道小题[合集] 一道 yahoo 面试题
Amazon算法问题请教A blackbox function f(x)
An interview question from a well-known small company刚刚被Google电面了,真失败
问道题一道热门的 Google 面试题
[InterviewStreet] XOR key (50 Points),请pass的大牛给点思路Google Onsite 面经
相关话题的讨论汇总
话题: 10话题: number话题: so话题: largest话题: consider
进入JobHunting版参与讨论
1 (共1页)
m*****f
发帖数: 1243
1
Consider a function which, for a given whole number n, returns the number of
ones required when writing out all numbers between 0 and n.
For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
that f(n)=n?
h*********i
发帖数: 2605
2
f(13)=5
m*****f
发帖数: 1243
3
1, 10, 11, 12, 13
6

【在 h*********i 的大作中提到】
: f(13)=5
s*x
发帖数: 3328
4
1 10 11 12 13

【在 h*********i 的大作中提到】
: f(13)=5
n****g
发帖数: 14743
5
有趣

of

【在 m*****f 的大作中提到】
: Consider a function which, for a given whole number n, returns the number of
: ones required when writing out all numbers between 0 and n.
: For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
: that f(n)=n?

S*********N
发帖数: 6151
6

of
f(0)=0

【在 m*****f 的大作中提到】
: Consider a function which, for a given whole number n, returns the number of
: ones required when writing out all numbers between 0 and n.
: For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
: that f(n)=n?

j**7
发帖数: 59
7
f(n) = f(n-1)+y(n)
y(n) is the number of 1 in n
Is it good enough?
g*******y
发帖数: 1930
8
not good enough
有logN的算法:
f(n) = f(n/10)*10 + n/10
这个式子只是个近似,边界值处理要注意一下

【在 j**7 的大作中提到】
: f(n) = f(n-1)+y(n)
: y(n) is the number of 1 in n
: Is it good enough?

a*****r
发帖数: 55
9
999999999
n******r
发帖数: 1247
10
这chinglish...

of

【在 m*****f 的大作中提到】
: Consider a function which, for a given whole number n, returns the number of
: ones required when writing out all numbers between 0 and n.
: For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
: that f(n)=n?

相关主题
An interview question from a well-known small companyleetcode: largest rectangle in histogram求帮助
问道题问一道C++ template的面试题
[InterviewStreet] XOR key (50 Points),请pass的大牛给点思路问一个linkedin的面试题
进入JobHunting版参与讨论
g*******y
发帖数: 1930
11
呵呵,你不说我们还没注意到,"whole number"~

【在 n******r 的大作中提到】
: 这chinglish...
:
: of

n******r
发帖数: 1247
12
"whole number"反应了半天才知道是啥意思,"the next largest n"还没明白啥意思

【在 g*******y 的大作中提到】
: 呵呵,你不说我们还没注意到,"whole number"~
a*****r
发帖数: 55
13
f(10^k)=k*10^(k-1) + 1
m*****f
发帖数: 1243
14
网上看到转贴得, 不是我写的, 没注意

【在 n******r 的大作中提到】
: 这chinglish...
:
: of

m*****f
发帖数: 1243
15
事实上下一个f(n) = n的数好像是199981, 最优应该有logn的算法

【在 a*****r 的大作中提到】
: 999999999
a*****r
发帖数: 55
16
Yes, I was wrong.
f(10^10-1) = 10^10
a*****r
发帖数: 55
17
199981 is actually right.
f*********r
发帖数: 68
18
Please read the question carefully before attempting to think it's Chinglish
. There is nothing wrong with the term "whole number" and "the next largest
n".

【在 n******r 的大作中提到】
: "whole number"反应了半天才知道是啥意思,"the next largest n"还没明白啥意思
b***e
发帖数: 1419
19
199981

number of
such

【在 m*****f 的大作中提到】
: Consider a function which, for a given whole number n, returns the number of
: ones required when writing out all numbers between 0 and n.
: For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
: that f(n)=n?

b***e
发帖数: 1419
20
Such numbers are finite. So it's really O(n), in a strict sense.

【在 m*****f 的大作中提到】
: 事实上下一个f(n) = n的数好像是199981, 最优应该有logn的算法
相关主题
[合集] 一道 yahoo 面试题一道热门的 Google 面试题
A blackbox function f(x)Google Onsite 面经
刚刚被Google电面了,真失败问一道算法题largest subsequence sum <= max
进入JobHunting版参与讨论
c******a
发帖数: 198
21
whole number有啥问题?

【在 g*******y 的大作中提到】
: 呵呵,你不说我们还没注意到,"whole number"~
m*****f
发帖数: 1243
22
O(logn)是肯定的, brute force解法就是O(n)阿

【在 b***e 的大作中提到】
: Such numbers are finite. So it's really O(n), in a strict sense.
l*******r
发帖数: 511
23
could you explain the algorithm?

【在 a*****r 的大作中提到】
: 199981 is actually right.
H*M
发帖数: 1268
24
觉得有点奇怪
他们就写那么一个式子
是一个现有的成熟的算法还是,你们现场想出来的?
解释一下吧
我想到的就是recursion的那个O(n)算法
你们怎么都这么牛
就说一个式子

【在 l*******r 的大作中提到】
: could you explain the algorithm?
t******e
发帖数: 1293
25
这个在《编程之美》里面有,可以下载pdf看,或者买一本。

of

【在 m*****f 的大作中提到】
: Consider a function which, for a given whole number n, returns the number of
: ones required when writing out all numbers between 0 and n.
: For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
: that f(n)=n?

c*****g
发帖数: 1137
26
什么叫the next largest? 第二大的?

of

【在 m*****f 的大作中提到】
: Consider a function which, for a given whole number n, returns the number of
: ones required when writing out all numbers between 0 and n.
: For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
: that f(n)=n?

m********0
发帖数: 2717
27
programming pearl?

【在 t******e 的大作中提到】
: 这个在《编程之美》里面有,可以下载pdf看,或者买一本。
:
: of

m*****f
发帖数: 1243
28
我下载的不全, 请问你有全的pdf吗?

【在 t******e 的大作中提到】
: 这个在《编程之美》里面有,可以下载pdf看,或者买一本。
:
: of

h***r
发帖数: 726
29
no. I finished reading this book. not in that book. (unless in the question
part) : )

【在 m********0 的大作中提到】
: programming pearl?
b***e
发帖数: 1419
30
Sorry, typo. I mean O(1). There are only finite number of integers n
such that fn(n) = n.

【在 m*****f 的大作中提到】
: O(logn)是肯定的, brute force解法就是O(n)阿
相关主题
给大家推荐个网站,interviewstreet.com今天一道面试题主动跪了
问个老题 - max submatrix with the same border请教一道算法题
贴两个比较tricky,又常被问到的面试题出道小题
进入JobHunting版参与讨论
H*M
发帖数: 1268
31
你不要老claim something吧,你总得给点proof或者说明什么的

【在 b***e 的大作中提到】
: Sorry, typo. I mean O(1). There are only finite number of integers n
: such that fn(n) = n.

b***e
发帖数: 1419
32
First see that:
f(10^n-1) = 10^(n-1) * n
e.g., f(9) = 1, f(99) = 20, f(999) = 300, ...
For the first several iterations, apparently f(n) < n always. So the
hope is one day, f(n) will catch up. Let's understand that the first
catch-up must happen in the form of "1x...", because that's where n -
f(n) is reducing.
So now, the question is, what's the "x.." after 1. Consider the length
of it. Can it be "1xx"? No, since at 99 you are down by 99-20 = 79,
and during 100 ~ 199, you can only catch u

【在 H*M 的大作中提到】
: 觉得有点奇怪
: 他们就写那么一个式子
: 是一个现有的成熟的算法还是,你们现场想出来的?
: 解释一下吧
: 我想到的就是recursion的那个O(n)算法
: 你们怎么都这么牛
: 就说一个式子

b***e
发帖数: 1419
33
f(10^100 - 1) = 100 * 10^99 = 10^101
So after 10^100, n will never again catch up with f(n).
It is not hard to see that f(n)/n is O(log(n)).

【在 H*M 的大作中提到】
: 你不要老claim something吧,你总得给点proof或者说明什么的
c*******d
发帖数: 255
34
应该是再也没有了吧
9以下的恰好有 1个
99以下的恰好有20个
999以下的恰好有300个
9999以下的恰好有4000个
一般的,k个9以下的恰好有k*10^{k-1}个
所以f(n)增长速度怎么都赶不上n

of

【在 m*****f 的大作中提到】
: Consider a function which, for a given whole number n, returns the number of
: ones required when writing out all numbers between 0 and n.
: For example, f(13)=6. Notice that f(1)=1. What is the next largest n such
: that f(n)=n?

m*****f
发帖数: 1243
35
事实上有不少...

【在 c*******d 的大作中提到】
: 应该是再也没有了吧
: 9以下的恰好有 1个
: 99以下的恰好有20个
: 999以下的恰好有300个
: 9999以下的恰好有4000个
: 一般的,k个9以下的恰好有k*10^{k-1}个
: 所以f(n)增长速度怎么都赶不上n
:
: of

c*******d
发帖数: 255
36
受教了,多谢!

【在 b***e 的大作中提到】
: First see that:
: f(10^n-1) = 10^(n-1) * n
: e.g., f(9) = 1, f(99) = 20, f(999) = 300, ...
: For the first several iterations, apparently f(n) < n always. So the
: hope is one day, f(n) will catch up. Let's understand that the first
: catch-up must happen in the form of "1x...", because that's where n -
: f(n) is reducing.
: So now, the question is, what's the "x.." after 1. Consider the length
: of it. Can it be "1xx"? No, since at 99 you are down by 99-20 = 79,
: and during 100 ~ 199, you can only catch u

b***e
发帖数: 1419
37
Dude,
r = k * 10^(k-1) / 10^k = k / 10
When k -> infinity, r -> infinity. I told you fn/n is O(log(n)). Didn't
you see that?

【在 c*******d 的大作中提到】
: 应该是再也没有了吧
: 9以下的恰好有 1个
: 99以下的恰好有20个
: 999以下的恰好有300个
: 9999以下的恰好有4000个
: 一般的,k个9以下的恰好有k*10^{k-1}个
: 所以f(n)增长速度怎么都赶不上n
:
: of

p********7
发帖数: 549
38
I got an idea about it.
前10个数0-9 有1个1
前100个数0-99有20个1
前1000个数0-999有20*10+100= 300
。。。
前100000个数0-99999有50000个1
前200000个数0-199999有50000+100000+50000 = 200000
f(199999) = 200000
so go back one by one,get the right one
more explanation
前20 0-19 有12个
前200 0-199 有20+100+20 = 140
前2000 0-1999 有300+1000+300 = 1600
只有在n的最高位是1的情况下,f(n)增加速度是高于n,其他时候都是低于n
1 (共1页)
进入JobHunting版参与讨论
相关主题
Google Onsite 面经Amazon算法问题请教
问一道算法题largest subsequence sum <= maxAn interview question from a well-known small company
给大家推荐个网站,interviewstreet.com问道题
问个老题 - max submatrix with the same border[InterviewStreet] XOR key (50 Points),请pass的大牛给点思路
贴两个比较tricky,又常被问到的面试题leetcode: largest rectangle in histogram求帮助
今天一道面试题主动跪了问一道C++ template的面试题
请教一道算法题问一个linkedin的面试题
出道小题[合集] 一道 yahoo 面试题
相关话题的讨论汇总
话题: 10话题: number话题: so话题: largest话题: consider