Facebook Interview Questions
- 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 - 0of 0 votes
Answersgiven an array, find whether there exists 3 elements a,b,c in it such that a+b=c using efficient method.
- ajay.raj October 02, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersYou are provided a BST, which is corrupted. One of the nodes in it has 2 parents.
- ajay.raj October 02, 2017 in United States
Let’s say those are parent 1 and parent 2. It is ensured that none
of these parents will be the ancestor of the other. Identify the node,
and remove the link of the wrong parent.| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
Answersgiven an array of strings and characters, make the largest string possible.
- ajay.raj October 02, 2017 in United States
The resultant string should be a combination of the strings given in the array.
The given array
of characters may contain repeated elements.
Example – Given char array – {a,a,b,c,d,d,e,c} and given strings
– {abba, aabc, de, cde} the
ans is aabccde| Report Duplicate | Flag | PURGE
Facebook SDET - 1of 1 vote
AnswersGiven an adjacency matrix of a directed graph, find the number of cycles in the graph
- ajay.raj October 02, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersGiven K sorted (ascending) arrays. Write an iterator class that iterate over the arrays and returns the next element. Duplicate are allowed. What is the complexity to iterate the entire arrays? what is the complexity for each iteration?
Example:arr1 = {1,2,3,4,7,9} arr2 = {3,5,6,8,10}
The iterator should return:
1,2,3,3,4,5,6,7,8,9,10
Extension:
Don't return duplicates, so the above iterator should return:
- PenChief September 29, 2017 in Israel1,2,3,4,5,6,7,8,9,10
| Report Duplicate | Flag | PURGE
Facebook - 1of 1 vote
AnswersGiven a binary tree that complies to the following rule:
The parent node value is always the the result of the AND operator of its children values.
You modify one of the LEAF nodes value (e.g. if it was 1 it is now 0). Write a function that fixes the tree
so it complies with the above rule.
- PenChief September 19, 2017 in Israel// // 0 1 // / \ / \ // 1 0 =====> 1 1 // / \ / \ / \ / \ // 1 1 0 1 1 1 1 1 // // The parent node value is always children value's LOGICAL AND // & //
| Report Duplicate | Flag | PURGE
Facebook Algorithm - 0of 0 votes
AnswersGiven an array of integers, return the index of the max value in this array.
Note:
If the max value appears more than once, the function should return one the indexes, but make it so that the next call will return different index.
Important: you are not allowed to store state between calls
Example: given this input array// 0 -1 6 4 5 6 6 // | | | // 2,1/3 5,1/3 6,1/3
Function signature:
int getIndex(const std::vector<int>& numbers);
Example output:
2 5 6 5 2
Extension:
What if you knew how many times the max value appears in the array, can you improve the function performance?
So using the given example array, the function signature is now:
- PenChief September 19, 2017 in Israelint getIndex(const std::vector<int>& numbers, int maxCount);
| Report Duplicate | Flag | PURGE
Facebook Algorithm - 0of 0 votes
Answers
- ajay.raj September 19, 2017 in United StatesGiven an array of n * m matrix, and a moving matrix window (size k * k), move the window from top left to bottom right at each iteration, find the median number inside the window at each moving Can you do it better than brutal force method? void getMedian(int[][] matrix, int k){ print median } For matrix [ [1, 5, 3], [3, 2, 1], [4, 1, 9], ] The moving window size k = 2. At first the window is at the start of the array like this [ [|1, 5|, 3], [|3, 2|, 1], [4, 1, 9], ] ,get the median (2 + 3) / 2 = 2.5; then the window move one step forward. [ [1, |5, 3|], [3, |2, 1|], [4, 1, 9], ] ,get the median (2 + 3) / 2 = 2.5 then the window move one step forward again. [ [1, 5, 3], [|3, 2|, 1], [|4, 1|, 9], ] ,get the median (2 + 3) / 2 = 2.5 then the window move one step forward again. [ [1, 5, 3], [3, |2, 1|], [4, |1, 9|], ] ,get the median (1 + 2) / 2 = 1.5
| Report Duplicate | Flag | PURGE
Facebook SDE1 - 3of 3 votes
AnswersWe are planning an orienteering game.
- ajay.raj September 19, 2017 in United States
The aim of this game is to arrive at the goal (G) from the start (S) with the shortest distance.
However, the players have to pass all the checkpoints (@) on the map.
An orienteering map is to be given in the following format.
########
#@....G#
##.##@##
#..@..S#
#@.....#
########
In this problem, an orienteering map is to be given.
Calculate the minimum distance from the start to the goal with passing all the checkpoints.
Specification
* A map consists of 5 characters as following.
You can assume that the map does not contain any invalid characters and
the map has exactly one start symbol 'S' and exactly one goal symbol 'G'.
* 'S' means the orienteering start.
* 'G' means the orienteering goal.
* '@' means an orienteering checkpoint.
* '.' means an opened-block that players can pass.
* '#' means a closed-block that players cannot pass.
* It is allowed to move only by one step vertically or horizontally (up, down, left, or right) to the
next block.
Other types of movements, such as moving diagonally (left up, right up, left down and right down)
and skipping one or more blocks, are NOT permitted.
* You MUST NOT get out of the map.
* Distance is to be defined as the number of movements to the different blocks.
* You CAN pass opened-blocks, checkpoints, the start, and the goal more than once if necessary.
* You can assume that parameters satisfy following conditions.
* 1 <= width <= 100
* 1 <= height <= 100
* The maximum number of checkpoints is 18.| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
Answersconvert prefix to postfix expression
- ajay.raj September 16, 2017 in United States
public String convert2postfix(String prefix){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersGiven an array of integers where each element points to the index of the next element how would you detect if there is a cycle in this array
- ajay.raj September 12, 2017 in United States
can you do it without extra space| Report Duplicate | Flag | PURGE
Facebook SDE1 - 3of 3 votes
AnswersI get a chance to talk to Facebook software engineer during my android engineer interview. He asked me couple of question about native android like diff between views and fragment, mutable and immutable string, diff between string builder and string and a programming question convert int into words.
- Helper Guide September 08, 2017 in UK| Report Duplicate | Flag | PURGE
Facebook Android Engineer Android - 2of 2 votes
AnswersThere is a maze of size m*n. You are sitting at (0,0). Another person is sitting in another cell. There are some cheeses placed in different cells with a cell value of 2. Some cells are blocked with a value of 1, thus you cannot pass it, while some cells are filled with 0, thus you can pass it.
- ajay.raj September 08, 2017 in United States
You can move to left, right, up, down at each step. You have to collect all the pieces of cheese and then reach to Another Person cell. You need to return the minimum no. of steps required to do so.
Public int getShortest(int[][] maze, int[] anotherPersonCell){
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersWe start with a list of Integers. We can remove a group of integers from the list if the all but one equals the remaining number. This removal operation can be performed in the remaining number of list until no more operations can be performed.
- ajay.raj September 07, 2017 in United States
Write a function which can accept an array of integers, and return the minimal number of remaining integers from performing this operation.
Example [1, 3, 5, 6] -> remove 1, 5, 6 , because 1 + 5 = 6, thus only [3] left, so return 1
[48, 20, 1, 3, 4, 6, 9, 24] -> remove 3, 6, 9 , because 3 + 6 = 9, and remove 4, 20, 24, 48, because 4 + 20 + 24 + 48, thus only [1] left, so return 1
int left(int[] nums){
}| Report Duplicate | Flag | PURGE
Facebook Software Developer - 1of 1 vote
AnswersThe numbers on a telephone keypad are arranged thus:
1 2 3 4 5 6 7 8 9 0
Starting from any digit, and choosing successive digits as a knight moves in chess, determine how many different paths can be formed of length n. There is no need to make a list of the paths, only to count them.
- ajay.raj September 04, 2017 in United States
A knight moves two steps either horizontally or vertically followed by one step in the perpendicular direction; thus, from the digit 1 on the keypad a knight can move to digits 6 or 8, and from the digit 4 on the keypad a knight can move to digits 3, 9 or 0. A path may visit the same digit more than once.
Your task is to write a function that determines the number of paths of length n that a knight can trace on a keyboard starting from any digit .
public int findNumberOfPaths(int digit, int step){| Report Duplicate | Flag | PURGE
Facebook Software Engineer - -1of 1 vote
AnswerHow do I design a Payment Gateway system? What are the things to consider in this design ?
- koustav.adorable August 28, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook SDE-2 System Design - 2of 2 votes
AnswersIn Docker, building an image has dependencies. An image can only be built once
- ajay.raj August 27, 2017 in United States
its dependency is built (If the dependency is from outside, then the image can
be built immediately).
Sometimes, engineers make mistakes by forming a cycle dependency of local images.
In this case, ignore the cycle and all the images depending on this cycle.
Input is vector of pair of images (image, its dependency).
Output the order of images to be built in order.
##Example:
```
Example 1:
{{"master", "ubuntu"}, {"numpy", "master"}, {"tensorflow", "numpy"}}
Output: master, numpy, tensorflow
Example 2:
{{"python", "numpy"}, {"numpy", "python"}, {"tensorflow", "ubuntu"}}
Output: tensorflow
Example 3:
{{"b", "c"}, {"c", "d"}, {"a", "b"}, {"d", "e"}, {"e","c"}, {"f", "g"}}
Ouput: f| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersThere are n servers, reboot time is S0, S1..Sn-1
- ajay.raj August 27, 2017 in United States
There are m tasks, the completion of the time required are T0, T1… Tm-1
How to assign tasks to each server makes the total time the shortest| Report Duplicate | Flag | PURGE
Facebook SDE1 - 1of 1 vote
AnswersIf 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.
- Anon August 15, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersHow will you multiply two infinitely large integers.
- Anon August 15, 2017 in United States| Report Duplicate | Flag | PURGE
Facebook Software Engineer - 0of 0 votes
AnswersGiven a list/array of "Assign" trees with integers, operators and variables, return the result of the requested "Result" tree expression.
Example:
- thetinysheep August 13, 2017 in United States"Assign" / \ "x" "+" / \ 2 3 "Assign" / \ "y" "-" / \ 5000 30 "Assign" / \ "z" "*" / \ 50 x "Return" \ "-" / \ z "*" / \ 1 y
| Report Duplicate | Flag | PURGE
Facebook Software Developer Trees and Graphs - 1of 1 vote
AnswersYou are given logs that contain user and page visits for a given day.
- smitha August 13, 2017 in United States
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?| Report Duplicate | Flag | PURGE
Facebook - 0of 0 votes
AnswersConvert Json string to Map
- ajay.raj August 02, 2017 in United States
public Map jsonToMap(String t) {
}| Report Duplicate | Flag | PURGE
Facebook SDE1 - 0of 0 votes
AnswersWhat if server is slow, how to solve
- ajay.raj August 01, 2017 in United States
What if one server is down| Report Duplicate | Flag | PURGE
Facebook SDE1