Re: [问题] Google Interview Question (4)

楼主: Leon (Achilles)   2013-03-06 02:08:47
※ 引述《RockLee (Now of all times)》之铭言:
: ※ 引述《Leon (Achilles)》之铭言:
: : Sorry, I can't understand your writing.
: : Also, the link seems to be wrong...
: : Can you describe it, step by step.
: : For example, there are only 3 words, (a,b,c)
: : how are you going to find the window, for the document
: : [b b a c b b b b c b b a] ?
: 虽然 pseudo code 可能比较短,
: 但由于 interview Google 时必需写 actual code,
: 所以我想还是直接用实际的 Java code 表达我的想法.
: (我假设 window 长度指的是包含的字数, 与每个字的长度无关)
: 以 Leon 大给的例子:
: document: b b a c b b b b c b b a
: index: 0 1 2 3 4 5 6 7 8 9 10 11
: occurence a: 2, 11
: occurence b: 0, 1, 4, 5, 6, 7, 9, 10
: occurence c: 3, 8
: 执行过程及结果会是:
: windowBegin = 0; windowEnd = 3
: windowBegin = 1; windowEnd = 3
: windowBegin = 2; windowEnd = 4
: windowBegin = 3; windowEnd = 11
: windowBegin = 4; windowEnd = 11
: windowBegin = 5; windowEnd = 11
: windowBegin = 6; windowEnd = 11
: windowBegin = 7; windowEnd = 11
: windowBegin = 8; windowEnd = 11
: bestBegin = 1
: bestEnd = 3
:
作者: seanwu (海恩)   2013-03-06 04:41:00
找出对应当前start的ending是O(logK),他在移除start换下一个start时,补上目前start的list中下一个index是必要而且保证是合法的window,TreeMap中总是有K个index找ending只是找出max index而已
楼主: Leon (Achilles)   2013-03-07 13:38:00
我看不懂你写什么

Links booklink

Contact Us: admin [ a t ] ucptt.com