由买买提看人间百态

topics

全部话题 - 话题: iterator
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)
c**********e
发帖数: 2007
1
来自主题: JobHunting版 - C++ Q56: map & typedef (C29)
typedef std::map MapType;
MapType theMap;
Referring to the code sample above, which one of the following blocks of
code displays the string contents of the entire map theMap?
a) MapType::iterator it = theMap.first();
while(it!= theMap.end()) std::cout << it;
b) MapType::iterator it = theMap.begin();
while(it!= theMap.end()) std::cout << theMap[it];
c) MapType::iterator it = theMap.begin();
while(it!= theMap.end()) std::cout << (*it++).second;
d) MapType::iterator it = theMap
y*******n
发帖数: 129
2
来自主题: JobHunting版 - 一道有关String的面试题
store list of words in hashtable
key: signature
value: list of words with the same signature.
recurse on input to find solution
code:
typedef std::map > Dict;
typedef std::map >::iterator DictIter;
void descramble(const std::string& input, std::string& output, Dict& dict) {
if (input.empty()) {
std::cout << output << std::endl;
} else {
for (size_t i=1; i<=input.size(); i++) {
std::string ... 阅读全帖
y*********e
发帖数: 518
3
来自主题: JobHunting版 - Google Onsite 面经
这个yield return只是一个syntax sugar, 只能用于来写iterator.
尤其是这个面试题,要记住状态,满麻烦的.若是只是想,我就写一个inorder traversal,
那就容易多啦!yield return就是让开发者只需要按照traversal的思路写,然后在访问
每一个节点的时候,yield return下便是了!
比如,这个很简单的例子.给定一个array,来写一个iterator:
int[] intArray;
.......
for (int i = 0; i < intArray.Length; i++)
yield return intArray[i];
编译器会自动把如上的代码转换成,创建一个iterator,然后每执行current()一次,就从
array里面提取一个对象,如下:
class __intArrayEnumerator // C#里面把iterator叫Enumerator
{
private int[] __object;
private int __state;
public int... 阅读全帖
i**********e
发帖数: 1145
4
来自主题: JobHunting版 - 请问一道很难的面试题
刚想到很精简的 code,不需要用 post-fix stack-based expression,直接储存进一
个 string 数组即可。
效率应该是不错的了,有一些方面可以考虑提高效率,例如用 vector 需要删除元素可
能会慢些,但 vector 里的元素很少,应该影响不大。
还有一点就是每次传递归的时候,都需要把所有的数组重新 copy 一次。这是无可避免
的,因为每次进入下一层递归时必须传 copy,不能在原有数组中更改。
#include
#include
#include
#include
#include
using namespace std;
void generate(vector A, int target, int s, vector expression);
template
void eraseAt(vector &vec, int i) {
typename vector::iterator ... 阅读全帖
S*********r
发帖数: 5693
5
来自主题: JobHunting版 - 请问这段代码什么意思?
发信人: hsh (三胡), 信区: Basketball
标 题: 姚明准备当码工了
发信站: BBS 未名空间站 (Wed Mar 2 22:50:08 2011, 美东)
http://sports.sohu.com/20110303/n279628477.shtml
姚明在自己facebook和twitter上写道:“Welcome to function(iterator) { var
result = true; this.function(iterator) { var index = 0; try { this._each(
function(value) { iterator(value, index++); }); } catch (e) { if (e != $
break) throw e; } return this; }(function(value, index) { result = result &&
!!(iterator || Prototype.K)(value, index); if (!result) throw $break; });
... 阅读全帖
e****a
发帖数: 449
6
. 在版上潜水快一年了 收获非常大 现在拿到了比较满意的offer, 中型IT公司,环境
还不错,非
湾区和NYC, 一年8万多。发找工作的经历回馈本版, 给还在找工或者将要找工的同学
参考.主要针
对转行的,没有经验的同学,如果有说的不对的或者废话的, 大家可以直接忽略,因为
本人是菜鸟.
背景: 生物phd, WSN, 计算机 master.毫无工作经验,无实际project经验. 面过的
公司:
Blackrock, BOA, Morgan stanley, GS, Facebook, Google 和给offer的公司。 有一
点统计和 ML的知识背景,后来证明毫无用处. c++和 java比较熟悉 没有大project经验
,
j2ee, .net, LAMP 知道一些, 后来突击学习了操作系统和网络的基本知识, 还有就是
经常在
mitbbs 学习大牛们的帖子. 整理了版上一年内的 和 careercup 上的一些面经, 比较
乱, 大家
可以参考下, 基本上概括了店面的所有题,onsite的大部分题. 非常感谢版上的常驻大
牛小牛们给
我的帮助,现在牛牛们都忙着发财... 阅读全帖
l******t
发帖数: 2243
7
congrats!

发信人: evaeva (evaeva), 信区: JobHunting
标 题: 生物PHD 转行找CS, 报Offer和罗嗦的面经
发信站: BBS 未名空间站 (Sat Mar 19 06:10:37 2011, 美东)
. 在版上潜水快一年了 收获非常大 现在拿到了比较满意的offer, 中型IT公司,环境
还不错,非
湾区和NYC, 一年8万多。发找工作的经历回馈本版, 给还在找工或者将要找工的同学
参考.主要针
对转行的,没有经验的同学,如果有说的不对的或者废话的, 大家可以直接忽略,因为
本人是菜鸟.
背景: 生物phd, WSN, 计算机 master.毫无工作经验,无实际project经验. 面过的
公司:
Blackrock, BOA, Morgan stanley, GS, Facebook, Google 和给offer的公司。 有一
点统计和 ML的知识背景,后来证明毫无用处. c++和 java比较熟悉 没有大project经验
,
j2ee, .net, LAMP 知道一些, 后来突击学习了操作系统和网络的基本知识, 还有就是... 阅读全帖
l*****g
发帖数: 685
8
这个跟iterator(int i)怎么implement有关吧
btw, iterator(int i)这样的API应该说是个Indexer, 而不是iterator. iterator是一
个一个按顺序取元素,Indexer可以取任意指定的位置

C. These code block don't share
3 possible reasons why case 2
i**********e
发帖数: 1145
9
来自主题: JobHunting版 - 问道amazon的面试题
My code found two valid answers for the following input in about 3 secs (
obviously not as good as grass, but the algorithm is easier to code).
Input, A = {2 2 4 6 7 7 8 8 8 9 9 10 11 12 13 14 15 16 16 17 18 20 21 22 23
24 25 26 28 29 30 31 33 34 37 38 39 40 41 45 47 47 49 54 56 }
Answer:
2 7 2 4 8 8 8 10 7
7 10 8 8 8 4 2 7 2
grass, can you explain whether your code generates the solution {7 10 8 8 8
4 2 7 2} ?
Test cases:
A = {7,10,5,2,8,3}
Answer:
2 5 3
3 5 2
A = {1,1,1,2,3,2}
Answer:
1 1 1
A ... 阅读全帖
i**********e
发帖数: 1145
10
来自主题: JobHunting版 - 问道amazon的面试题
My code found two valid answers for the following input in about 3 secs (
obviously not as good as grass, but the algorithm is easier to code).
Input, A = {2 2 4 6 7 7 8 8 8 9 9 10 11 12 13 14 15 16 16 17 18 20 21 22 23
24 25 26 28 29 30 31 33 34 37 38 39 40 41 45 47 47 49 54 56 }
Answer:
2 7 2 4 8 8 8 10 7
7 10 8 8 8 4 2 7 2
grass, can you explain whether your code generates the solution {7 10 8 8 8
4 2 7 2} ?
Test cases:
A = {7,10,5,2,8,3}
Answer:
2 5 3
3 5 2
A = {1,1,1,2,3,2}
Answer:
1 1 1
A ... 阅读全帖
r******n
发帖数: 170
11
来自主题: JobHunting版 - 一道G家题目
贴个c++的版本:
void restore(int cnt_arr[], int orig_arr[], size_t size)
{
vector svec;
for(size_t i=0; i svec.push_back(i+1);
for(size_t i=0; i {
vector::iterator iter=svec.begin()+cnt_arr[i];
orig_arr[i]=*iter;
svec.erase(iter);
}
}
不知道能不能写的更简洁点?
d*******d
发帖数: 2050
12
来自主题: JobHunting版 - 一道G家题目
这一段:
size_t j=0;
while(j {
++j;
++iter;
}
直接写:
iter = iter + cnt_arr[i]
不就得了.vector的iterator是random access型的
s*******f
发帖数: 1114
13
来自主题: JobHunting版 - 问一道微软面试题
static const int MAX_LEN = 10000000;//max size, if we cannot find
deplication within MAX_LEN, the random function is good.
//return where it begin duplicate
int TestRandomFun(int (*f)()){
static const int INIT_LEN = 100000;
static const int SUBARR_LEN = 10; //find 10-len substr first then
keep comparing,
static const int DUP_THRESHHOD = 1000; //if it keep equalling to
1000, we say then random function produce duplications.
vector v(INIT_LEN);
int c = 0;
while (v.size() < MAX_LEN){
for (int ... 阅读全帖
S*******0
发帖数: 198
14
来自主题: JobHunting版 - 贡献邮件面试题(Web Development)
1. Deadlock describes a situation that two or more threads (processes) are
blocked forever, waiting for each other.
Causes: one thread needs to visit the resource that another thread is
possessing and vice versa.
Effects: If deadlock happens, the threads involved will hang there forever
in an undesired status. Deadlock should be avoided.
2.
public ArrayList getToyotas(ArrayList cars)
{
if(cars == null) return null;

ArrayList toyotas = new ArrayList();
for ... 阅读全帖
A**u
发帖数: 2458
15
来自主题: JobHunting版 - G家电面砸了,面经
我有笨办法
#include
#include
#include
#include
using namespace std;
vector P( int n );
vector R( int n );
vector P( int n )
{ vector code;
if ( n == 1 )
{
code.push_back(string("0"));
code.push_back(string("1"));
}
else
... 阅读全帖
S**I
发帖数: 15689
16
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
S**I
发帖数: 15689
17
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
l*****y
发帖数: 56
18
来自主题: JobHunting版 - 一道google 经典题
像楼主说的,每次把最小的往上移。
用了三个指针,分别指向三个数组,中间会交换指针,min, mid, max,他们分别指向
三个从小到到大排列的数, 距离就是 *max -*min.
最后return the minimal distance, the vector d records the three elements
with minimal distance.
请指正, 谢谢了!
void swap(vector::iterator &a, vector::iterator &b){
vector::iterator temp;
temp=a;

a=b;
b=temp;
}
int min_dist(vector &a, vector &b, vector &c, vector &d){
vector::iterator min=a.begin(), mid=b.begin(), max=c.begin();
int dist=100... 阅读全帖
l*****y
发帖数: 56
19
来自主题: JobHunting版 - 一道google 经典题
像楼主说的,每次把最小的往上移。
用了三个指针,分别指向三个数组,中间会交换指针,min, mid, max,他们分别指向
三个从小到到大排列的数, 距离就是 *max -*min.
最后return the minimal distance, the vector d records the three elements
with minimal distance.
请指正, 谢谢了!
void swap(vector::iterator &a, vector::iterator &b){
vector::iterator temp;
temp=a;

a=b;
b=temp;
}
int min_dist(vector &a, vector &b, vector &c, vector &d){
vector::iterator min=a.begin(), mid=b.begin(), max=c.begin();
int dist=100... 阅读全帖
m****r
发帖数: 141
20
Given a sequence of data (with duplicates), move a fix-sized window along
the data sequence and find mode in the window at each iteraion, where the
oldest data is removed and a new data is inserted to the window.
I cannot find better solutions here.
My idea: Use a hashtable, key is the data, key's data is the frequency of
the data occuring in the window.
At the first iteration, iterate each data in the window and put it to the
hashtable, meanwhile cout the frequency of each data. After that, tra... 阅读全帖
D********g
发帖数: 650
21
来自主题: JobHunting版 - Google onsite归来
面经回馈本版,只列出technical question.
P1:
A. Add next pointer to each node on a BTree to its next sibling on the same
level.
B. Boggle题,find all possible words from a 2D character array.
P2:
A. Given
interface Iterator {
T next();
boolean hasNext();
}
interface Predicate {
boolean accept(T t);
}
Implement a method that creates an "accept" iterator that returns items
accepted by the passedin pred variable.
Iterator conditionIterator(Iterator input, Predicate pred) {
}
B. Concurren... 阅读全帖
h*****g
发帖数: 312
22
来自主题: JobHunting版 - 问道G 的题
A. Given
interface Iterator {
T next();
boolean hasNext();
}
interface Predicate {
boolean accept(T t);
}
Implement a method that creates an "accept" iterator that returns items
accepted by the passedin pred variable.
Iterator conditionIterator(Iterator input, Predicate pred) {
}
这题撒意思?需要设计模式的背景知识吗?
p*****o
发帖数: 1285
23
来自主题: JobHunting版 - 贡献几个on-site题,不说谁家的了
Iterator class provides two basic methods,
bool has_next();
T& next();
要求写一个wrapper class for Iterator>, 实现和Iterator相同的界
面,也就是实现上述两个方法。
n*******w
发帖数: 687
24
来自主题: JobHunting版 - F家面经
1. regex
test过了,要源码的话站内吧。
bool regex(char* str, char* pattern)
if(!str && !pattern) return true;
if(!str || !pattern) retrun false;
if(pattern+1 && *(pattern+1) == '-' && pattern+2) //handle a-z
return *str >= *pattern && *str <= *(pattern+2) && regex(str+1,
pattern+3);
if(pattern+1 && *(pattern+1) == '+')
if(*pattern == '.') //handle .+
bool tmp = false;
char* iter = pattern;
while(iter) //iterater over all possible repeated t... 阅读全帖
d******a
发帖数: 238
25
来自主题: JobHunting版 - 问个题
我刚写了个,没怎么检查,欢迎探讨。
class Iterator{
public:
` Iterator(vector> &a) : v(a)
{
m_outer_iter = v.begin();

while (m_outer_iter != v.end())
{
if (m_outer_iter->size() != 0)
break;
else
m_outer_iter++;
}

if (m_outer_iter == v.end())
m_flag = false;
else
{
m_inner_iter = m_outer_iter->begin();
m_next = *m_inner_iter;
... 阅读全帖
b***i
发帖数: 10018
26
来自主题: JobHunting版 - 三藩pre-ipo公司big data职位招聘
有两种职位,Data Engineer和Data Research Engineer。给办H1-b和绿卡。Junior也
欢迎。
有意者请把简历发到t*******[email protected]。谢谢。
Senior Data Engineer at Tapjoy in San Francisco, CA
Sr. Data Engineer
About Us:
Tapjoy is a mobile value exchange platform, driving personalized app
discovery for consumers, customer acquisition and engagement for app and
brand advertisers, and rich monetization for innovative developers. The
Tapjoy network spans over 20,000 apps and 800 million global consumers on
iOS, Android and Windows Phone. ... 阅读全帖
i*********n
发帖数: 58
27
Pseudocode and implementation needs to be optimized:
set PowerSet(set input)
if (input.empty())
return set.insert(EmptySet);
else
e = input.first();
input.removeFirst();
input = PowerSet(input);

for (iter = input.second(); iter != input.end(); ++iter)
set.insert(SetUnion(e, *iter));
return SetUnion(set, input);
b*******S
发帖数: 17
28
来自主题: JobHunting版 - Python大牛请进
我沒有去看python的code 不過就猜猜看 只是推理
http://docs.python.org/library/stdtypes.html?
highlight=readlines#file.readlines
裡面說Files support the iterator protocol. Each iteration returns the same
result as readline(), and iteration ends when the readline() method returns
an empty string.
所以你stackoverflow裡面的例子
for line in file.readlines():
#preprocess line
yield line
這樣搞不好就是直接弄個iterator來,每次就叫file.readline()去抓一行
如果是這樣的case,那當然就會省空間了
l*****a
发帖数: 14598
29
你这样的好处是什么呢?真的没看懂
我的理解就是一个数组,每个数组保存一个chain
List> [] array= new LinkedList>[size];
hashtableIterator中hold一个 array, index(for the array),Iterator ,V>> (for the list in each slot)
应该就可以了吧?
插入删除都是先找slot,然后对相应的list操作就可以了
hasNext(),next()的话都是先找current iterator.hasNext(), iterator.next()
如果没有的话,再去找下一个slot对应list的iterator

,
l*****a
发帖数: 14598
30
你这样的好处是什么呢?真的没看懂
我的理解就是一个数组,每个数组保存一个chain
List> [] array= new LinkedList>[size];
hashtableIterator中hold一个 array, index(for the array),Iterator ,V>> (for the list in each slot)
应该就可以了吧?
插入删除都是先找slot,然后对相应的list操作就可以了
hasNext(),next()的话都是先找current iterator.hasNext(), iterator.next()
如果没有的话,再去找下一个slot对应list的iterator

,
t********6
发帖数: 348
31
来自主题: JobHunting版 - leetcode出了新题word ladder
第二题,求指导:
class Solution {
public:
void traverse(string& start, string& root, unordered_map string> >& prev, vector& current, vector>& result) {
auto iter = prev.find(root);
for (string str : iter->second) {
current.push_back(str);
if (str == start) {
vector new_one(current.size());
reverse_copy(current.begin(), current.end(), new_one.begin()
);
result.push_ba... 阅读全帖
t********6
发帖数: 348
32
来自主题: JobHunting版 - leetcode出了新题word ladder
第二题,求指导:
class Solution {
public:
void traverse(string& start, string& root, unordered_map string> >& prev, vector& current, vector>& result) {
auto iter = prev.find(root);
for (string str : iter->second) {
current.push_back(str);
if (str == start) {
vector new_one(current.size());
reverse_copy(current.begin(), current.end(), new_one.begin()
);
result.push_ba... 阅读全帖
c*****u
发帖数: 562
33
来自主题: JobHunting版 - 刚刚结束的linkedIn电面
第一题:java.lang.ArrayIndexOutOfBoundsException: -1
T t=flatC.get(currIndex);
用的是楼主提供的testcase
https://dl.dropbox.com/u/7472691/mitbbs/DeepIteratorImplTester.java
也贴个我的第一题吧:
public class DeepIteratorImpl implements Iterator {
private Map> deepIterators;
private Map singleElements;
private int index;
private int maxIndex;
// Constructor
public DeepIteratorImpl(Collection> c) {
if (c... 阅读全帖
a******3
发帖数: 113
34
来自主题: JobHunting版 - Scala怎么通过index访问set或者array
定义了一个
val map = new ConcurrentSkipListMap[Key, Value]()
因为要实现多线程,需要重写他的iterator
我的代码如下
def keyIterator: Iterator[Key] = new Iterator[Key] {
val newMap=getMapClone
var set=newMap.keySet()
var pos = 0
def hasNext = pos < newMap.size()
def next: Key = { val z = array(pos) ; pos += 1 ; z }
}
[error] found : Int
[error] required: Key
array(pos)这方法貌似是通过key去访问,但是我想通过index去访问这个set,该怎么
写呢?或者有什么办法可以iterate这个map的key集合吗
本人新手,无奈网上找不到,求各位不吝赐教
x*****0
发帖数: 452
35
来自主题: JobHunting版 - 两道最近onsite算法题
(2) C++ code:
void split_by_whitespace(string& s, vector& result)
{
stringstream ss(s);
string cur;

while(ss >> cur)
result.push_back(cur);
}
void maxi_assonance(vector& x)
{
vector::iterator it = x.begin();
vector > r;
map key_ind;

for(; it!=x.end(); ++it)
{
string cur = *it;
if(cur[0]=='a' || cur[0]=='e' ||
cur[0]=='i' || cur[0]=='o' ||
cur[0]=='u')
{ ... 阅读全帖
b****g
发帖数: 192
36
来自主题: JobHunting版 - 问一道C++ template的面试题
题目很简单,没什么说的,但是我卡在C++语法上了。
需要自己写个模板,模板里有个iterator,于是我就不知道该怎么写了。
template
class Wrapper
{
iterator it;
};
给class T做个模板,T可以是vector、list等等。我要写的模板就是把T的iterator赋
给it,这样我在it里面找next就相当于在T的iterator里面找。
a******e
发帖数: 710
37
来自主题: JobHunting版 - 狗狗家onsite面经
开始只是想到了O(n)的算法。 O(m)的算法可以这么实现
#include
#include
using namespace std;
struct DListNode {
char val;
DListNode *prev;
DListNode * next;
DListNode(char v): val(v), prev(nullptr), next(nullptr) {}
};
void printList(DListNode* head){
while (head!=nullptr) {
cout<val<<", ";
head = head->next;
}
cout< }
void printSet(unordered_set &s) {
for (auto iter=s.begin(); iter!=s.end(); ++iter)
cout<<(*ite... 阅读全帖
r*********n
发帖数: 4553
38
来自主题: JobHunting版 - 问个题目,找不在区间内的所有数
这种题目一看就知道对方想考察的是binary search的变体
描述算法比较verbose,这里给个例子
interval array A: [{1, 3}, {3, 4}, {7, 12}, {9, 10}] //按照[1, 3, 7, 9]来排
的顺
integer array B: [4, 5, 10]
1. binary search (actually upper_bound) B[0] = 4 in A: get i = 2 (if A[i]==
4,then ++i)
2. iterate through A[0, ..., i-1] until you find the first index j such that
its end time is >= 4: j = 1
3. because j < i, 4 is contained in an interval
4. binary search B[1] = 5 in A: get i = 2
5. iterate through A[j, ..., i-1] (j = 1) until you find t... 阅读全帖
h****y
发帖数: 137
39
来自主题: JobHunting版 - T家电面面经并且不解为何被秒拒
leetcode原题, permutation II和permutation sequence, 就是把int换成了char, 45
分钟的面试老中面试官大哥迟到5分钟, 却要按时结束, 加上闲扯几句, 这两题一共就
32分钟时间, 我自己感觉除了一点小typo之外没有问题啊, 那几个typo还是因为第二题
完全没时间检查了, 有他迟到的5分钟肯定能检查出来. 6个小时后就收到拒信, 而且我
用的C++, 感觉面试官对C++一点都不熟, 基本不说话, 我说好了后他也不review, 不作
评价,第二题还冒了一句std::set的元素是无序的, 你这样遍历得到的结果是随机的,
还浪费我时间跟他解释, 我汗...
下面贴上我的代码, 想请大家评评, 真心不懂为啥被拒, 能不能跟recruiter complain
一下?
1. input : string
output : print all the permutation of the input
there are duplicates in the input, avoid print out the same string in ... 阅读全帖
a******e
发帖数: 710
40
来自主题: JobHunting版 - T家电面面经并且不解为何被秒拒
我觉得30分钟做出这两道题很不简单啊。
不过这个循环的判断应该是小于等于号吧?
for (int i = 1; i <= str.size(); ++i)
nPermute *= i;
string correspPermute(string& str, int index)
{
set table;
for (auto& c : str)
table.insert(c);

int nPermute = 1;
for (int i = 1; i < str.size(); ++i)
nPermute *= i;

string res;
--index;
for (int m = index; m >= 0; --m) // 这里不应该是index应该是str.size()
{
nPermute /= m;
int idx = index / nPermute;
auto iter = table.... 阅读全帖
m*****n
发帖数: 204
41
来自主题: JobHunting版 - LinkedIn 面试题讨论
I wrote a java solution in another thread using iterator-ized (tail)
recursion:
http://www.mitbbs.com/article0/JobHunting/32585567_0.html
It is equivalent to the following python code:
def iterate(list):
for obj in list:
if isinstance(obj, int):
yield obj
else:
for sub_obj in iterate(obj):
yield sub_obj
def main():
list = [ 1, 2, [], 3, [ 4, 5 ], 6 ]
for i in iterate(list):
print i
print 'Done'
h*****u
发帖数: 109
42
来自主题: JobHunting版 - 树遍历的考点小结
多位网友发过了,比如ultrabo,小节一下考点
A
/
B C
共六种排列 (要求): inorder, preorder, postorder, inorder right first (CAB),
preorder right first (ACB), postorder right first (CBA)
实现技术:recursive, iterative with one stack, iterative with two stacks,
iterative with parent pointer but no stacks, iterative with threaded binary
trees, Morris traversal (dynamic threaded tree)
做一个表,行是六种要求,列是各种技术,一共多少啊?还有没想到的吧。
Morris traversal codes: http://www.cnblogs.com/AnnieKim/archive/2013/06/15/MorrisTraversal.html
m*****n
发帖数: 204
43

The following is an O(nlgn) solution for string of size n.
It maintains a heap for eligible chars, preferring longer streams.
Ineligible chars are maintained in a candidate queue, and added back
to the working queue when their position constraint is removed.
public class MinDistance {
public String rearrange(String source, int distance) {
// TODO Check params.

// WorkingQueue of eligible streams. Longest stream at head,
// but BackupStream at tail.
PriorityQueue阅读全帖
t**c
发帖数: 480
44
来自主题: JobHunting版 - 问个算法题
//lst1 has N items, and lst2 has M items
public static void Print( List lst1, List lst2)
{
Iterator itr1 = lst1.iterator();
Iterator itr2 = lst2.iterator();
while (itr1.hasNext() || itr2.hasNext())
{
int x=0, y=0;
if (itr1.hasNext())
{
x = itr1.next();
System.out.println(x);
}
if (itr2.hasNext())
{
y = itr2.next();
System.out.println... 阅读全帖
f**********t
发帖数: 1001
45
来自主题: JobHunting版 - linkedin电面
// Given a nested list of integers, returns the sum of all integers in the
list
// weighted by their depth. For example, given the list {{1,1},2,{1,1}} the
// function should return 10 (four 1's at depth 2, one *2 at depth 1). Given
// the list {1,{4,{6}}} the function should return 27 (one 1 at depth 1, one
4
// at depth 2, and *one 6 at depth 3)
int getNum(string::iterator &i, string::iterator end) {
if (i == end) {
return 0;
}
bool neg = false;
if (*i == '-') {
neg = true;
... 阅读全帖
w********0
发帖数: 377
46
这时当时的code,我copy下来了。请大牛指点。
Given a nested list of positive integers: {{1,1},2,{1,1}}
Compute the reverse depth sum of a nested list meaning the reverse depth of
each node (ie, 1 for leafs, 2 for parents of leafs, 3 for parents of parents
of leafs, etc.) times the value of that node. so the RDS of {{1,1},2,{1,1}
} would be 8 = 1*1 + 1*1 + 2*2 + 1*1 + 1*1.
{1,{4,{6}}}
6*1 + 4*2 + 1*3 = 6+8+3 = 17
struct Iterm
{
int v;
bool isInteger();
int getInteger();
list getList();
l... 阅读全帖
x*******9
发帖数: 138
47
来自主题: JobHunting版 - 问一道G家热题
做了一下
>> 给定一个数字数组 ,其中每个元素是从末端数小于原数组中该元素的个数。求原数
组。
Time complexity: O(n * logn) // quick-sort + traverse
Memo complexity: O(n)
>> 令s[i]为a[i+1..n-1]中比a[i]大的数的数量。求最大的s[i]。要求O(nlogn)
Time complexity: O(n * logn) // Manipulate the Binary Indexed Tree
Memo compleixty: O(n)
#include
#include
#include
#include
#include
#include
using namespace std;
#define print(x) cout << x << endl
#define input(x) cin >> x
const int SIZE = 1024;
// @brief Bin... 阅读全帖
O********e
发帖数: 48
48
来自主题: JobHunting版 - 问道大数据的题
A generalized solution:
Suppose you have a master node (or are able to use a consensus protocol to
elect a master from among your servers). The master first queries the
servers for the size of their sets of data, call this n, so that it knows to
look for the k = n/2 largest element.
The master then selects a random server and queries it for a random element
from the elements on that server. The master broadcasts this element to
each server, and each server partitions its elements into those la... 阅读全帖
f********a
发帖数: 367
49
来自主题: JobHunting版 - 刷了半天题
没刷过iterator的题, 面试被问一个PositiveInteger的Iterator,
就是给你个IntegerIterator, (iterator over an array), 写个
PositiveIterator。iterate over positive integer(next, hasNext, remove)
刚一看, 觉得还行啊, 然后一写, 不大对, 然后一个中国面试官, 还挺照顾, 给
我hint, 我电话里也听不清楚。。。
R*********d
发帖数: 34
50
来自主题: JobHunting版 - 刷了半天题
方便起见,就用了ArrayList,不过意思是一样的。
public class PositiveIntegerIterator
{
private int prev = -1;
private Iterator it;
public PositiveIntegerIterator(Iterator it){
this.it = it;
}
public boolean hasNext(){
if(prev > 0){
return true;
}
while(it.hasNext()){
prev = it.next();
if(prev > 0){
return true;
}
}
return false;
}
public Integer next(){
... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)