## Facebook Interview Questions

- 0of 0 votes
Make 100 HTTP GET requests to http://en.wikipedia.org/wiki/Main_Page and print the following statistics for the response time to stdout:

• 10th, 50th, 90th, 95th, 99th Percentile

• Mean

• Standard Deviation

Your solution must be parallel. You must make at least N (say 10, but should be configurable). Use ExecutorService in Java for making the requests at a time.

Explain design choices, known limitations and edge cases.

What challenges did you face? How would you improve the code if you had more time?

- 0of 0 votes
Give you an unsorted integer iterator

and a percentage that is expressed in double (for example, 0.4 for 40%),

and find the number of the sorted array at the percentage position.

Example: Enter [1 3 2 5 4 6 7 9 8 10], and 0.6, you will return 6

public int findNumber(Iterator<Integer> nums, double percent){

}

- 0of 0 votes
can you use union find to Detect Cycle in a Directed Graph? why or why not

- 0of 0 votes
how to design github

- 0of 0 votes
Return the most popular 10 words in the past 24 hours for twitter

Follow up in order to reduce the size of each log, do not write timestamp, how to get the same answer,

- 2of 2 votes
Find out if the given string forms a valid lottery number.

- A valid lottery number contains 7 unique digits between 1 and 59.

e.g.

4938532894754 (yes) -> 49 38 53 28 9 47 54

1634616512 (yes) -> 1 6 34 6 16 51 2

1122334 (no)

- 0of 0 votes
Given a Calendar class (there are three fields, year, month, day) and a number of N,

Implement a function that returns the calendar after N days,

For example, if the input is {2017, 3,20} and 12, then the return is {2017,4, 1}

- 0of 0 votes
implement a Fibonacci iterator

- 0of 0 votes
Now we have one server, one database, what if response time is slow?

How to optimize?

- 0of 0 votes
Given an integer n, count the total number of digit 3 appearing in all non-negative integers less than or equal to n.

(E.x: given 30, return 4 {3,13, 23, 30})

- 0of 0 votes
prime factors. given a number return the prime factor multiplication.

eg. 90 = 2 * 3 * 3 * 5.

- 0of 0 votes
Remove any number containing 9 like 9, 19, 29, ... 91, 92, ... 99, 109...

Write a function that returns the nth number. E.g. newNumber(1) = 1

newNumber(8) = 8, newNumber(9) = 10

- 0of 0 votes
Given a n*m size 2D array with integers from 1 to n*m - 1 in it.

Integers are not sorted. The last position of the matrix stays a movable block.

For each time, you can swap the movable block with any adjacent number.

And eventually you will have the integers sorted and the movable block returned

to its starting position. Think about an approach to print the path.

(You can assume it always have at least a solution)

- 0of 0 votes
How to get the repeating decimal pattern of a division? (e.g 1/3, 1/6)

- 0of 0 votes
Given a preorder traversal of a BST, print out the inorder transversal of the BST

public void printInorder(int[] nums){}

- 0of 0 votes
Implement circular buffer with read & write functions

- 0of 0 votes
Coding III

Implement int divide(int a, int b) without division or mod operation.

## Round IV

Behavioral Questions + Project Walk Through + Coding (Validate BST)

## System Design V

Design memcache to enable read, write and delete (single server, non-distributed infrastructure).

Which data structure to go with?

Eviction rules?

How to minimize segmentation?

How to handle concurrency?

## Extra

After two weeks they called me to an extra round of system design.

How to store social graphs?

How to handle concurrent read/write requests(read heavy) on one server.

- 0of 0 votes
Coding I

Flatten a linked list.

Each node in the list carries a piece of data and a pointer. The data could be in a normal data type such as an integer, or a pointer that points to another list node.

The interviewer gave no specification on how the list node class was defined. You may look at each list node as if it has two pointers - one of them points to the next node; the other points to the ‘data’ which could be either a node or an integer. There also needs to be a function to tell you about the node data is actual data or a pointer.

I solved the problem with recursion. During the process, any nodes that don’t carry an integer get removed.

- 0of 0 votes
Find Famous person in the list of persons.

A person is a famous person if he doesn't know anyone in the list and everyone else in the list should know this person.

The function isKnow(i,j) => true/ false is given to us. No need to worry about it.

Goal is to find the famous person in O(n) complexity.

- 0of 0 votes
/* Find all subsets of size k in an array that sum up to target

the array may contains negative number */

class Solution {

public List<List<Integer>> combinationSum(int[] nums, int target, int k) {

}

- 0of 0 votes
A bot is an id that visit the site m times in the last n seconds,

given a list of logs with id and time sorted by time, return all the bots's id`class Log{ String id; int time; } public HashSet<String> getBots(Log[] logs, int m, int n){ }`

- 0of 0 votes
download all urls from 1000 hosts. Imagine all the urls are graph.

Requirement: Each host has bad internet connection among each other, Has to download url exacly once.

- 2of 2 votes
FB on-site two weeks ago last round of coding . (This problem is also in the internal question bank of G.)

There is a robot in a room. The initial location of the robot is unknown. The shape or area of the room is unknown.

You have a remote that could walk the robot into any of the four directions - up, left, down or right.

Here is the move method: boolean move(int direction), direction: 0, 1, 2, 3. If the robot hits the wall, the method returns false.

Otherwise returns true and the robot moves on to the direction given.

Find out the area of the room.

e.g.

X

XXX X

XXXXX 'X' marks the floor plan of the room.

A room like such has an area of 10.

- 0of 0 votes
Give you a robot and a room where you do not know where the robot is in the room and you do not know the size of the room, you have a remote control that allows the robot to walk around four directions. Here you give a move method: boolean move (int direction), direction: 0,1,2,3 that four directions. If it can move in that direction, return true, and if it cannot move in that direction, return false. Ask you determine how big this room is. the shape of the room can be any shape, so you cannot assume it is rectangle or square.

- 0of 0 votes
Given a 2D character array of size NxN. Find if there is a path from the cell 'R' to the cell 'T'. You can go left, right, up, down from a cell and you cannot pass through any cell marked with 'X'.

Example input:

X__R_X

X_XXX_

______

_XX_XX

XT__X_

Output: true

- 0of 0 votes
Print all permutations of a given string.

- 0of 0 votes
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].

You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You can begin the journey with an empty tank at one of the gas stations.

Return ALL the starting gas station's index where you can travel around the circuit once

public List<Integer> canCompleteCircuit(int[] gas, int[] cost) {

}

- 1of 1 vote
You have a array with integers:

`[ 1, -2, 0, 6, 2, -4, 6, 6 ]`

You need to write a function which will evenly return indexes of a max value in the array.

In the example below max value is 6, and its positions are 3, 6 and 7. So each run function should return random index from the set.

Try to implement with O(n) for computation and memory.

Try to reduce memory complexity to O(1).

- 0of 0 votes
You have a binary tree which consists of 0 or 1 in the way, that each node value is a LOGICAL AND between its children:

`0 / \ 0 1 / \ / \ 0 1 1 1`

You need to write a code, which will invert given LEAF and put tree in a correct state.

- 0of 0 votes
Given n1, n2 is the number after removing one digit from n1. Example, n1 = 123, then n2 can be 12, 13 or 23.

If we know the sum of n1 + n2, and find the possible values of n1 and n2.

public List<List<Integer>> getNumber(int sum){

}