Facebook Interview Questions
- -8of 8 votes
AnswersWhat is the screen dimensions of various iPhone models?
- thinkrightthru February 20, 2014 in India| Report Duplicate | Flag | PURGE
Facebook iOS Developer Graphics - 2of 2 votes
Answers// cat, actor -> T // car, actor -> F bool anaStrStr (string needle, string haystack) { }
Write a function that takes 2 strings , search returns true if any anagram of string1(needle) is present in string2(haystack)
- juny February 19, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersI/P: N, k
- poorna.chandra.akp February 19, 2014 in United States
O/P: all subset of N with exactly K elements.
eg: I/p: N = 5, K =3
O/p:
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
2 3 4
2 3 5
3 4 5| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 2of 4 votes
AnswersIn Java: Write a function in language of your choice that takes in two strings, and returns true if they match. Constraints are as follows: String 1, the text to match to, will be alphabets and digits. String 2, the pattern, will be alphabets, digits, '.' and '*'. '.' means either alphabet or digit will be considered as a "match". "*" means the previous character is repeat 0 or more # of times. For example: Text: Facebook Pattern: F.cebo*k returns true.
- dke.ade February 13, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 4of 4 votes
AnswersPrints all unique subsets of the string.
- mabodx February 11, 2014 in United States
Given a string write a function which prints all the subsets of the string. Now make the function to return only unique solutions.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 0of 0 votes
AnswersGiven the following 3 by 3 grid where the (first row, first column) is represented by (0,0):
- RashnaRazdan February 05, 2014 in United States
0,1 1,2 3,3
1,1 3,3 3,2
3,0 1,3 null
we need to find if we can get to each cell in the table by following the cell locations at the current cell we are at. We can only start at cell (0,0) and follow the cell locations from that cell, to the cell it indicates and keep on doing the same for every cell.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 3 votes
AnswersThere are N objects kept in a row. The ith object is at position x_i. You want to partition them into K groups. You want to move all objects belonging to the same group to the same position. Objects in two different groups may be placed at the same position. What is the minimum total amount by which you need to move the objects to accomplish this?
- saumya.tyagi6 February 01, 2014 in United States
Input:
The first line contains the number of test cases T. T test cases follow. The first line contains N and K. The next line contains N space seperated integers, denoting the original positions x_i of the objects.
Output:
Output T lines, containing the total minimum amount by which the objects should be moved.
Constraints:
1 <= T <= 1000
1 <= K <= N <= 200
0 <= x_i <= 1000
Sample Input:
3
3 3
1 1 3
3 2
1 2 4
4 2
1 2 5 7
Sample Output:
0
1
3
Explanation:
For the first case, there is no need to move any object.
For the second case, group objects 1 and 2 together by moving the first object to position 2.
For the third case, group objects 1 and 2 together by moving the first object to position 2 and group objects 3 and 4 together by moving object 3 to position 7. Thus the answer is 1 + 2 = 3.| Report Duplicate | Flag | PURGE
Facebook SDE-2 Algorithm - 4of 4 votes
AnswersGiven an unordered array of positive integers, create an algorithm that makes sure no group of integers of size bigger than M have the same integers.
- Fred_Castro January 22, 2014 in United States
Input: 2,1,1,1,3,4,4,4,5 M = 2
Output: 2,1,1,3,1,4,4,5,4| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
AnswersSink Zero in Binary Tree. Swap zero value of a node with non-zero value of one of its descendants
- yuanbing January 18, 2014 in United States
so that no node with value zero could be parent of node with non-zero.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 2of 2 votes
AnswersMapping
- Thiago January 13, 2014 in United States
'1' = 'A','B','C'
'2' = 'D','E','F'
...
'9' =
input: 112
output :ouput = [AAD, BBD, CCD, AAE, AAF, BBE, BBF, CCE, CCF]| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGroup Anagrams
- Thiago January 13, 2014 in United States
input = ["star, astr, car, rac, st"]
output = [["star, astr"],["car","rac"],["st"]);| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - -5of 5 votes
AnswerMinimum Spanning Tree using alghoritm prim
- fgfsdgs January 06, 2014 in United States| Report Duplicate | Flag | PURGE
Facebook Java Developer - 2of 2 votes
AnswersYou have two numbers decomposed in binary representation, write a function that sums them and returns the result.
- getmax0 December 16, 2013 in United States
Input: 100011, 100100
Output: 1000111| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Bit Manipulation - 1of 3 votes
AnswersYou have a dictionary which is an array of words and array of strings.
- Grumpy December 11, 2013 in United States
Write two functions
1. Prepare the array of strings to be searched in the dictionary
2. Check if the string contains all valid words or not.| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer JavaScript - 5of 5 votes
AnswersGiven "n", generate all valid parenthesis strings of length "2n".
- anusha136 December 02, 2013 in United States
Example:
Given n=2
Output:
(())
()()| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 9of 11 votes
AnswersGiven a number N, write a program that returns all possible combinations of numbers that add up to N, as lists. (Exclude the N+0=N)
- ootah November 14, 2013 in United States
For example, if N=4 return {{1,1,1,1},{1,1,2},{2,2},{1,3}}| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 6of 6 votes
AnswersWrite a function for retrieving the total number of substring palindromes.
- Andrew November 04, 2013 in United States
For example the input is 'abba' then the possible palindromes= a, b, b, a, bb, abba
So the result is 6.
Updated at 11/11/2013:
After the interview I got know that the O(n^3) solution is not enough to go to the next round. It would have been better to know before starting implementing the solution unnecessarily ...| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 6 votes
AnswersGiven a set of n points (coordinate in 2d plane) within a rectangular space, find out a line (ax+by=c), from which the sum of the perpendicular distances of all the points will be minimum. This can has a general usecase like, in a village there are few house, you have to lay a road, such that sum of all the approach roads from each house will be minimum.
- amukh November 02, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersGiven an array, remove the duplicates and return a unique array keeping the first occurrence of the duplicates and the order.
- kchronis October 29, 2013 in United States for iOS
[@2, @1, @3, @1, @2] --> [@2, @1, @3]| Report Duplicate | Flag | PURGE
Facebook iOS Developer Arrays - 0of 0 votes
AnswersQuestion was on Arithmetic progression
- careeradmirer October 27, 2013 in United States
Example :
Given the AP :- 1 3 7 9 11 13 find the missing value "which would be 5 here".
Conditions :
Get an user for the length of AP sequence and make sure user provides length is above 3.
Get the input in a single line ex:- "1 3 5 7 9 11"
Provide the solution in O(n) or less if you can.| Report Duplicate | Flag | PURGE
Facebook Algorithm - 0of 2 votes
AnswersCheck if a given tree is a valid BST
- tbag October 26, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 0 votes
AnswersThere are n points on a 2D plan, find the k points that are closest to origin ( x=0, y=0)
- k October 17, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Web Developer Algorithm - 7of 7 votes
AnswersGiven a regular expression with characters a-z, ' * ', ' . '
- kevin October 13, 2013 in United States
the task was to find if that string could match another string with characters from: a-z
where ' * ' can delete the character before it, and ' . ' could match whatever character. ' * ' always appear after a a-z character.
Example:
isMatch("a*", "") = true;
isMatch(".", "") = false;
isMatch("ab*", "a") = true;
isMatch("a.", "ab") = true;
isMatch("a", "a") = true;| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 1of 3 votes
AnswersInput - List<String> ["star", "rats", "ice", "cie", "arts"]
print all anagrams in buckets:
["star", "rats", "arts"]
["ice", "cie"]
The signature of unimplemented method is given:public void anagramBuckets(List<String> input);
I was given this question during phone interview.
- sunnyhust2005 October 12, 2013 in United States for Facebook Android| Report Duplicate | Flag | PURGE
Facebook Applications Developer Algorithm - -2of 8 votes
AnswersAs we know facebook always asks questions from graph theory he asked me this problem to code-
- Rahul Sharma October 12, 2013 in India
there is a grid of n*n where each cell represent an Island or and some of these are very dangerous so u have to avoid these during path selections.You can move up,down,left ,right.You are given your starting position ,positions of dangerous Islands and position some specific Islands.Your task is to deliver a message to all the specific Islands in minimum number of moves to all specific Islands(NOTE- there are also chances that no moves are possible to cover all specific Island ,in such case you have to tell "NOT POSSIBLE TO DELIVER ALL ",otherwise output minimum moves).| Report Duplicate | Flag | PURGE
Facebook SDE-2 Algorithm - 0of 2 votes
AnswersWrite code to print all different paths in an undirected graph from a given source to destination with no loop(any node can be at most once in a path ).
- Rahul Sharma October 11, 2013 in India| Report Duplicate | Flag | PURGE
Facebook SDE-2 - 0of 4 votes
AnswersGiven a undirected graph, source and destination, write the code to find the total number of distinct nodes visited, considering all possible paths.
- Rahul Sharma October 09, 2013 in India| Report Duplicate | Flag | PURGE
Facebook SDE-2 Algorithm - 1of 1 vote
Answers// merge sorted arrays 'a' and 'b', each with 'length' elements,
- mikeldi10 October 07, 2013 in Spain
// in-place into 'b' to form a sorted result. assume that 'b'
// has 2*length allocated space.
// e.g. a = [1, 3, 5], b = [2, 4, 6] => b = [1, 2, 3, 4, 5, 6]
//how to do it without rearanging the b array| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
Answersboolean isBST(const Node* node) {
- mikeldi10 October 07, 2013 in Spain
// return true iff the tree with root 'node' is a binary search tree.
// 'node' is guaranteed to be a binary tree.
}
n
/ \
a b
\
c| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 5of 5 votes
AnswersInitially there is a number n written on board. Two players start playing a game turn by turn. Each player has to replace the number n written on the board by n-2^k (for some k >= 0 such that 2^k < n)?
- ACP Pradyuman October 03, 2013 in United States
Also the number n-2^k has to be as beautiful as n (The beauty of a number depends on the number of one's in its binary representation). The player loses the game when he can't select any such k.
Given the initial number n, determine which player will win the game if both players play optimally. n > 0 and n <= 10^9.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Bit Manipulation