由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Java面试题求解
相关主题
careercup书上那个maintain median value的题一个Linkedlist面试题的教训
请教一道题 median ii问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5
算法题问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,
发个evernote的code challengeA家面经 (转载)
[INTERVIEW] Amazon, ITG, YAHOO 电面, 求分析leetcode number of islands为什么不能用BFS?
Facebook 面经求推荐学习recursive 算法的资料
这题到底什么意思?求教一个combination的问题,求好方法
面经求教一道ms的题目
相关话题的讨论汇总
话题: person话题: list话题: null话题: gender话题: public
进入JobHunting版参与讨论
1 (共1页)
b**********f
发帖数: 136
1
Java 小白,实在不知道怎么做。求大侠解答!下周就要去面试了,不是Java
developer的职位,但是会考到一点编程。
public class Person {
Person father;
Person mother;
Gender gender;
Integer age;
List children;
int level = 0;
public enum Gender {
Male,
Female;
}
}
For the above class, you basically have to implement 2 methods.
public List getOldestSisters()
(person can have multiple parents since remarrying )
public List getGreatestAncestors()
Find the oldest sisters of the given Person object. Such class recursively
defines a Person father, Person mother, and a List of children
W***o
发帖数: 6519
2
小朋友,自己要先try try,上来就这么直接问让人写code会被骂的。
不过,恍惚记得大学cs系的女僧貌似都是让其男友写code做作业的
o*******r
发帖数: 73
3
同是java小白,简单写了一下,供参考。希望楼主是萌妹纸。。嘿嘿。
预祝面试成功。
public List getOldestSisters() {
List ret = new LinkedList<>();
PriorityQueue pq = new PriorityQueue(1, (a, b) -> a.
age - b.age);
Set visitedParents = new HashSet<>();
Queue queue = new LinkedList<>();
if (father != null) queue.offer(father);
if (mother != null) queue.offer(mother);
while (!queue.isEmpty()) {
Person p = queue.poll();
visitedParents.add(p);
if (p.children != null) {
for (Person kid : p.children) {
if (kid.father != null && !visitedParents.contains(kid.
father)) queue.offer(kid.father);
if (kid.mother != null && !visitedParents.contains(kid.
mother)) queue.offer(kid.mother);
if (kid != this && kid.gender == Gender.Female) {
if (kid.age != null) {
if (pq.isEmpty()) pq.add(kid);
else {
while (!pq.isEmpty() && pq.peek().age < kid.
age) pq.poll();
pq.offer(kid);
}
}
}
}
}
}
while (!pq.isEmpty()) {
ret.add(pq.poll());
}
return ret;
}
S********t
发帖数: 3431
4
你这是当伦理题做呢

【在 o*******r 的大作中提到】
: 同是java小白,简单写了一下,供参考。希望楼主是萌妹纸。。嘿嘿。
: 预祝面试成功。
: public List getOldestSisters() {
: List ret = new LinkedList<>();
: PriorityQueue pq = new PriorityQueue(1, (a, b) -> a.
: age - b.age);
: Set visitedParents = new HashSet<>();
: Queue queue = new LinkedList<>();
: if (father != null) queue.offer(father);
: if (mother != null) queue.offer(mother);

b**********f
发帖数: 136
5
大侠请赐教,真的很着急。
几乎知道此题必考。
工作中不需要写java code,实在是做不出来。
b**********f
发帖数: 136
6
大侠请赐教,真的很着急。
几乎知道此题必考。
工作中不需要写java code,实在是做不出来。
b**********f
发帖数: 136
7
大侠请赐教,真的很着急。
几乎知道此题必考。
工作中不需要写java code,实在是做不出来。
w*****w
发帖数: 53
8
是女生吗?是女生的话,给我看看Linkedin,我当面手把手给你写。
j*r
发帖数: 23
9
public class Person {
Person father;
Person mother;
Gender gender;
Integer age;
List children;
int level = 0;
public enum Gender {
Male,
Female;
}
}
public List getOldestSisters() {
Person parent = father;
if (parent == null) {
parent = mother;
}

if (parent == null) {
return null;
}

Person oldestSister = null;

List siblings = parent.children;

if (siblings != null) {
for(Person sibling: siblings) {
if (sibling.gender == Female) {
if (oldSister == null || sibling.age > oldestSister.age)
{
oldSister = sibling;
}
}
}
}
return oldestSister;
}

【在 b**********f 的大作中提到】
: 大侠请赐教,真的很着急。
: 几乎知道此题必考。
: 工作中不需要写java code,实在是做不出来。

p*********g
发帖数: 2998
10
直接做查询的真是傻,
要我就直接加一个参数MaxHeap<>sister()
然后方法里直接
return heap.DeleteMax();
直接完事

【在 j*r 的大作中提到】
: public class Person {
: Person father;
: Person mother;
: Gender gender;
: Integer age;
: List children;
: int level = 0;
: public enum Gender {
: Male,
: Female;

1 (共1页)
进入JobHunting版参与讨论
相关主题
求教一道ms的题目[INTERVIEW] Amazon, ITG, YAHOO 电面, 求分析
"简单的"linklist的问题Facebook 面经
一个stack怎么sort这题到底什么意思?
两种DP面经
careercup书上那个maintain median value的题一个Linkedlist面试题的教训
请教一道题 median ii问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5
算法题问了一个链表,1->2->3->4->5, 每两个交换,2->1->4->3->5,
发个evernote的code challengeA家面经 (转载)
相关话题的讨论汇总
话题: person话题: list话题: null话题: gender话题: public