《数据科学面试40+真题讲解》,K神本年度最后一次开课


一亩三分地论坛

 找回密码
 Sign Up 注册获取更多干货
码农求职神器Triplebyte:
不用海投,内推你去多家公司面试
Airbnb 数据科学职位
in analytics and inference
天天打游戏、照样领工资,
你要不要来?
把贵司招聘信息放这里
查看: 1829|回复: 0
收起左侧

求问一道Amazon的题目

[复制链接] |试试Instant~ |关注本帖
ziningxiao2 发表于 2015-3-22 23:03:51 | 显示全部楼层 |阅读模式

2015(1-3月) 码农类 硕士 全职@Amazon - 网上海投 - 技术电面 |Other

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?Sign Up 注册获取更多干货

x
A binary tree is either an empty tree (represented by an empty pointer) or a
node consisting of a single integer value and two binary trees called the
left subtree and right subtree.
.1point3acres缃A binary tree T is given. A path in tree T is a non-empty sequence of nodes .鏈枃鍘熷垱鑷1point3acres璁哄潧
of tree T such that each consecutive node in the sequence is a subtree of
its preceding node.
A path P in tree T is given. The amplitude of path P is the maximum
difference between values of nodes on path P. The amplitude of tree T is the
maximum amplitude of paths in T. If tree T is empty, then it does not have
any paths and its amplitude is assumed to be 0.
For example, consider the following tree T consisting of nine nodes:
Sequence [9, 8, 2] is a path in this tree. Sequence [12, 8, 2] is not a path
in this tree. Path [5, 8, 2] has amplitude 6. Paths [9, 8, 2] and [5, 8, 12
] have amplitude 7. The amplitude of the tree is 7, as no path in it has
amplitude greater than [9, 8, 2] or [5, 8, 12].
Assume that the following declarations are given:
class Tree {
  public int x;
  public Tree l;
  public Tree r;. visit 1point3acres.com for more.
}
Write a function:
class Solution { public int solution(Tree T); }
that, given a tree T consisting of N nodes, returns the amplitude of T.
For example, given tree T shown in the example above, the function should
return 7.
Assume that:
·    N is an integer within the range [0..1,000,000];
·    each element of tree T is an integer within the range [−1,000,
000,000..1,000,000,000].. 鍥磋鎴戜滑@1point 3 acres
Complexity:
·    expected worst-case time complexity is O(N);
·    expected worst-case space complexity is O(N).
// you can also use imports, for example:
// import java.math.*;
class Solution {
    public int solution(Tree T) {
        // write your code in Java SE 6
    }
}

本版积分规则

关闭

一亩三分地推荐上一条 /5 下一条

手机版|小黑屋|一亩三分地论坛声明

custom counter

GMT+8, 2017-11-18 03:44

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

快速回复 返回顶部 返回列表