amazon OA
- Item association:
ITEM ASSOCIATION。
input
[itemA, itemB],表示物品A和物品B相互关联。
[itemB, itemC],表示物品B和物品C相互关联。
如果物品相互关联,就组成一个组。最后要求找出物品最多的那个组。
遇到了一道没有做过的题,用了union find现做出来的:(场景叙述做了处理)
给出一串Pair,每个pair说明两个人互为朋友,[A,B]说明A和B是朋友,[C,B]说明C和B是朋
友,{D,E}说明E和D是朋友。
找出人数最大的朋友圈,如果两个朋友圈人数相等,返回有着字典顺序最小朋友的那个圈。
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=282891&extra=page%3D1 %26filter%3Dsortid%26sortid%3D311%26searchoption%5B3089%5D%5Bvalue%5D%5B5%5 D%3D5%26searchoption%5B3089%5D%5Btype%5D%3Dcheckbox%26searchoption%5B3046 %5D%5Bvalue%5D%3D5%26searchoption%5B3046%5D%5Btype%5D%3Dradio%26sortid% 3D311
类似movie,改成了books,关系更简单, 【book1,book2】. visit1point3acres.comfor more.
【book3,book4】
【book5,book6】
. Waral鍗氬鏈夋洿澶氭枃绔�,找出最大的network是什么
2.
菜单具体可以看之前这位楼主的帖子,写的很详细。
http://www.1point3acres.com/bbs/ ... adio%26sortid%3D311.涓€浜�-涓夊垎-鍦帮紝鐙鍙戝竷
3.(有代码和解释)
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=276519&extra=page%3D1%26filter%3Dsortid %5D%5Btype%5D%3Dradio%26sortid%3D311
结果第二题,distance between two nodes in a bst.
我自己上机器跑的没问题,OA上case只能跑一个。我都懒得吐槽了。
第一个case正常情况,总返回-1。
给一个数组A[5,6,3,1,2,4],先建立BST,然后搜索两个node之间的距离。
已知第一个元素5是root,剩下的是无序的!!注意后面有可能是右子树先出现(6,对应root-5),
也有可能是左子树先出现(1,2,对应root-3)!
如果有node不存在的话,返回-1;
要求实现的函数长这样:int distance(int* values, int n,int node1, int node2)
注:题目中没说,但是好像数组里应该没有重复元素。
2个给好的tests,9个隐藏的。
Recursion建树,while loop找距离,test都过了,其他方法不清楚会不会有TLE。
%
先建一个BST,然后找 其中两点的距离。
4: leetcode原题: balanced parenthesis判断括号是否成对出现;;
5.
. more info on1point3acres.comhttp://www.1point3acres.com/bbs/thread-207511-1-1.html
6
7Counting Anagrams LC438
given 2 strings A and B, find the number of anagram occurrances of B in A,output the number, following by the start index of each anagram occurrance.For example:. From 1point 3acres bbs
abdcefgicdba adca
Output:
08
- 第二题是在Movie network里寻找N个分数最高的Movie,
刚刚收到onsite,发面经攒一下人品,希望onsite能够顺利。http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=244701&extra=page%3D2%26filter%3Dsortid%26 3D311
第二题是给你CEO还有各个部门的经理人从属关系。让你找两个人的最近的公共管理人。其实就是
K叉树LCA。
提前准备一下吧~
, Maze。
Maze这道题是从0,0点找到出口位置所用的最短步数。我也是用BFS做的,
因为感觉找最短路径这个应该是比较好的办法了。
可惜不知道为啥还有一个case没过,知道的朋友可以留言给我,我很好奇哈哈~
第二题是给一个movie,每个movie有id,rating和一个list of neighbors,
让你从这个movie开始,找到similar的top k rating movie,不包括这个movie。
用bfs遍历这个图,然后再用一个minHeap,每次分两种情况,如果minHeap.size()== k,
那就看是不是比peek的rating大,如果大就扔出来一个把这个新的放进去。如果minHeap.size() < k
,就放进去。最后结果就在minHeap里面。
参考帖子:
http://www.1point3acres.com/bbs/thread-225078-1-1.html
. from:1point3acres.com/bbs
.鐗涗汉浜戦泦,涓€浜╀笁
给一部电影,要求返回跟这部电影相关的,排名最高的N部电影,其中不包括输入的那部电影!!
输出不需要排序。如果不够N部,就有多少输出多少部。
电影长这样:
class Movie {
private:
int id;; float rate;; vector<Movie*> similarMovies;;
public:
int getID();;
float getRate();;
鍒
vector<Movie*>& getSimilar();;
}
假设有个Movie类,public class Movie
{
int movieId;;.
float rating;;
List<Movie> similarMovies
还有其他的getters.
}
现在要求找到k个和movie最相似 的movies。
函数的signature大概是这样的:
public static List<Movie> getNearest(Movie movie, int numSimilar)。
举个栗子:
m0 <-->m1, similarity 2 mo <--> m2, similarity 3 m1 <--> m3, similarity 4 m2 <--> m5, similaity 5
如果要返回和mo最相似的movie,那么应该返回m5 (只有有一条路径从m1到m5,并且5是最大的); 如果返回3个最相似的就返回m2, m3,m5(顺序不重要); 如果需要返回10个,但是相似的只有9个, 那么就返回9个。
source movie本身不能在返回结果里面。
可以的一个做法是dfs + min-Heap(PriorityQueue), 我们一直做dfs, 每次碰到一个新的movie,如果现在queue的size比k小的话, 踢出队列,加上这个新的。
- baseball
- Given a string array representing a throw ball blocks, each string is either a number, +, Z, X. Calculate total. If number, just add to total. If +, add last 2 scores to total.
If Z, remove last score from total. If X, double last score and add to toal.
Use 0 for any missing last score.有些corner cases要考虑。
- Given a string array representing a throw ball blocks, each string is either a number, +, Z, X. Calculate total. If number, just add to total. If +, add last 2 scores to total.
.鏈枃鍘熷垱鑷�1point3acres璁哄潧
. visit1point3acres.comfor more.
.charAt(0) == 'x'来处理的;然后string转int调用了Integer题目我看了半天,stack的操作应该是z直接pop;
x先pop,然后再将double的值放进去;
+是先pop出来两个值,加给score后,在按原样放回去,并把他俩的和也放进去。
我贴的link上有一个例子,大家可以过一下,我写的很是头疼。
要求实现的函数长这样:
vector<Movie*> find(Movie& movie, int N)
2个给好的tests,10个隐藏的。
BFS搜索所有电影,max heap挑选结果,这样做test可以都过,不清楚其他方法会不会有TLE。
打棒球得分,给了一个String[] input,求最终score
如果是integer, 就加给score(有负值)
如果是“x”,将上一个值double,加给score; 若没有上一个值,上一个值按0计算
如果是“z”,上一个成绩作废,score剪掉上一值
如果是“+”,将上两个值相加,然后加给score
我的解法是用一个stack挨个处理。
麻烦的是,input是个string[];;每一个我都是用string
直
.
10
第一题,amazon warehouse。。。其实就是给你x,y然后算x,y到原点的距离,输出最小的几个,java应该priorityqueue就够了,我用的python,也还可以。
11
第二题,golf event要砍树。。。每次只能砍所有树里面最矮的那颗。其实就是maze题的变形。2D-array. 0不能1可以走,>1就是树,要求的输出就是从原点开始,走到每颗当前树里面最矮的那颗所需的步数+需要砍得树的 的总和。方法我就是先找好所有的树,排好序,然后从一个点到另一个点做BFS。 找出最小步数。
举个例子[[1,1,0,2],[3,1,1,1]],从(0,0)走到 (0,3)--》2这棵树,就是5步+2(树高),然后从(0,3) 走到 (1,0)->3这棵树4步+3(树高)所以5+2+4+3返回14
Microsoft Word - 社招 OA.docx
- Item association:
ITEM ASSOCIATION
input
[itemA, itemB],AB[itemB, itemC],BC
44 union find:()
Pair,4pair4C[A,B] [C,B]
C4C4
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=282891&extra=page%3D1 %26filter%3Dsortid%26sortid%3D311%26searchoption%5B3089%5D%5Bvalue%5D%5B5%5 D%3D5%26searchoption%5B3089%5D%5Btype%5D%3Dcheckbox%26searchoption%5B3046 %5D%5Bvalue%5D%3D5%26searchoption%5B3046%5D%5Btype%5D%3Dradio%26sortid% 3D311
moviebooks book1book2. visit1point3acres.comfor more.
book3book4
book5book6. Waral,networkD
2.
http://www.1point3acres.com/bbs/ ... adio%26sortid%3D311Update: http://www.1point3acres.com/bbs/thread-280797-1-1.html€--
3.()http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=276519&extra=pa
ge%3D1%26filter%3Dsortid %5D%5Btype%5D%3Dradio%26sortid%3D311
distance between two nodes in a bst.OAcase4 4case-1
4A[563124]BST4node 45root!!(6
root-5)
(12root-3)!
node-1;
:int distance(int* values, int nint node1, int node2):
24tests94
Recursionwhile looptestTLE%
4BST,
z
BB.56tr][V
BLGL;CBB;BBCLBB= B=
oB.56v3NDD-= =3-.56ABB
=3-=3-+
yACGp3-p 64=B=B=+3-12BA v=sT
1BCBLBHLBLA;B;B=
NBAL;CBAB=LA=B;NN=
GL;CBBB;BBCLBB=B=
DGC
CL,)(BABCL=B=B(A
LBL
.56( )
(
: leetcode: balanced parenthesis5.
. more info onhttp://www.1point3acres.com/bbs/thread-207511-1-1.html
6
Counting Anagrams LC438given 2 strings A and B, find the number of anagram occurrances of B in A, output the number, following by the start index of each anagram occurrance. For example:. From 1point 3acres bbsabdcefgicdba adcaOutput:08
8.Movie networkN4Movie
onsiteConsitehttp://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=244701&extra=page%3D2 %26filter%3Dsortid%26 3D311
CEO4CE4C C
K}LCA
~
, Maze
MazeE0,0BFS 4
4case~
4movie4movieidrating4list of neighbors
E4moviesimilartop k rating movie4movie
bfs44minHeapminHeap.size()== k
peekrating44{minHeap.size() < k
{minHeap
:http://www.1point3acres.com/bbs/thread-225078-1-1.html
. from:1point3acres.com/bbs.,€S
N !!
N :
class Movie {
private:
int id float rate vector<Movie*> similarMovies public:
int getID()
float getRate()
vector<Movie*>& getSimilar()
}
4Moviepublic class Movie{
int movieId .float ratingList<Movie> similarMovies
getters.}k4movie movies
signature:public static List<Movie> getNearest(Movie movie, int
numSimilar)
4:m0 <-->m1, similarity 2 mo <--> m2, similarity 3 m1 <--> m3, similarity 4
m2 <--> m5, similaity 5
momovie,m5 (Em1m5,5);34m2, m3m5();10494 94source movie
4dfs + min-Heap(PriorityQueue) dfs 4 moviequeuesizek 4
- baseball1. Given a string array representing a throw ball blocks, each string is either a number, +, Z, X. Calculate total. If number, just add to total. If +, add last 2 scores to total.If Z, remove last score from total. If X, double last score and add to toal.Use 0 for any missing last score.Bcorner cases
.1point3acres. visit1point3acres.comfor more.
.charAt(0) == 'x';stringintIntegerstackzpop;
xpopdouble{;+pop4score {{
link4 :
vector<Movie*> find(Movie& movie, int N) 24tests104
BFSmax heaptest TLE
4String[] inputscore
integer score()
“x”,4doublescore;440 “z”,4score “+”4score
4stack4
input4string[]4string
.
10
amazon warehousex,yx,y
4javapriorityqueuepython11 Version1:
udnAOA,[T
1.
public static int checkWinner (List<List<String>> codeList, List<String> shoppingCart) {}4codeList fashoppingCart targetcodelistshoppingCartxT codelist]itemwccshoppingcartitem 1T zcodelist]titem"anything" hixT
Ex1:
codelist:
[
[apple, apple],
[orange, banana, orange]
]
shoppingCart: [orange, apple, apple, orange, banana, orange]
return 1,codelistshoppingcartaorangex
Ex2:
codelist:
[
[orange, banana, orange]
[apple, apple]
]
shoppingCart: [orange, apple, apple, orange, banana, orange] return 0,codeListshoppingcartxT
Ex3:
codelist:
[.1point3acres�
[apple, apple],
[orange, banana, orange],
[pear, orange, grape]
]
shoppingCart: [orange, apple, apple, orange, banana, orange, pear, grape]
return 0,codelist[pear, orange, grape]]orangeshoppingcartx T
Ex4:
codeList:
[
[apple, apple],
[orange, anything, orange]
]
shoppingCart:
[orange, apple, apple, orange, mango, orange] return 1T
Version2:
shopping listbasket
4shopping list[[apple, banana], [orange, apple], [anything, orange]].
checkbasketmatch shopping list.match hpianythingih
basket [apple, banana, apple, apple, orange, apple, banana, orange, apple, orange]matchreturn 1
- golfmT
B
public int flatFields (int numRows, int numColumns, List<List<Integer>> fields) {}4fieldsT
TEx1:
[
[1, 3, 0, 2]
[1, 1, 3, 1]
]
V]1ghT0gT c1gTeV ioT 2 < 3o2T Vel 13-> (0, 3) -> (1, 3) -> (1, 2) -> (1, 1) -> (1, 0)h5 hmb[1, 1, 3, 1] vT
Ex2:
[
[1, 0]
[3, 2]
]
V]-1m eV1v0 3 q]32o2Tha
B
golf eventmaze 2D-array. 01>1E + E44BFS
4[[1,1,0,2],[3,1,1,1]],E(00)(03)--25+2() E(03)(10)->34+3()5+2+4+314