Facebook Interview Questions
- -1of 3 votes
AnswersGiven a string Sting="ABCSC" Check whether it contains a Substring="ABC"?
- Anonymous September 29, 2013 in India
1)If no , return "-1".
2)If yes , remove the substring from string and return "SC".
use very simple code and concept(ALGORITHM)..| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer - 0of 0 votes
AnswersGiven an array of randomly sorted integers and an integer k, write a function which returns boolean True if a pair of numbers exists in the array such that A[i] + A[j] = k and False otherwise. Provide an O(N) and an O(N log N) solution.
- djlewis September 25, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 4of 4 votes
AnswersWe are given a set of integers with repeated occurences of elements. For Example, S={1,2,2}.
- sc.shobhit September 14, 2013 in India
We need to print the power set of S ensuring that the repeated elements of the power set are printed only once.
For the above S, the power set will be {NULL, {1}, {2}, {2}, {1,2}, {1,2}, {2,2}, {1,2,2}}. So, as per the question requirements, we need to print {NULL, {1}, {2}, {1,2}, {2,2}, {1,2,2}}| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm Coding Trees and Graphs - 0of 0 votes
AnswersYou are given an integer K, and a sorted array as an input which has been rotated about an unknown pivot. For example, 4 5 6 7 8 9 1 2 3.
- sc.shobhit September 14, 2013 in United States
We need to write a function which should return the index of K in the array, if K is present, else return -1.| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 1of 1 vote
AnswersWrite a function which returns the square root of a given number upto a precision of 0.0001. Only arithematic operations like addition, subtraction, division and multiplication are allowed.
- sc.shobhit September 14, 2013 in India| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm Coding - 33of 35 votes
AnswersA k-palindrome is a string which transforms into a palindrome on removing at most k characters.
- sc.shobhit August 28, 2013 in India
Given a string S, and an interger K, print "YES" if S is a k-palindrome; otherwise print "NO".
Constraints:
S has at most 20,000 characters.
0<=k<=30
Sample Test Case#1:
Input - abxa 1
Output - YES
Sample Test Case#2:
Input - abdxa 1
Output - No| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 0of 0 votes
AnswersGiven an array write a function to print all continuous subsequences in the array which sum of 0.
- Mukesh August 13, 2013 in United States
e.g:
Input:
Array = [-1, -3, 4, 5, 4]
output:
-1, -3, 4| Report Duplicate | Flag | PURGE
Facebook Algorithm - 0of 0 votes
AnswersGiven an array write a function to print all triplets in the array which sum of 0.
- Mukesh August 13, 2013 in United States
e.g:
Input:
Array = [-1, -3, 5, 4]
output:
-1, -3, 4| Report Duplicate | Flag | PURGE
Facebook Algorithm - 2of 4 votes
AnswersAlex is standing on the top left cell (1,1) of a n*m table. The table has n rows and m columns. Initially, he is facing its right cell. He moves on the table in the following way:
- itzmevacho August 01, 2013 in United States
>He moves one step forward.
>He turns to his right
>While moving forward, if he would go out of the table or reach a visited cell, he turns to his right.
He moves in the table as much as he can. Can you find out the number of cells he visits before he stops?
For example, given a 9x9 grid, the following would be his moves. The number on each cell represents the step he would land on that particular cell.
1 2 55 54 51 50 47 46 45
4 3 56 53 52 49 48 43 44
5 6 57 58 79 78 77 42 41
8 7 60 59 80 75 76 39 40
9 10 61 62 81 74 73 38 37
12 11 64 63 68 69 72 35 36
13 14 65 66 67 70 71 34 33
16 15 20 21 24 25 28 29 32
17 18 19 22 23 26 27 30 31
Input:
The first line of the input contains two integer numbers n and m.
n and m are between 1 and 100.
Output:
Print an integer to the output being the answer of the test.
Sample input #00:
3 3
Sample output #00:
9
Sample input #01:
7 4
Sample output #01:
18| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer - 1of 3 votes
AnswersWe have a rectangle with n rows and m columns filled with numbers from 1 to n*m.
- itzmevacho August 01, 2013 in United States
Cell (i,j) of the rectangle is important iff:
* i = 1 and j = 1 (or)
*there is an important cell (a,b) such that (a,b) is a neighbor of (i,j) and the number
on (i,j) is greater than number on cell (a,b) and all of (a,b)'s neighbors except for (
(i,j) itself
Two cells are considered to be neighbors if they share a common edge between them.
Unfortunately the number in some of the cells has been erased. We want to write a number to those cells such that the resultant rectangle has all the numbers between 1 to n*m and it contains as many important cells as possible. In case there are several ways to do that, we are interested with the rectangle which is lexicographically smallest.
A table is lexicographically smaller that the other if the string of its row-major view is lexicographically smaller than the other.
Input:
The first line of the input contains two integers n and m, Each of the next n lines contains m tokens. Each token is either an integer between 1 and n*m or '?'.
Output:
Print the maximum number of important cells that can be obtained in the first line of the output and print the rectangle in the next n lines.
Constraints:
1 <=n,m <=6
Sample input #00:
2 3
2 ? ?
? ? 3
Sample output #00:
3
2 1 4
5 6 3
Sample input #01:
6 6
? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ?
Sample output #02:
24
1 2 3 13 14 15
4 6 8 10 11 16
5 7 9 12 19 17
28 26 24 22 20 18
29 27 25 23 21 36
30 31 32 33 34 35| Report Duplicate | Flag | PURGE
Facebook Front-end Software Engineer - 3of 5 votes
AnswersA string is called sstring if it consists of lowercase english letters and no two of its consecutive characters are the same.
- priteshpathak15 July 29, 2013 in India
You are given string s of length n. Calculate the number of sstrings of length that are not lexicographically greater than s.
Input format
The only line of input contains the string s. It's length is not greater than 100.
All characters of input are lowercase english letters.
Output format:
Print the answer of test modulo 1009 to the only line of output.
Sample input:
bcd
Sample output:
653| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Front-end Software Engineer Algorithm - 2of 4 votes
AnswersGiven a sequence of numbers A(1) ..A(n), find the continuous subsequenceA(i)..A(j) for which the sum of elements is maximum.
- pirate July 28, 2013 in India
condition: we should not select two contiguous numbers| Report Duplicate | Flag | PURGE
Yahoo Facebook Software Engineer / Developer Algorithm - -3of 9 votes
AnswersGiven a number x, less than 100. How will you generate true with probability x/100. So if x = 65, how will you generate true with probability 65/100. You can represent true by 1 and false by 0.
- anil.varshney101 July 16, 2013 in -| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 0of 4 votes
AnswersGiven - a number (n) and a sorted array
- LAP July 07, 2013 in United States
Find a number in the array having least difference with the given number (n).| Report Duplicate | Flag | PURGE
Facebook Intern Algorithm - 7of 7 votes
AnswersPattern Matching
- mamidi.laxman.lnu June 11, 2013 in United States
----------------
Characters: a to z
Operators: * +
* -> matches zero or more (of the character that occurs previous to this operator)
+ -> matches one or more (of the character that occurs previous to this operator)
Output if a given pattern matches a string.
Example:
pattern:a*b
string:aaab b, ab, aab, aaab, ab
output:1
pattern:a+aabc
string:ab aabc, aaabc, aaaabc ..
output:0
pattern:aa*b*ab+
string:aab aab, aabab, aaaabbab
output:1
pattern: a+a*b*
string: a ab, aab, aaabb
output: 1
Valid Assumptions: Please assume that both the pattern and string input are valid| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer - 18of 18 votes
AnswersIf a=1, b=2, c=3,....z=26. Given a string, find all possible codes that string can generate. Give a count as well as print the strings.
- diffuser78 June 07, 2013 in United States
For example:
Input: "1123". You need to general all valid alphabet codes from this string.
Output List
aabc //a = 1, a = 1, b = 2, c = 3
kbc // since k is 11, b = 2, c= 3
alc // a = 1, l = 12, c = 3
aaw // a= 1, a =1, w= 23
kw // k = 11, w = 23| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm Coding - 1of 3 votes
AnswersYou are given an array of 1's 2's and 3's. Sort this list so the 1's are first, the 2's come second, and the 3's come third.
- Aasen May 23, 2013 in United States
Ex: Input [1, 3, 3, 2, 1]
Output [1, 1, 2, 3, 3]
But there is a catch!! The algorithm must be one pass, which means no merge/quick sort. Also no extra list allocations are allowed, which means no bucket/radix/counting sorts.
You are only permitted to swap elements.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern Algorithm - 0of 0 votes
AnswersGiven an array, find all unique three-member subsets, with unique being that [0,2,3] and [3,2,0] are the same set. Should run in faster than 2^n time
- shailpatel2 April 01, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
AnswersGiven an virtual 4x4 boggle board, and some 4 letter words, determine if the words are in the board
- rosie March 22, 2013 in United States
ex.
S M E F
R A T D
L O N I
K A F B
STAR- no
TONE- no
NOTE- yes
SAND- yes
etc.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Intern - 2of 2 votes
AnswersDesign the Facebook newsfeed for an Android app. The actual design would be very complex so you may limit your solution to only status updates and photo posts. Keep your answer broad rather than deep since it would need to fit in a 45-minute interview.
- Barry Fruitman March 20, 2013 in United States
Normally you would need to ask the interviewer a lot of questions but since that is not possible here, state your assumptions.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Android - 6of 6 votes
AnswersWrite a function that accepts two or more strings and returns the longest common substring in all of them.
- Barry Fruitman March 20, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 2of 2 votes
AnswersWrite a function that takes a string and returns true if the entire string is a palindrome, otherwise return false. The function should be case-insensitive and ignore any whitespace or punctuation.
- Barry Fruitman March 20, 2013 in United States
For example, return true for:
"A man, a plan, a canal: Panama."| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 1of 1 vote
AnswersImplement this Java function:
- Barry Fruitman March 20, 2013 in United States
int findNeedleInHaystack(String haystack, String needle)
If needle is a substring of haystack, it should return the index of needle.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Algorithm - 15of 15 votes
AnswersGiven a set of 2D points, some integer k, find the k points closest to the origin, (0,0).
- peetonn March 09, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook iOS Developer Algorithm - 1of 1 vote
AnswerHow will you describe iOS manual memory management for a new developer in few words?
- peetonn March 09, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook iOS Developer System Design - 0of 2 votes
AnswersHow would you implement call for canceling queued blocks with dispatch_after?
- peetonn March 09, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook iOS Developer Threads - 1of 3 votes
AnswersWrite a program to print the powerset.
- shubhra.datta March 05, 2013 in United States
E.g. given this set {1,2,3}, it will print {},{1},{2},{3},{1,2},{1,3}, {2,3}, {1,2,3}| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 0of 4 votes
AnswersWrite a program to clone a graph
- shubhra.datta March 05, 2013 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding - 3of 3 votes
AnswersFind the k'th largest element in a binary search tree. Write code for
- jtr.hkcr March 03, 2013 in United Statesstruct Node { int val; struct Node *left; struct Node *right; } Node; Node * kth_largest(Node *root, unsigned int k);
| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Coding