Facebook Interview Questions
- 0of 0 votes
Answerstrie search, Search Return all words that match the wildcard *
- ajay.raj November 12, 2017 in United States
such as
add ("car")
add ("caw")
add ("cauw")
search ("c*w") returns "caw" and "cauw".| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answersgiven a target node in a directed graph, find the shortest cycle including this node, return the whole path.
- ajay.raj November 11, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Intern - 0of 0 votes
AnswersImplement a trie tree which can add and search word, an extra "*" sign will also be considered, similar to Leetcode 211 but with "*"
- Aamir November 09, 2017 in United States
'*' means any sequence of characters (including the empty sequence).| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 1of 1 vote
AnswersGiven a Map (representing an old phone key number and possible letters present there) and a sequence of keys return all possible combinations of strings that are possible to produce.
Map<String, String[]> map = new HashMap<String, String[]>(); map.put("1", new String[] { "a", "b", "c" }); map.put("2", new String[] { "c", "d", "e" }); map.put("3", new String[] { "f", "g", "h" }); String in = "12"; List<String> mix(String in, Map<String, String[]> map)
The result for "1,2" should be [ac, bc, cc, ad, bd, cd, ae, be, ce]
- Bruno November 09, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Android Engineer Java - 0of 0 votes
Answers
- ajay.raj November 09, 2017 in United Statesgiven a binary array, you can flip 0 -> 1 or 1 -> 0 to make all the 1 are in the left part and all the 0 to the right part, return the minimun flip required example 1 1011000 -> 1111000 only need one flip 0 -> 1 example 2 00001 -> 10000 require 2 flips public int findMiniFlip(int[] nums) { } }
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven a string s, break s such that every substring of the partition can be found in the dictionary.
- ajay.raj November 05, 2017 in United States
Return the minimum break needed.
Example
Given a String CatMat
Given a dictionary ["Cat", "Mat", "Ca", "tM", "at", "C", "Dog", "og", "Do"]
return 1
we can break the sentences in three ways, as follows:
CatMat = Cat Mat break 1
CatMat = Ca tM at break 2
CatMat = C at Mat break 2
but the first way has the minimum break, thus return 1
public int wordBreak(String s, Set<String> dict) {
// Write your code here
}| Report Duplicate | Flag | PURGE
Facebook SDET - 0of 0 votes
AnswersGiven a 2d grid map of '1's (land) and '0's (water), find the perimeter of each island. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
- ajay.raj November 05, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersTo determine if two graphs have isomorphism or not
- ajay.raj November 05, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGive an array A, find the (i, j) pairs that satisfy the condition.
- ajay.raj November 05, 2017 in United States
Condition 1: A [j] = A [i] + 1, Condition 2: j - i is as large as possible
Followup condition 1 is changed to A [j]> A [i]| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answersfind a shortest string to cover all of a list of string,
- ajay.raj November 04, 2017 in United States
For example, [aab, aabb, bc], should return aabbc,
because aab, aabb, bc are all the substring of aabbc| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven a linked list with next and random pointer, deepcopy the linked list and return new head.
- me.samyakjain November 03, 2017 in United States
Node {
char val,
Node next,
Node random }
A {
val: ’a’
next: D
random: G}
D {
val: ’d’
next: G
random: A}
G {
val: ’g’
next: null
random: D}
-----------
| |
| V
A -> D -> G -> null
-------------
| |
| V
A' -> D' -> G' -> null| Report Duplicate | Flag | PURGE
Facebook Android Engineer Algorithm - 0of 0 votes
AnswersExplain in detail about your favourite android api.
- me.samyakjain November 03, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Android Engineer Android - 0of 0 votes
Answersgiven 2 list of interval representing users online offline timestamp e.g (already sorted), find all intervals that both of users are online.
- ajay.raj November 03, 2017 in United States
e.g A= [(3, 5), (7, 11)] B=[(2, 4), (9, 10)] --> [(3, 4), (9, 10)].| Report Duplicate | Flag | PURGE
Facebook SDE1 - 2of 2 votes
AnswerFacebook
- aonecoding November 03, 2017 in United States
-Phone: LC304 & longest arithmetic sequence. Return the sequence.| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersGiven an array of integers and k, find the difference between the number of the strictly increasing number of subarrays (of size more than one) and the number of the strictly decreasing subarray in the window of size k. your method should be time and space efficent
- ajay.raj November 03, 2017 in United States
example
int[] nums = {188930, 194123, 201345, 154243, 154243};
int k = 3;
Output
3, 0, -1
Explanation
For the first window of [188930, 194123, 201345], there are 3 increasing subranges ([188930, 194123, 201345], [188930, 194123], and [194123, 201345]) and 0 decreasing, so the answer is 3. For the second window of [194123, 201345, 154243], there is 1 increasing subrange and 1 decreasing, so the answer is 0. For the third window of [201345, 154243, 154243], there is 1 decreasing subrange and 0 increasing, so the answer is -1.
public int[] getdiff(int[] nums, int l){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answers
- ajay.raj October 31, 2017 in United StatesThere is an unordered interval stream, write a method, returns the total length that all intervals cover by now class Interval{ int start; int end; } public List<Integer> countCoverLength(Iterator<Interval> stream){ }
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answers‘.’Matches any single character,' * 'Matches any sequence of characters (including the empty sequence).
- ajay.raj October 28, 2017 in United States
There are two input, one is string pattern, and the other is dictionary like dict = ["cat", "cats", "and", "sand", "dog"].
return a boolean: whether to find a dictionary in the pattern match the word
eg: dict = ["cat", "cats", "and", "sand", "dog"].
pattern = "* t", -> true (can match cat)
pattern = ".a *" -> true (can match cat, cats, can also match sand, because * can also express empty sequence)| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersHow would you store and retrieve values in Memcache if the values are larger than the individual value size allowed by Memcache?
- ajay.raj October 25, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 2of 2 votes
Answersnode {
- ajay.raj October 23, 2017 in United States
node * left, * right;
}
Given a list of node to determine whether the node in the list can form a valid binary tree. several points of judgment
1. need to ensure that all left, right pointer point to the node inside list
2. no cycle
3. All node must be connected
Boolean isValidTree(List<Node> list){}| Report Duplicate | Flag | PURGE
Facebook Software Developer - 1of 1 vote
AnswersGiven a matrix of N * M, given the coordinates (x, y) present in a matrix,
- ajay.raj October 23, 2017 in United States
Find the number of paths that can reach (0, 0) from the (x, y) points with k steps (requires exactly k, k> = 0)
From each point you can go up, down, left and right in four directions.
For example, the following matrix:
----------
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
(x, y) = (1, 1), k = 2, the output is 2| Report Duplicate | Flag | PURGE
Facebook Software Developer - 0of 0 votes
AnswersFind all words [A-Z] in a dictionary (about 1M words) that are made of a subset (in any order) of the chars in the input parameter [A-Z].
- ajay.raj October 19, 2017 in United States
ex: input "ACRAT" (10 to 20 chars, up to 30 worst case)
matching words: "A", "CAR", "ACA", "ART", "RAC".
non-matching words: "BAR", "AAA"
follow up : the input is a list of words. Return a list of words that each
list is formed by exactly the characters in the input list.
For example: two lists {“DEBIT”, “CARD”} and{“BAD”, “CREDIT”}
are formed by the same exact group of characters.| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven a sorted list of integers, square the elements and give the output in sorted order.
- nra October 19, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersFind the distance between the farthest two elements in a binary tree.
- nra October 19, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer Algorithm - 0of 0 votes
AnswersGiven a string separated by a space like "123456 abc+efg" determine
- ajay.raj October 18, 2017 in United States
the solution by mapping integers to letters like a:1, b:2, c:3, d:4, e:5, f:6.
The only operations allowed were + or -. So the calculated solution
that made the tests pass was 123+456 = 579.| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersHow many subsets of a given array sum to zero?
- ajay.raj October 18, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven numbers 1 through 52, take 5 unique numbers and determine
- ajay.raj October 18, 2017 in United States
if the number 42 can be made using any combination of addition (+),
subtraction (-), multiplication (*), and division (/) on those 5 numbers| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
Answers/* Intersection of two sorted interval lists, A=[(1,2), (5,7)..]
B=[(2,6)...] return [(5,6)..] */
- ajay.raj October 09, 2017 in United Statesimport java.util.*; class Interval{ int start; int end; public Interval(int start, int end){ this.start = start; this.end = end; } } class Solution { public List<Interval> Intersection(Interval[] i1, Interval[] i2) {}
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answers* Given a string on length N. You can swap only the adjacent elements
- ajay.raj October 02, 2017 in United States
and each element can be swapped atmost once.
Find the no of permutations of the string that can be generated after
performing the swaps as mentioned.
Ex –
string – “12345”
Ans = 8
Explanations- (All the permutations)
12345
21345
13245
12435
12354
21435
13254
21354| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven an array of n positive integers, find the number of subarrays
- ajay.raj October 02, 2017 in United States
such that product of the elements of those subarrays are less than k.
For eg. Arr= {2, 3, 6} k=10
No of such subarrays= 4| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersPrint the levels of a binary tree in reverse order using stack and recursion
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ]
public List<List<Integer>> levelOrderBottom(TreeNode root) {
- ajay.raj October 02, 2017 in United States
}| Report Duplicate | Flag | PURGE
Facebook SDE1
Open Chat in New Window