由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - g面经来一个。
相关主题
linkedin电面LinkedIn 面试题讨论
贴一个C++ nested Iterator的code,求讨论和指正。问一个Linkedin经典题
L二电面据,附面经谁能给个Serialization/Deserialization of a Binary Tree Java版完整code?
用有限状态机写了一下leetcode valid numberAmazon面试题请教
发现valid number真是必杀题List Flattening from book
ebay第一轮电话面经又面了一上午,M家的,大家进来做题
C++ Q76: singly linked list -- 这个逆序打印有什么错?一道面试题:Flatten a multilevel linked list
问一个C++的binary search tree类实现问题 (转载)版上看到的几道F家的题目
相关话题的讨论汇总
话题: index话题: list话题: nestedlist话题: nested话题: node
进入JobHunting版参与讨论
1 (共1页)
t**r
发帖数: 3428
1
Given a list which can can contain elements as well as lists, write an
iterator to flatten a nested list.
e***a
发帖数: 1661
2
it's not difficult
m******3
发帖数: 346
3
用c++很难写啊,关键是c++怎么表示一个nested list,有什么好方法么?
b*******w
发帖数: 56
4
type 'a elem = Single of 'a | Multi of ('a elem list);;
let rec flatten l =
match l with
| [] -> []
| hd :: tl -> match hd with
| Single x -> x :: flatten tl
| Multi x -> (flatten x) @ flatten tl;;
e********2
发帖数: 495
5
看起来像Ocaml,Haskel之类的。

【在 b*******w 的大作中提到】
: type 'a elem = Single of 'a | Multi of ('a elem list);;
: let rec flatten l =
: match l with
: | [] -> []
: | hd :: tl -> match hd with
: | Single x -> x :: flatten tl
: | Multi x -> (flatten x) @ flatten tl;;

s**x
发帖数: 7506
6

C++ 怎么表示一个tree node? 用pointer 呗。
用 subclass, pointer to the base class 也可以。

【在 m******3 的大作中提到】
: 用c++很难写啊,关键是c++怎么表示一个nested list,有什么好方法么?
h**k
发帖数: 3368
7
每个node是一个class object,class含有两个field,一个是list,一个是element
value

【在 m******3 的大作中提到】
: 用c++很难写啊,关键是c++怎么表示一个nested list,有什么好方法么?
e**y
发帖数: 784
8
格式都坏了,凑合看吧
这是airbnb的电面题
// [123,456,[788,799,833],[[]],10,[]]
// 123->456->788(list)->[](list)->10->(list)
// 799
// 833
class nestedList {
private:
bool isNumber;
list l;
int val;
public:
nestedList(string, int&);
void print();
};
nestedList::nestedList(string s, int& index) {
if(index==s.length()) return;
// object is a number
if(isdigit(s[index])) {
size_t sz;
val=stoi(s.substr(index), &sz);
// cout << "index==" << index << endl;
// cout << "value==" << val << endl;
isNumber=true;
index+=sz;
return;
}
// object is a list
isNumber=false;
// s[index]=='[', s[index+1]==']'
if(s[index+1]==']') { // list is empty
index+=2;
return;
}
// s[index]=='[', s[index+1]==number or '[';
do {
index++; // skip '[' or ','
nestedList object(s, index);
l.push_back(object);
} while(s[index]==',');
// s[index]==']'
index++; // skip ']'
return;
}
void nestedList::print() {
// print the number
if(isNumber) {
cout << val;
return;
}
// print the list
cout << '[';
for(auto it=l.begin(); it!=l.end(); it++) {
it->print();
if(l.end()!=next(it,1)) cout << ',';
}
cout << ']';
}

【在 t**r 的大作中提到】
: Given a list which can can contain elements as well as lists, write an
: iterator to flatten a nested list.

k***g
发帖数: 166
9
struct Node {
int value;
struct Node *next;
struct Node *nested;
};
Node *h = get_list();
if (h->nested) { // then there is a nested list behind this node
h = h->nested;
} else { // otherwise there is no nested list behind it
h = h->next;
}

【在 m******3 的大作中提到】
: 用c++很难写啊,关键是c++怎么表示一个nested list,有什么好方法么?
j**********3
发帖数: 3211
10
这个不能用java写吧?python的题吧?
java的list不是有type限定么?

【在 t**r 的大作中提到】
: Given a list which can can contain elements as well as lists, write an
: iterator to flatten a nested list.

V******B
发帖数: 3940
11
用C++11?
还是该用variant?

【在 e**y 的大作中提到】
: 格式都坏了,凑合看吧
: 这是airbnb的电面题
: // [123,456,[788,799,833],[[]],10,[]]
: // 123->456->788(list)->[](list)->10->(list)
: // 799
: // 833
: class nestedList {
: private:
: bool isNumber;
: list l;

1 (共1页)
进入JobHunting版参与讨论
相关主题
版上看到的几道F家的题目发现valid number真是必杀题
回馈本版 众小公司面经ebay第一轮电话面经
一些人简历上没有本科学校C++ Q76: singly linked list -- 这个逆序打印有什么错?
LinkedIn Onsite 面经问一个C++的binary search tree类实现问题 (转载)
linkedin电面LinkedIn 面试题讨论
贴一个C++ nested Iterator的code,求讨论和指正。问一个Linkedin经典题
L二电面据,附面经谁能给个Serialization/Deserialization of a Binary Tree Java版完整code?
用有限状态机写了一下leetcode valid numberAmazon面试题请教
相关话题的讨论汇总
话题: index话题: list话题: nestedlist话题: nested话题: node