由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Google电面题一道
相关主题
python里面怎么表示树?问一道算法题
求教一道老题面试题
请问一道题MS面试题
请教一道g算法题BST面试题
Twitter电面未通过一个GOOG的二叉树面试题
在版上看到的G题google电面
hackerrank上的A journey to the Moon做道有序数组元素求最大和题?
发个Yahoo onsite面经,攒人品,求bless!! executive committee谷歌 电面
相关话题的讨论汇总
话题: string话题: input话题: parent话题: animal话题: edge
进入JobHunting版参与讨论
1 (共1页)
s****n
发帖数: 70
1
给了这么长一道题,光读就读了半天
Write a Java function, printTree(), which prints a given tree in depth first
format to stdout. Details:
The argument of printTree is a stream of pairs of string values.
Each string found anywhere in the input represents a unique node.
Each item in the stream is a pair indicating a parent/child relationship
in the tree. The first element in the pair is the parent. The second
element in the pair is the child.
Each parent can have many children.
The input list may contain relationship pairs in any order, although:
The order in which the pairs appear in the input list determines the nodes’
order with respect to its siblings.
public static class Edge {
String parent;
String child;
public static Edge of(String parent, String child) { ... }
}
Example input:
List input = newArrayList();
input.add(Edge.of(“cat”, “lion”));
input.add(Edge.of(“mammal”, “cat”));
input.add(Edge.of(“animal”, “fish”));
// Note that the list of nodes is disjoint at this point.
input.add(Edge.of(“animal”, “mammal”));
input.add(Edge.of(“animal”, “bird”));
input.add(Edge.of(“lifeform”, “animal”));
TreePrinter.printTree(input);
Expected output:
lifeform
animal
fish
mammal
cat
lion
bird
l*********8
发帖数: 4642
2
谢谢分享
先建树,然后输出。 其实是两道小题

first


【在 s****n 的大作中提到】
: 给了这么长一道题,光读就读了半天
: Write a Java function, printTree(), which prints a given tree in depth first
: format to stdout. Details:
: The argument of printTree is a stream of pairs of string values.
: Each string found anywhere in the input represents a unique node.
: Each item in the stream is a pair indicating a parent/child relationship
: in the tree. The first element in the pair is the parent. The second
: element in the pair is the child.
: Each parent can have many children.
: The input list may contain relationship pairs in any order, although:

p*****2
发帖数: 21240
3
用个hashtable代表树就好了吧。
1 (共1页)
进入JobHunting版参与讨论
相关主题
谷歌 电面Twitter电面未通过
Amazon 2 电面经历在版上看到的G题
问一个很简单的suffix tree问题。请指点。hackerrank上的A journey to the Moon
A家,link all node in the same lev发个Yahoo onsite面经,攒人品,求bless!! executive committee
python里面怎么表示树?问一道算法题
求教一道老题面试题
请问一道题MS面试题
请教一道g算法题BST面试题
相关话题的讨论汇总
话题: string话题: input话题: parent话题: animal话题: edge