## Facebook Interview Questions

- 0of 0 votes
Given 2 strings representing very large numbers (these are not representable as a BigInteger or other various type) write a method for adding the two numbers and returning their sum.

- 0of 0 votes
word look up

- 1of 1 vote
I was asked to design a system on a whiteboard which simulate a executor.

This system has a method that is being triggered every second. I need to add logic to the method (i.e. run jobs).

There is also a method called job_arrived() that is called when a new job arrives.. I need to implement it as well.

I needed to implement a system which tries to run each job right when it is arrived (it has a return value that gets a success status from a black box service). if the job ran successfully that's the end of it..

if not I need to re-run it after 2 seconds (and if that fails as well - there will be no re-runs).

of course - more than one job can be accepted each second.

I was asked to describes the system (describe the classes and method) and consider the system to be large scale one (meaning.. threading is in order here..).

The answer I gave was apparently not multi threaded enough..

any idea to what I should have done?

Thanks guys

- 4of 4 votes
Congrats on aonecode member A.P. for signing the offer with FB! Thanks for sharing the experience with us.

phone:

postorder tree traversal recursive -> iterative

add two binary number

on-site:

1 ring buffer

2 merge intervals

3 Leetcode alien dictionary

4.sort list of words

- 0of 0 votes
Given a number, rearrange the digits of that number to make a higher number, among all such permutations that are greater,one of them is the smallest, Find the smallest greater permutation (the next Permutation).

Examples:

next_permutation (12) = 21

next_permutation (315) = 351

next_permutation (583) = 835

next_permutation (12389) = 12398

next_permutation (34722641) = 34724126

- -2of 2 votes
If b == “1”:

quit()

- 0of 0 votes
Given a binary tree, where each node represents an integer, find the max value of path sum.

- 5of 5 votes
FB On-site March

Q: Find number of Islands.

XXXOO

OOOXX

XXOOX

Return 3 islands.

1 1 1OO

OOO2 2

3 3OO 2

Followup: If the board is too big to fit in memory, how to get the number?

- 1of 1 vote
Interleave list of lists in Java

Example:

input = [[1,2,3], [9, 0], [5], [-4,-5,-2,-3,-1]];

output = [1,9,5,-4,2,0,-5,3,-2,-3,-1]

- 0of 0 votes
Given an array of n elements return true if 3 of the sum of 3 elements is equal to a constant c

Example array a[6,2,3,4] constant c = 9

if a[1] + [2] + [3] == c return true

The size of the array is n

If any set of 3 elements is equal to the constant c, then return false

- 2of 2 votes
Given a string with alpha-numeric characters and parentheses, return a string with balanced parentheses by removing the fewest characters possible. You cannot add anything to the string.

- 2of 2 votes
Given a collection of two dimensional points and a number k, return the k closest points to (0,0) by Euclidean distance.

- -2of 2 votes
How do I report a problem with Facebook?Facebook Advertising Help, Tips & Support | Facebook for Business provide facebook help center number ?

- 1of 1 vote
Given a string as input, return the list of all the patterns possible:

`'1' : ['A', 'B', 'C'], '2' : ['D', 'E'], '12' : ['X'] '3' : ['P', 'Q']`

Example if input is '123', then output should be [ADP, ADQ, AEP, AEQ, BDP, BDQ, BEP, BEQ, CDP, CDQ, CEP, CEQ, XP, XQ]

- 1of 1 vote
Move[inplace] the non zero elements at the one end(end of array) and return the numbers of non zero elements in output array

Solution : https://www.geeksforgeeks.org/move-zeroes-end-array/

- 0of 0 votes
what is UI/Main Thread in android.

when you can use Thread over Service

- -1of 1 vote
Question 2: Given a number 'k', return the corresponding row, given the pattern:

k => output

0 => []

1 => ["0", "1", "8"]

2 => ["00", "11", "69", "96", "88"]

3 => ["000", "111", "101", "888", ...] // and so on ...

- 0of 0 votes
Question 1: Given an input of an array of string, verify if, turned 180 degrees, it is the "same".

For instance:

[1, 6, 0, 9, 1] => return true

[1, 7, 1] => return false

- 2of 2 votes
March 2018 Phone Interview FB

Calculate a moving average that considers the last N values.

Circular Queue (Interviewer didn't agree with the linked list queue that I suggested at first. Said the pointers took space)

- 0of 0 votes
Why facebook?

What was the biggest technical problem that you solved?

Do you have any apps on google play?

Give me a scenario where the requirements were ambiguous, what did you do?

- 0of 0 votes
Design Instagram like app end to end

- 0of 0 votes
Given a string "L*&EVe)))l", write a method which will determine if the input is a palindrome. Ignore all special characters. Uppercase/lowercase should be considered as same.

- 0of 0 votes
Imagine a room full of people, with only 1 celebrity in the room. Celebrity is defined as a person who does not know anyone, but everyone knows him/her. Write a method who will take array of people and a person as input and return boolean if the person is a celebrity or not.

- 0of 0 votes
Given two input arrays, return true if the words array is sorted according to the ordering array

Input:

words = ['cc', 'cb', 'bb', 'ac']

ordering = ['c', 'b', 'a']

Output: True

Input:

words = ['cc', 'cb', 'bb', 'ac']

ordering = ['b', 'c', 'a']

Output: False

- 2of 2 votes
Give the following input, output if the array is sorted according to the ordering array given. Return true or false.

Input:

words = ['cc', 'cb', 'bb', 'ac']

ordering = ['c', 'b', 'a']

Output: True

Input:

words = ['cc', 'cb', 'bb', 'ac']

[bb cb cc ac]

ordering = ['b', 'c', 'a']

Output: False

- -1of 1 vote
Define a class 'Space' which has a member string variable that indicates if the space is a "tree", a "house" or an empty space and another member variable that will store the 'space neighbors' (left, right, up and down only)

Given a 'Grid' (list) of Spaces write the code for the findAll(start) method to find all the trees and houses given a 'Space' as start point

Example, Grid of 'Spaces':

T 0 0 H 0

0 0 0 0 0

H H T H 0

Where Ts are trees and Hs are houses

- 0of 0 votes
"""

Given a 2d array of 0s and 1s, 0 means water,

1 means land, connected 1s form an island,

count the number of islands on this map.

01010

01001

01101

returns 3

"""

- 0of 0 votes
# Given a dictionary, find all pairs of words that,

# when concatenated together, form a palindrome.

# ‘none', 'xenon': 'nonexenon' is a palindrome

# 'none', 'xexenon': 'nonexexenon' is a palindrome

- 2of 2 votes
How would you work with a backend engineer to design a news feed on mobile. Imagine that we only care about showing the user feed and posting a picture.

Follow-ups

1. what kind of apis would you want him to expose and what would they look like

2. How would you refresh the news feed on the iOS app and how often?

3. How would you cache the data/images. What size cache would you have?

- 1of 1 vote
Given an aray with ['a1', 'a2', .....'aN', 'b1', 'b2', ....'bN', 'c1', 'c2', .....'cN'],

stagger the subarrays so it becomes ['a1', 'b1', 'c1', 'a2', 'b2', 'c2', ...'aN', 'bN', 'cN']. The optimal solution requires linear-time

sorting and a constant space complexity.