注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
写好的内容全部丢失,只好再写一遍了。
替朋友发apple的面经(1/15/2019):
Interview started at 9:00AM.
1) How would you solve cleaning robot problem?
given:
- interface RobotMap {
- Tuple(x,y) getOriginXY()
- boolean isObfuscated(x,y)
- }
- clean(RobotMap robotMap) {
- // define
- }
复制代码
My answer:
Since the interviewer was so vague, I have to ask a lot of clarifying questions. I also defined the following function inside RobotMap
move(x,y)
I see this as a Graph problem, so my solution, was to use DFS:
- clean(RobotMap, robotMap) {
- Set<Tuple> visited = new HashSet<>();
- return dfs(robotMap, visited, robot.getOrigin());
- }
- void dfs(RobotMap robotMap, Set<Tuple> visited, Tuple location) {
- if(!visited.contains(location) {
- // has not visited this location
- visited.add(location)
- if(!robotMap.isObfuscated(location.x, location.y) {
- dfs(robotMap, visited, new Tuple(x + 1, y);
- dfs(robotMap, visited, new Tuple(x - 1, y);
- dfs(robotMap, visited, new Tuple(x , y + 1);
- dfs(robotMap, visited, new Tuple(x , y - 1);
- }
- robotMap.move(x,y)
- }
- }
复制代码
He asked me, what happened if the robot goes to an dead end hall way?
e.g.
--------------------------------------------------
* |
--------------------------------------------------
So I thought of adding a data structure, to implement a backtracking solution. But I never had the chance to implement it, because he cut me of for another interviewer. It was hard to read that dude's face, so I'm not sure if he was impressed with my solution or not.
2) In JAVA, Given a class definition, tell me what's wrong with it?
- class A {
- A() {
- foo();
- }
-
- foo() {
- }
- }
- class B extend A {
- B() {
- // some code here
- }
- @Override
- foo() {
- }
- }
复制代码
I tonology. I love to code and build stuff).
6) Design a twitter. This took a lot of time and I was not sure if he was happy with my answer.
I started with database design
then I added a REST API on top of it. With Cache (Redis), Elastic search (for search), Kafka.
All the cool stuff that I can think of. :D
7) The last interview question was kinda weird. He wants me to create a merge function given the squares. (I'm not sure if this is a GUI or algorithm question)
see attached file. (没有权限上传)
at first I designed the square.
- Square {
- boolean isShaded;
- Square topRight;
- Square topLeft;
- Square bottomRight;
- Square bottomLeft;
- Square( topRight, topLeft, bottomRight, bottomLeft) <-- constructor
- boolean isPlain() {
- return topRight == null && topLeft == null && bottomRight == null && bottomLeft == null;
- }
- }
- Square merge(Square sq1, Square sq2) {
- if(sq1.isPlain() && sq2.isPlain() ) {
- if(sq1.isShaded() ) {
- return sq1;
- } else {
- return sq2;
- }
- // more conditions here
- }
- // recursive call
- Square topRight = merge(sq1.topRight, sq2.topRight)
- Square topLeft = merge(sq1.topLeft, sq2.topLeft)
- Square bottomRight = merge(sq1.bottomRight, sq2.bottomRight)
- Square bottomLeft = merge(sq1.bottomLeft, sq2bottomLeft)
- return new Square(topRight, toLeft, bottomRight, bottomLeft)
- }
复制代码
At the end I was exhausted, and I cannot even think well. It was a great experience overall, but I think it will help if you do a lot of practice. If you can simulate the situation. Let say, you have 7 friends to interview you for 1 day, that will definitely help a lot.
|