## Facebook Interview Questions

- 0of 0 votes
If you are given 2 infinitely large integers in the form of strings, given the length of the string, find the product of the two integers.

- 0of 0 votes
How will you multiply two infinitely large integers.

- 0of 0 votes
Given a list/array of "Assign" trees with integers, operators and variables, return the result of the requested "Result" tree expression.

Example:`"Assign" / \ "x" "+" / \ 2 3 "Assign" / \ "y" "-" / \ 5000 30 "Assign" / \ "z" "*" / \ 50 x "Return" \ "-" / \ z "*" / \ 1 y`

- 1of 1 vote
You are given logs that contain user and page visits for a given day.

u1 -> p4

u3 -> p2

u7 -> p9

...

comeup with efficient data structure that answers these queries

Which page was visited by exactly 100 users in day?

Which page was visited by only one user exactly 15 times in a day?

Which page was visited by u3 more than 20 times in a day?

- 3of 3 votes
Given a sorted array A, find how many subsets of A satisfies MIN(subset) + MAX(subset) < K.

- 0of 0 votes
Convert Json string to Map

public Map jsonToMap(String t) {

}

- 0of 0 votes
What if server is slow, how to solve

What if one server is down

- 0of 0 votes
Given a 2D matrix of 0's and 1's, where the 1's make up a rectangle, find the coordinates of the top-left corner of the rectangle and the rectangle's width and height.

- 1of 1 vote
Array has N integers，range[0...N-1]。Set S[k], 0 <= K < N as S[K] = {A[K], A[A[K]], A[A[A[K]]],....},

write a function returns the size of the largest set S[K] for this array. return 0 if empty.

ex:

A = [5, 4, 0, 3, 1, 6, 2]

return 4 because S[2] equals {0, 5, 6, 2} 4 elements

- 0of 0 votes
Given an array of integers and a target number, determine if an arithmetic expression using these integers can be evaluated to the target number, you are allowed to use '+', '-', '*', '/'. Follow-up: when evaluating the expression, take operand precedence into account,

public boolean getTarget(int[] nums, int target){

}

exponentia is ok

- 1of 1 vote
Given a list of input tasks to run, and the cooldown interval, output the minimum number of time slots required to run them.

// Tasks: 1, 1, 2, 1, 2

// Recovery interval (cooldown): 2

// Output: 8 (order is 1 _ _ 1 2 _ 1 2 )

=========

Tasks are task numbers in that order coming in for execution. Cooling time is time interval required to cool down the machine after executing a task. So it's like if CPU executed task 1 then it needs 2 cooling time intervals before executing another task 1 but meanwhile, it can execute other tasks which are not same as 1 and so on. So before executing any task, you have to check if you have executed same task number before and if yes, then if its cooling time interval is done or not.

The output is basically the number of cycles/time slots CPU took to execute these tasks in that order (including when task executed and cooling intervals).

- 0of 0 votes
find the Closest leaf to a given node in Binary Tree

can you do it in o(n) time

public TreeNode findCloestLeafNode(TreeNode root, TreeNode target){}

no parent pointer

- 0of 0 votes
validate IP in string format and return the uint32 format

‘1.2.3.4’ -> 0x01020304

- 1of 1 vote
Given a n-nery tree and its deep copy, a node in the original tree, return the corresponding node in the copy

public TreeNode getCopyNode(TreeNode root, TreeNode copy, TreeNode node)

- 0of 0 votes
Write the code to find the median of an unsorted array in average linear time.

followup the array is distributed across many machines.

- 0of 0 votes
Write a function to split a SQL query into individual statements.

give you a String which contains a separate Query with a semicolon ";" return all valid queries

Such as

"select name from courseinfo ;; select * from db1 where home = 'usa' ;"

The main thing to consider is that some special cases such as the escape symbol and the quotation marks inside the semicolon

public List<String> getQuery(String queries){

}

- 0of 0 votes
given a list of numbers, put with + - * / any two number, find the maximum value you can get.

int getMaxNumber(int[] nums){

}

- 0of 0 votes
Given a group of movies and their start time, assuming that are 1 hour long,

Returns a movie schedule (no time conflict).

enter:

Movie ("Shining", [14, 15, 16])

Movie ("kill bill", [14, 15])

Movie ("Pulp fiction", [14, 15])

One possible result is shining 16, kill bill 15, pulp fiction 14

public void schedule (HashMap <String, List <Integer >> map) {

}

- 3of 3 votes
3.1 design: design fb inbox search —> just focus on the post

4.1 binary tree to circular double linked list.

4.2 two arrays, find the common elements of two sorted array. if one array is small, the other is very big.

- 2of 2 votes
2.1 career discussion

2.2 divide two numbers with no / or %

- 3of 3 votes
1/4 round of FB on-site interview, Master Degree, Hired

1.1 diameter of tree

1.2 find the point which have the maximum overlap of intervals

- 0of 0 votes
friend circle. Given a streaming pairs representing friend relationship

(1, 2) means 1 and 2 are friends, (1, 3) means 1 and 3 are friends

Return all its friends.

List<Integer> getFriends (Iterator<List<Integer>> relations, int id){

}

- 0of 0 votes
For given list of numbers find out triplets with sum 0

Input : arr[] = {0, -1, 2, -3, 1}

Output : 0 -1 1

2 -3 1

- 0of 0 votes
Given a String and dictionary of words, break the string in minimum space sentence.

Ex:

inputStr = "ilikefacebook"

dictionary = {"i","like","face","book","facebook"}

Possible Strings:

i like face book - 3 spaces

i like Facebook - 2 spaces - this is expected answer.

- 0of 0 votes
given a matrix and a target, return if there is a path who’s sum is == target

Input: matrix, integer output: true or false;

- 0of 0 votes
permute the String including case change

"abc".

For example:

abc

ABC

Abc

aBc

abC

ABc

abC

AbC

- 0of 0 votes
implemnt JSON.stringify()

- 0of 0 votes
Can you achieve the following without using enums? Given the last two lines stay the same.

`enum DayHalf { AM,PM; DayHalf dh1=DayHalf.AM; DayHalf dh2=DayHalf.PM; }`

- 1of 1 vote
given a string of number, you can add a + or * sign between any two numbers, find the maximum value you can get

ex. s = "89" --> 8 * 9 = 72

int maxNumber(String s){}

- 1of 1 vote
Consider an implementation of Strings consisting of an array where the first element of the array indicates the length of the String and the next elements represent the value of the ASCII characters in the String. Implement String concatenation and discuss shortcomings of this operation under this implementation of Strings.