majia168
 0of 0 votes
Answersgive a bunch of job dependency, such as A> B, A > C, B> D, and so on, implement two interfaces.
 majia168 in United States
The first one is get_next_stage, which returns jobs in parallel for the next phase. The second is job_done, which tells you which job completed. Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswerGive a list of the company's Mergers and Acquisitions relationships, for example
 majia168 in United States
[
["baidu", "ofo"],
["mobike", "alibaba"],
]
Said baidu acquired ofo, mobike acquired Alibaba.
Seeking the longest of a M & A chain. No cycle Report Duplicate  Flag
Google Backend Developer  0of 0 votes
Answersdetermine whether a number is the sum of two squares, such as 17 = 16 +1
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answers
 majia168 in United StatesGive a matrix, for example 1 0 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 Find if there is a rectangle in the matrix, all four corners are 1 For the example, there is only one rectangle, that is 1 0 1 0 1 0 1 0 1
 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersclass DirectedGraphNode {
 majia168 in United States
int label;
List<DirectedGraphNode> neighbors;
DirectedGraphNode(int x) {
label = x;
neighbors = new ArrayList<>();
}
}
check if there is a cycle in a directed graph, if there is a cycle, remove all the cycles Report Duplicate  Flag
Facebook SDE1  1of 1 vote
AnswersYou are given a binary tree and a function shouldBeErased(node to check whether a node should be erased. Erase all nodes that should be erased in the binary tree and return the resulting forest in the form of an array of every root node.
 majia168 in United States
Follow up:
What if this is a Binary Search Tree? (In this case you are given a list of nodes that should be erased instead of the function.) Does it make the problem simpler or more complicated or just the same? Report Duplicate  Flag
Google SDE1  0of 0 votes
Answersgiven a string and a segmentation length k
 majia168 in United States
For example:
"This is a good day" k = 10
Cut into:
"This (1/4)"
"is a (2/4)"
"good (3/4)"
"day (4/4)"
Each line followed by a suffix in the form of (i/n) has 10 chars including space (except for the last line), return the minimum cut required, for the example, just return 4. Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answerstrie search, Search Return all words that match the wildcard *
 majia168 in United States
such as
add ("car")
add ("caw")
add ("cauw")
search ("c*w") returns "caw" and "cauw". Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersgiven a target node in a directed graph, find the shortest cycle including this node, return the whole path.
 majia168 in United States Report Duplicate  Flag
Facebook Intern  0of 0 votes
AnswersThere are n bus lines, known bus stops by bus, the bus is bidirection, ask from station A to station B at least a few transfers.
 majia168 in United States Report Duplicate  Flag
Google SDE1  0of 0 votes
Answers
 majia168 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
Facebook SDE1  0of 0 votes
Answersthe longest unique value path in a graph
 majia168 in United States
/**
* Definition for undirected graph.
* class UndirectedGraphNode {
* int label;
* List<UndirectedGraphNode> neighbors;
* UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }
* };
*/
public class Solution {
public int findLongestUniqueValuePath(List<UndirectedGraphNode> node) {
}
} Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersGiven a string s, break s such that every substring of the partition can be found in the dictionary.
 majia168 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
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.
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersTo determine if two graphs have isomorphism or not
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGive an array A, find the (i, j) pairs that satisfy the condition.
 majia168 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
Facebook SDE1  0of 0 votes
AnswersGiven an array of length n + 1, containing elements 1 through n and a space,
 majia168 in United States
Requires the use of a given swap (index i, index j) function to sort the array,
You can only swap the gap and a number, in the end, put the gap at the end Report Duplicate  Flag
Google SDE1  0of 0 votes
Answersfind a shortest string to cover all of a list of string,
 majia168 in United States
For example, [aab, aabb, bc], should return aabbc,
because aab, aabb, bc are all the substring of aabbc Report Duplicate  Flag
Facebook SDE1  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.
 majia168 in United States
e.g A= [(3, 5), (7, 11)] B=[(2, 4), (9, 10)] > [(3, 4), (9, 10)]. Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswerDesign a SparseVector class that implements
 majia168 in United States
Vector interface, which contains 4 methods: get(int index),
increment(int index, int delta), numNonZeros(), and dotProduct(Vector other) Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswerGive a vote list = [(a, 100), (b, 150), (a, 200)] # (name, timestamp) and time T
 majia168 in United States
Find the highest number of votes (or anyone with the highest number of votes) at T
ex: T = 100 > a, T = 150 > a or b, T = 200 > a
followup1, give one more input K, find Top K votes at T
followup2, the same vote list, K, but given the Top K votes list, find the time T. Report Duplicate  Flag
Google SDET  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
 majia168 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
Facebook SDE1  0of 0 votes
Answers
 majia168 in United Statesgive an enum, where each element has a parentchildren relationship, and children's expression is the value of parent append an index, such as enum vehicle { car = 1 toyota = 11 camry = 111 corolla = 112 honda = 12 truck = 2 GMC = 21 } Ask a value, return to his parent, such as GMC = 21, return to the truck
 Report Duplicate  Flag
Google SDE1  1of 1 vote
AnswersGiven a list points on a 2d plane, find
 majia168 in United States
largest rectangular area that can be formed
for the rectangle only considers those parallel to x and y Report Duplicate  Flag
Google SDE1  0of 0 votes
Answers
 majia168 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
Facebook SDE1  0of 0 votes
Answers‘.’Matches any single character,' * 'Matches any sequence of characters (including the empty sequence).
 majia168 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
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?
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  2of 2 votes
Answersnode {
 majia168 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
Facebook Software Developer  1of 1 vote
AnswersGiven a matrix of N * M, given the coordinates (x, y) present in a matrix,
 majia168 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
Facebook Software Developer  0of 0 votes
AnswersFind all words [AZ] in a dictionary (about 1M words) that are made of a subset (in any order) of the chars in the input parameter [AZ].
 majia168 in United States
ex: input "ACRAT" (10 to 20 chars, up to 30 worst case)
matching words: "A", "CAR", "ACA", "ART", "RAC".
nonmatching 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
Facebook SDE1  0of 0 votes
AnswersGiven a string separated by a space like "123456 abc+efg" determine
 majia168 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
Facebook SDE1  0of 0 votes
AnswersHow many subsets of a given array sum to zero?
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven numbers 1 through 52, take 5 unique numbers and determine
 majia168 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
Facebook SDE1  1of 1 vote
Answers/* Intersection of two sorted interval lists, A=[(1,2), (5,7)..]
B=[(2,6)...] return [(5,6)..] */
 majia168 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
Facebook SDE1  0of 0 votes
Answers* Given a string on length N. You can swap only the adjacent elements
 majia168 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
Facebook SDE1  0of 0 votes
AnswersGiven an array of n positive integers, find the number of subarrays
 majia168 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
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 bottomup 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 bottomup level order traversal as: [ [15,7], [9,20], [3] ]
public List<List<Integer>> levelOrderBottom(TreeNode root) {
 majia168 in United States
} Report Duplicate  Flag
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.
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersYou are provided a BST, which is corrupted. One of the nodes in it has 2 parents.
 majia168 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
Facebook SDE1  1of 1 vote
Answersgiven an array of strings and characters, make the largest string possible.
 majia168 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
Facebook SDET  1of 1 vote
AnswerGiven an adjacency matrix of a directed graph, find the number of cycles in the graph
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answers
 majia168 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
Facebook SDE1  3of 3 votes
AnswersWe are planning an orienteering game.
 majia168 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 openedblock that players can pass.
* '#' means a closedblock 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 openedblocks, 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
Facebook SDE1  0of 0 votes
Answersconvert prefix to postfix expression
 majia168 in United States
public String convert2postfix(String prefix){
} Report Duplicate  Flag
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
 majia168 in United States
can you do it without extra space Report Duplicate  Flag
Facebook SDE1  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.
 majia168 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
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.
 majia168 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
Facebook Software Developer  0of 0 votes
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.
 majia168 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
Facebook Software Engineer  2of 2 votes
AnswersIn Docker, building an image has dependencies. An image can only be built once
 majia168 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
Facebook SDE1  0of 0 votes
AnswersThere are n servers, reboot time is S0, S1..Sn1
 majia168 in United States
There are m tasks, the completion of the time required are T0, T1… Tm1
How to assign tasks to each server makes the total time the shortest Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersInput: expression_tree  sequence_of_operations
 majia168 in United States
The input is a single line of text with a expression tree and a sequence of operations separated by  character and ended by a \n newline character. Spaces are allowed in the input but should be ignored.
The expression tree is a sequence of 1character variables AZ and with sub expression trees formed by parenthesis (expression_tree). Examples: AB, A(B C D), (AB)C((DE)F)
The sequence of operations is a string of with characters R (reverse) or S (simplify)
Reverse means reverse the order of everything in expression tree. Applying reverse twice in a row cancels out. Example: (AB)C((DE)F)  R should print (F(ED))C(BA)
Simplify means remove the parentheses around the very first element in the expression tree and each of its subexpression trees. Applying S multiple times should have same result as applying S once. Example: (AB)C((DE)F)  S should print ABC(DEF)
String process(String input){
} Report Duplicate  Flag
Twitter SDE1  0of 0 votes
AnswersConvert Json string to Map
 majia168 in United States
public Map jsonToMap(String t) {
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersWhat if server is slow, how to solve
 majia168 in United States
What if one server is down Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven a 2D matrix of 0's and 1's, where the 1's make up a rectangle, find the coordinates of the topleft corner of the rectangle and the rectangle's width and height.
 majia168 in United States Report Duplicate  Flag
Facebook Jr. Software Engineer  1of 1 vote
AnswersArray has N integers，range[0...N1]。Set S[k], 0 <= K < N as S[K] = {A[K], A[A[K]], A[A[A[K]]],....},
 majia168 in United States
write a function returns the size of the largest set S[K] for this array. return 0 if empty.
ex:
A = [5, 4, 0, 3, 1, 6, 2]
return 4 because S[2] equals {0, 5, 6, 2} 4 elements Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven an array of integers and a target number, determine if an arithmetic expression using these integers can be evaluated to the target number, you are allowed to use '+', '', '*', '/'. Followup: when evaluating the expression, take operand precedence into account,
 majia168 in United States
public boolean getTarget(int[] nums, int target){
}
exponentia is ok Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersfind the Closest leaf to a given node in Binary Tree
 majia168 in United States
can you do it in o(n) time
public TreeNode findCloestLeafNode(TreeNode root, TreeNode target){}
no parent pointer Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answervalidate IP in string format and return the uint32 format
 majia168 in United States
‘1.2.3.4’ > 0x01020304 Report Duplicate  Flag
Facebook SDE1  1of 1 vote
AnswersGiven a nnery tree and its deep copy, a node in the original tree, return the corresponding node in the copy
 majia168 in United States
public TreeNode getCopyNode(TreeNode root, TreeNode copy, TreeNode node) Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answerwrite bash code to determine if the first number in the string is greater than 1000
 majia168 in United States
STR="count  43952 (1 rows)" Report Duplicate  Flag
Amazon Backend Developer  0of 0 votes
AnswersWrite the code to find the median of an unsorted array in average linear time.
 majia168 in United States
followup the array is distributed across many machines. Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswerWrite a function to split a SQL query into individual statements.
 majia168 in United States
give you a String which contains a separate Query with a semicolon ";" return all valid queries
Such as
"select name from courseinfo ;; select * from db1 where home = 'usa' ;"
The main thing to consider is that some special cases such as the escape symbol and the quotation marks inside the semicolon
public List<String> getQuery(String queries){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersgiven a list of numbers, put with +  * / any two number, find the maximum value you can get.
 majia168 in United States
int getMaxNumber(int[] nums){
} Report Duplicate  Flag
Facebook Software Engineer  0of 0 votes
AnswersGiven a group of movies and their start time, assuming that are 1 hour long,
 majia168 in United States
Returns a movie schedule (no time conflict).
enter:
Movie ("Shining", [14, 15, 16])
Movie ("kill bill", [14, 15])
Movie ("Pulp fiction", [14, 15])
One possible result is shining 16, kill bill 15, pulp fiction 14
public void schedule (HashMap <String, List <Integer >> map) {
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersfriend circle. Given a streaming pairs representing friend relationship
 majia168 in United States
(1, 2) means 1 and 2 are friends, (1, 3) means 1 and 3 are friends
Return all its friends.
List<Integer> getFriends (Iterator<List<Integer>> relations, int id){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersgiven a matrix and a target, return if there is a path who’s sum is == target
 majia168 in United States
Input: matrix, integer output: true or false; Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answerspermute the String including case change
 majia168 in United States
"abc".
For example:
abc
ABC
Abc
aBc
abC
ABc
abC
AbC Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersimplemnt JSON.stringify()
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  1of 1 vote
Answersgiven a string of number, you can add a + or * sign between any two numbers, find the maximum value you can get
 majia168 in United States
ex. s = "89" > 8 * 9 = 72
int maxNumber(String s){} Report Duplicate  Flag
Facebook Software Engineer  0of 0 votes
AnswersGive you an unsorted integer iterator
 majia168 in United States
and a percentage that is expressed in double (for example, 0.4 for 40%),
and find the number of the sorted array at the percentage position.
Example: Enter [1 3 2 5 4 6 7 9 8 10], and 0.6, you will return 6
public int findNumber(Iterator<Integer> nums, double percent){
} Report Duplicate  Flag
Facebook Software Engineer  0of 0 votes
Answerscan you use union find to Detect Cycle in a Directed Graph? why or why not
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersShell command, there is a log file, you want all the "error" inside the line to find out into another file inside,
 majia168 in United States
What instruction, Report Duplicate  Flag
Amazon SDE1  0of 0 votes
Answerhow to design github
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersReturn the most popular 10 words in the past 24 hours for twitter
 majia168 in United States
Follow up in order to reduce the size of each log, do not write timestamp, how to get the same answer, Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven a Calendar class (there are three fields, year, month, day) and a number of N,
 majia168 in United States
Implement a function that returns the calendar after N days,
For example, if the input is {2017, 3,20} and 12, then the return is {2017,4, 1} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersimplement a Fibonacci iterator
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersNow we have one server, one database, what if response time is slow?
 majia168 in United States
How to optimize? Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven an integer n, count the total number of digit 3 appearing in all nonnegative integers less than or equal to n.
 majia168 in United States
(E.x: given 30, return 4 {3,13, 23, 30}) Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersprime factors. given a number return the prime factor multiplication.
 majia168 in United States
eg. 90 = 2 * 3 * 3 * 5. Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersRemove any number containing 9 like 9, 19, 29, ... 91, 92, ... 99, 109...
 majia168 in United States
Write a function that returns the nth number. E.g. newNumber(1) = 1
newNumber(8) = 8, newNumber(9) = 10 Report Duplicate  Flag
Facebook SDE1  2of 2 votes
AnswersGiven a n*m size 2D array with integers from 1 to n*m  1 in it.
 majia168 in United States
Integers are not sorted. The last position of the matrix stays a movable block.
For each time, you can swap the movable block with any adjacent number.
And eventually you will have the integers sorted and the movable block returned
to its starting position. Think about an approach to print the path.
(You can assume it always have at least a solution) Report Duplicate  Flag
Facebook Software Engineer  0of 0 votes
AnswersHow to get the repeating decimal pattern of a division? (e.g 1/3, 1/6)
 majia168 in United States Report Duplicate  Flag
Facebook Software Engineer  1of 1 vote
AnswersGiven a preorder traversal of a BST, print out the inorder transversal of the BST
 majia168 in United States
public void printInorder(int[] nums){} Report Duplicate  Flag
Facebook Software Engineer  0of 0 votes
Answers/* Find all subsets of size k in an array that sum up to target
 majia168 in United States
the array may contains negative number */
class Solution {
public List<List<Integer>> combinationSum(int[] nums, int target, int k) {
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersA bot is an id that visit the site m times in the last n seconds,
given a list of logs with id and time sorted by time, return all the bots's id
 majia168 in United Statesclass Log{ String id; int time; } public HashSet<String> getBots(Log[] logs, int m, int n){ }
 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answershow to implement a Wish List like this one
 majia168 in United States
https://www.amazon.com/hz/wishlist/intro Report Duplicate  Flag
Amazon SDE1  0of 0 votes
Answersdownload all urls from 1000 hosts. Imagine all the urls are graph.
 majia168 in United States
Requirement: Each host has bad internet connection among each other, Has to download url exacly once. Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswerGive you a robot and a room where you do not know where the robot is in the room and you do not know the size of the room, you have a remote control that allows the robot to walk around four directions. Here you give a move method: boolean move (int direction), direction: 0,1,2,3 that four directions. If it can move in that direction, return true, and if it cannot move in that direction, return false. Ask you determine how big this room is. the shape of the room can be any shape, so you cannot assume it is rectangle or square.
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven n1, n2 is the number after removing one digit from n1. Example, n1 = 123, then n2 can be 12, 13 or 23.
 majia168 in United States
If we know the sum of n1 + n2, and find the possible values of n1 and n2.
public List<List<Integer>> getNumber(int sum){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersDesign copyonwrite string class
 majia168 in United States
e.g. stringclass s("abc");
stringclass s1 = s; // no copy
s = "bcd"; // copy Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven an ODD number, print diamond pattern of stars recursively.
n = 5, Diamond shape is as follows: * *** ***** *** *
void print(int n){
 majia168 in United States
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answers/From the input array, output a subset array with numbers part of a Fibonacci series.
 majia168 in United States
// input: [4,2,8,5,20,1,40,13,23]
// output: [2,5,1,8,13]
public static List<Integer> getFibNumbers(int[] nums){} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersCan multiple threads improve the time complexity to merge k sorted arrays? If so, how?
 majia168 in United States Report Duplicate  Flag
Facebook SDE1 Arrays  0of 0 votes
AnswersGives an array of unsorted int (may have negative number),
 majia168 in United States
rearrange the array such that the
num at the odd index is greater than the num at the even index.
example
giving 5, 2, 3, 4, 1, one of the expected result is 1,4,2,5,3,
please solve it in o(n) time, where n is the length of the array
public void rearrange(int[] nums){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answers
 majia168 in United StatesGiven a string, find all possible combinations of the upper and lower case of each Alphabet char, keep the none Alphabet char as it is. example1 s = "ab", return: "Ab", "ab", "aB", "AB" example2 s = "a1b", return: "A1b", "a1b", "a1B", "A1B" public List<String> getPermutation(String s){ }
 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersFor a given array, find the subarray (containing at least k number) which has the largest sum.
 majia168 in United States
Example:
// [4, 2, 1, 3], k = 2, return 1, and the subarray is [2, 1]
// [1, 1, 1, 1, 1, 1], k = 3, return 6, and the subarray is [1, 1, 1, 1, 1, 1]
try to do it in O(n) time
Followup, if input is stream, how to solve it
public int maxSubArray(int[] nums, int k) {} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answersfind maximum contiguous subarray sum with size (the number of the element in the subarray) <= k
 majia168 in United States
a brute force method is very simple, can you do it better?
public int maxSum(int[] nums, int k){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answers// Read4K  Given a function which reads from a file or
 majia168 in United States
// network stream up to 4k at a time, give a function which
// which can satisfy requests for arbitrary amounts of data
private int read4K(char[] buf) {
// GIVEN
}
// IMPLEMENT:
public int read(char[] buf, int toRead) { }
Due to network latency, if the read4K method return a value < 4k, it does not necessarily mean that we reach the End of File (EOF), in this case, you should continue to read the file until you reach toRead or EOF. Report Duplicate  Flag
Facebook SDE1  1of 1 vote
Answerhow to keep track of the sum in a sliding window for the data that are on disk
 majia168 in United States
rather than memory Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersInsert a node in a complete binary tree efficiently.
it is not BST, it is just a regular binary tree
public TreeNode insert(TreeNode root, int val){
}
this my solution using bfs (O(n) time), is there any more efficient method?
 majia168 in United Statesimport java.util.*; class TreeNode{ int val; TreeNode left; TreeNode right; public TreeNode(int val){ this.val = val; } } class Solution{ public TreeNode insertCompleteTree(TreeNode root, int val){ if(root == null){ return new TreeNode(val); } Queue<TreeNode> q = new LinkedList<>(); q.add(root); while(!q.isEmpty()){ int size = q.size(); for(int i = 0; i < size; i++){ TreeNode cur = q.remove(); if(cur.left == null){ cur.left = new TreeNode(val); return root; }else{ q.add(cur.left); } if(cur.right == null){ cur.right = new TreeNode(val); return root; }else{ q.add(cur.right); } } } return null; } public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res = new ArrayList<>(); if(root == null){ return res; } Queue<TreeNode> q = new LinkedList<>(); q.add(root); while(!q.isEmpty()){ int size = q.size(); List<Integer> list = new ArrayList<>(); for(int i = 0; i < size; i++){ TreeNode cur = q.remove(); list.add(cur.val); if(cur.left != null){ q.add(cur.left); } if(cur.right != null){ q.add(cur.right); } } res.add(list); } return res; } public static void main(String[] args){ Solution s = new Solution(); TreeNode root = null; int[] nums = {1, 2, 3, 4, 5, 6, 7}; for(int num : nums){ root = s.insertCompleteTree(root, num); System.out.println(s.levelOrder(root)); } } }
 Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersA table has some number of balls at various positions on a line segment.
 majia168 in United States
All are moving with same speed in one or the other direction.
Wherever a collision occurs they change direction.
A ball falls from the edges of the table.
Find the time when all balls fall of the table
given initial position of each ball and speeds Report Duplicate  Flag
Google SDE1  0of 0 votes
Answersgiven a graph: example > A company holds 10% of B company’s share,
 majia168 in United States
B company holds 5% of C company’s share, A company holds 2% of C company’s share,
what percent of C company’s share does A company hold? Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answers
 majia168 in United States// Design and implement key value system // // string > string // Insert a keyvalue pair or modify a value void put(string key, string value); // Delete a keyvalue pair void delete(string key); // Gets a value given a snapshot string get(string key, Snapshot snap); // Take a snapshot Snapshot takeSnapshot(); // Delete a snapshot void deleteSnapshot(Snapshot snap); // put(k1,v1) // put(k2,v2) // put(k3,v3) // takeSnapshot > snap1 { k1 > v1, k2 > v2, k3 > v3 } // get(k1,snap1) > v1 // put(k1,v4) // delete(k3) // takeSnapshot > snap2 { k1 > v4, k2 > v2 } // get(k1,snap2) > v4 // get(k1,snap1) > v1 // get(k3,snap2) > XX // deleteSnapshot(snap1) // get(k1,snap1) > XX // Space efficient is more important than time efficient, thus please use as small space as possible.
 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersWhat is the cost / complexity of a String.indexof() function call in java?
 majia168 in United States Report Duplicate  Flag
Amazon SDE1  0of 0 votes
AnswersGiven a task sequence tasks such as ABBABBC, and an integer k, which is the cool down time between two same tasks. Assume the execution for each individual task is 1 unit.
 majia168 in United States
rearrange the task sequence such that the execution time is minimal.
Example:
S = AAABBBCCC, K = 3
Result: ABCABCABC (all 'A's are 3 distance apart, similarly with B's and C's), thus return 9
S = AAABC, K=2
Result: ABCA_ _A, thus return 7
S = AAADBBCC, K = 2:
Result: ABCABCDA, thus return 8
public int rearrangeTasks(String tasks, int cooldown){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven an array of n elements which contains elements from 0 to n1, with any of these numbers appearing any number of times. Find these repeating numbers in O(n) and using only constant memory space.
 majia168 in United States
Try to do it in one pass
example
[4, 2, 0, 5, 2, 0, 1] return: 0, 2
[1, 2, 3, 0, 0, 1, 3, 6, 6,6] return 0, 1, 3, 6
public List<Integer> findRepeat(int nums[]){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersHow to check the validity of a 4 digit credit card expiration date (mm/yy)
 majia168 in United States
that still works 100 years from now.
public boolean isValid(String s){
} Report Duplicate  Flag
Amazon SDE1  0of 0 votes
Answerswhat is the time complexity for java.util.Random.nextInt()
 majia168 in United States Report Duplicate  Flag
Amazon Java Developer  0of 0 votes
Answersconvert a ternary expression into a Binary tree structure. a?b:c a / \ b c a?b?c:d:e a / \ b e / \ c d class TreeNode{ char val; TreeNode left; TreeNode right; public TreeNode(char val){ this.val = val; } } public TreeNode build(String s){}
try to do it in o(n) time complexity, n is the size of the string
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersSuppose you have a 2D grid. Each point is either land or water. There is also a start point and a goal. There are also keys that open up doors. Each key corresponds to one door. Implement a function that returns the shortest path from the start to the goal using land tiles, keys and open doors. Data Representation The board will be passed as an array of chars. A board can have the following tiles. 0 = Water 1 = Land 2 = Start 3 = Goal uppercase = door lowercase = key Example Maps (keys at each step are not required) `No doors` char[][] board1 = {{'0', '2', '1', '1', '1'}, {'0', '1', '0', '0', '1'}, {'0', '1', '0', '0', '3'}, {'0', '1', '0', '0', '1'}, {'0', '1', '1', '1', '1'}}; path : [0,1]>[0,2]>[0,3]>[0,4]>[1,4]>[2,4] `One door` char[][] board2 = {{'0', '2', '1', '1', '1'}, {'0', '1', 'a', '0', 'A'}, {'0', '1', '0', '0', '3'}, {'0', '1', '0', '0', '1'}, {'0', '1', '1', '1', '1'}}; path : [0,1]>[0,2]>[1,2]>[0,2]>[0,3]>[0,4]>[1,4]>[2,4]
public List<int[]> solve(char[][] board) {
 majia168 in United States Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersGroup a list of words so that the same group of words have a common substring, and this common substring is also in the word lists,
 majia168 in United States
example
[cow "," cold "," an "," co "], return [[" can "," an "], [" cow "," cold "," co "]]
["can", "cow", "cold"], return [["can"], ["cow"], ["cold"]]
["c", "ca", "can"], return [["c", "ca", "can"]]
public List<List<String>> groupWords(String[] s) Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersEnter a two digit number, find the year closest to this year.
 majia168 in United States
Example input 99, return 1999;
Input 15, return 2015.
public int getClosestYear(int input){
} Report Duplicate  Flag
Facebook SDE1  2of 4 votes
Answersgenerate random number which differs from the number generated last time in the range of [min, max)
 majia168 in United States
what is the best way to do it?
public int getNumber(int min, int max){
} Report Duplicate  Flag
Facebook SDE1  1of 1 vote
AnswersGiven a undirected graph with each node representing a char and a word,
check if the word can be formed by any path of the graph
example
graph:
adogact
word : dog, return true;
word: cat, return false;
The same letter may not be used more than once.
 majia168 in United Statesclass Node { char label; List<Node> neighbors; Node(char x) { label = x; neighbors = new ArrayList<>(); } } class Solution { public boolean exist(List<Node> nodes, String word) { } }
 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven a Binary tree (Not binary Search Tree ), find the inorder successor of a node.
 majia168 in United Statesclass TreeNode{ TreeNode left; TreeNode right; int val; public TreeNode(int val){ this.val = val; } } public TreeNode inOrderSuccessor(TreeNode root, TreeNode n) {
 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven a positive integer n, find the no of integers less than equal to n, whose binary representation doesn't contain consecutive 1s.
 majia168 in United States
eg:
I/P : 4
O/P: 4 (0,1,2,4 Valid)
public int count(int n){
} Report Duplicate  Flag
Facebook SDE1  1of 1 vote
AnswersGiven m 0 and n 1, count the total number of permutations where two 1 cannot be adjacent
 majia168 in United States
public int count(int m, int n){
} Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven a binary tree, return all the longest path between any two nodes in a tree. This path may or may not pass through the root.
Example:
Given a binary tree
 majia168 in United States/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ 1 / \ 2 3 / \ 4 5 Return [4,2,1,3] and [5,2,1,3]. Public List<List<Integer>> getLongestPath(TreeNode root) { }
 Report Duplicate  Flag
Google SDE1  1of 1 vote
AnswersGenerate a random 4digit even number : the adjacent 2 digits must be different.
 majia168 in United States
public int getNumber(){
} Report Duplicate  Flag
Google Software Engineer  1of 1 vote
Answerswrite a function that randomly return a random Fibonacci number in range [min, max)
 majia168 in United States
public int getRandom (int min, int max){} Report Duplicate  Flag
Google SDE1  0of 0 votes
Answerswrite a function that randomly return a random prime number in range [min, max)
 majia168 in United States
public int getRandom (int min, int max){} Report Duplicate  Flag
Google SDE1  0of 0 votes
Answershow does java implement priority queue?
 majia168 in United States
i answered min heap, the interviewer seemed it was not right Report Duplicate  Flag
Amazon SDE1  0of 0 votes
Answer
 majia168 in United Statesclass Log{ String fun_name; String enterOrExit;// enter or exit int time; public Log(String fun_name, String enterOrExit, int time){ this. fun_name = fun_name; this. enterOrExit = enterOrExit; this.time = time; } } public void printInclusiveAndExclusiveTime (List<Log> logs){ } Log for some functions, calculate the inclusive time and exclusive time for each function E.g Fun_name enter / exit time F1 enter 1 F2 enter 2 F2 exit 3 F1 exit 4 F1: inclusive time = 41 = 3, exclusive time = 31 = 2 F2: inclusive time = 32 = 1, exclusive time = 1
 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersFind the subarray within an array (containing at least TWO number) which has the largest sum.
 majia168 in United States
For example, given the array [2,1,3,4,1],
the contiguous subarray [2,1] has the largest sum = 3.
try to do it in O(n) time
Followup, if input is stream, how to solve it
public int maxSubArray(int[] nums) {} Report Duplicate  Flag
Facebook Software Engineer  0of 0 votes
Answerstokenize string, "" and [] are token flags, such as
 majia168 in United States
mytable "foo" [bar] "" [[[[]]].
"" Turned into ",]] turned into], [[not escaped
The results of the example given above:
mytable
foo
bar "
[[]
public List<String> tokenizestring(String s){
} Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersWhat design pattern is used to implement a SynchronizedHashMap?
 majia168 in United States Report Duplicate  Flag
Amazon Java Developer  0of 0 votes
AnswersF (n) = 3n + 1 (if n is odd) or n / 2 (if n is even)
 majia168 in United States
Collapse sequence refers to each number according to this formula
until the sequence becomes equal to 1,
Find the number (which is not greater than 10000), which will have the longest Collapse sequence.
public int getlongestCollapsesequence(int n){
} Report Duplicate  Flag
Google SDE1  1of 1 vote
AnswersFind the Lexicographic next word of the input word from a list of words
 majia168 in United States
Example
Words list
[Cat, dog, cow, donkey, zebra, monkey],
input
duck
output
monkey
Input
dog
output
donkey
Can you use trie to solve it?
public String findNextWord(List<String> words, String input){
} Report Duplicate  Flag
Google Software Engineer  0of 0 votes
Answerswrite a function to generate a random 4 digit unique even number, the four digits cannot be the same, 1234 is valid, but 1134 is not valid
 majia168 in United States Report Duplicate  Flag
Google SDE1  1of 1 vote
Answerswrite a function that randomly return only odd number in range [min, max)
 majia168 in United States
public int getRandomOdd(int min, int max){} Report Duplicate  Flag
Google Software Developer  0of 0 votes
AnswersFor a string chemical formula like “C6H2(NO2)3CH3”, and output a map with key as element and value as its count.
 majia168 in United States
element can have two chars, for example Fe2(SO4)3
public HashMap<Character, Integer> getCount(String chemicals){
} Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersA "derangement" of a sequence is a permutation where no element appears in its original position. For example ECABD is a derangement of ABCDE, given a string, may contain duplicate char, please out put all the derangement
 majia168 in United States
public List<char[]> getDerangement(char[]){} Report Duplicate  Flag
Facebook SDE1  2of 2 votes
Answersthree sum with duplicate, pirnt all indexes, for example:
 majia168 in United States
0 2 2 2
(0)(1)(2)(3)
print (0, 1, 2) (0, 1, 3)
can you do it use n^2 (or less) time complexity with as less space as possible?
public List<List<Integer>> threeSum(int[] nums) {} Report Duplicate  Flag
Facebook SDE1  0of 2 votes
AnswersGiven an array of task and k wait time for which a repeated task
 majia168 in United States
needs to wait k time to execute again. please rearrange the task
sequences to minimize the total time to finish all the tasks.
Example
Tasks = 111222, k = 2,
One possible task sequence is
12_12_12,
another possible task sequence is 21_21_21
thus you shoud return 8
public int getMiniTime(int[] nums, int k){
}
follow up, output one of the sequence 12_12_12, or 21_21_21 Report Duplicate  Flag
Facebook SDE1  0of 0 votes
AnswersGiven an unsorted array, sort it in such a way that the first
 majia168 in United States
element is the largest value, the second element is the smallest,
the third element is the second largest element and so on.
[2, 4, 3, 5, 1] > [5, 1, 4, 2, 3]
can you do it without using extra space
public void sortAlternate(int[] nums){} Report Duplicate  Flag
Facebook SDET  0of 0 votes
AnswersGiven a number of tasks (T) and servers (S), find out if the tasks can be accommodated on the servers. Each Task has a number of Units and each server has a number of Slots on which Units can run.
 majia168 in United States
The only condition is that two Units of the same Task "cannot" run on the same Server.
Servers
S[0] = "SS1", "SS2", "SS3", SS4 //Slots // 4 > 3 > 2 > 1
S[1] = "SS1", "SS2" // 2 > 1 > 0 > false
S[2] = "SS1", "SS2", SS3, SS4, SS5 // 5 > 4 > 3 > 2
S[3] = "SS1", "SS2", SS3, SS4, SS5 // 5 > 4 > 3 > 2
Example:
S[0] = 4
S[1] = 3
S[2] = 5
S[3] = 5
...
Tasks
T[0] = U0, U1, U2, U3 //Tasks
T[1] = U0, U1
T[2] = U0, U1, U2
...
Example:
T[0] = 4
T[1] = 2
T[2] = 3
implement
boolean boolean CanRunTasks(S[], T[]){
} Report Duplicate  Flag
Facebook SDE1  1of 1 vote
Answerdeleted
 majia168 in United States Report Duplicate  Flag
Google SDE1  0of 0 votes
Answersclass UndirectedGraphNode { int label; List<UndirectedGraphNode> neighbors; UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<>(); } } public boolean isBipartite(List<UndirectedGraphNode> nodes){ }
use DFS algorithm to check the bipartiteness of a graph
 majia168 in United States Report Duplicate  Flag
Facebook SDE1  0of 0 votes
Answers* Definition for a binary tree node.
 majia168 in United States
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
Given an array of Binary Tree Node, check if all of these nodes can form a binary tree?
Public boolean canForm(TreeNode[] nodes){
} Report Duplicate  Flag
Google Software Engineer / Developer  0of 0 votes
AnswersGive a Runable interface, and then give a scheduler post method. This post is parallel, for example:
 majia168 in United States
Method header:
public void post (Runable r) {};
Call 5 times:
Scheduler.post (r1);
Scheduler.post (r2);
Scheduler.post (r3);
Scheduler.post (r4);
Scheduler.post (r5);
The five runables are allocated to five threads and run at the same time. And then asked: how to achieve these five tasks one by one run, Report Duplicate  Flag
Google SDE1  4of 4 votes
Answersthere is a bunch of tasks, each have different time to complete, task is independent, and then there are some workers,
 majia168 in United States
How to allocate tasks to these workers to minimize the total time to complete all the task. The tasks can be randomly picked from the task list.
Example
Task: 2,2,3,7, 1
Worker: 2.
Return 8, because the first worker can work on the first three tasks : 2 + 2 + 3 = 7, and the second worker can work on the last two tasks : 7 + 1 = 8, so the total time to finish all the task is 8.
public int getMini(int[] tasks, int k) Report Duplicate  Flag
Facebook SDE1  4of 4 votes
AnswersGiven an nonnegative int array and target number, check if the target can be equal to the sum of nonnegative multiples of the numbers in the array.
 majia168 in United States
For example, I have three numbers 6,9,20. Ex: n = 47 then it can be determined that 47 = 9*3 + 20
n=23 then there are no combinations.
public boolean combinationSum(int[] nums, int target) {
} Report Duplicate  Flag
Google SDE1  2of 2 votes
AnswersFind three nonoverlap windows of size k in an int array, that together has a maximum sum
 majia168 in United States
of the 3k entries.
example
int[] nums = [1,2,1,2,6,7,5,1]
k = 2
output
[1,2],[2,6],[7,5] Report Duplicate  Flag
Google Software Engineer  2of 2 votes
AnswersGiven an int array without repeated elements and a target, count the total number of subset that can be generated from the array such that min (subset) + max (subset) < target
 majia168 in United States
public int countSubSet(int[] nums, int target){
} Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersData structure design, N horse races, there are 10 checkpoints, whenever a horse through a check point will produce a (horse number, check point number) message, then design a data structure and algorithm to update the messages and then get the top 3 horse efficiently.
 majia168 in United States Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersInput friend’s relation {{1,2}, {2,3}, {3,4}}, could you split all the users into two groups and for the user in each group, all the users do not know each other. So the expected output should be group1 {1,3}, group2 {2,4}. If it is cannot be spitted into two group, just return “impossible”
 majia168 in United States Report Duplicate  Flag
Google SDE1  0of 0 votes
AnswersGiven an array that contains both positive and negative integers, find the start and end index of the subarray that achieves the maximum subarray product using one pass
 majia168 in United States Report Duplicate  Flag
Google  0of 0 votes
Answershow to find leaf node value from preorder sequence of BST without rebuilding the tree
 majia168 in United States Report Duplicate  Flag
Google Software Engineer  0of 0 votes
Answersdeleted
 majia168 in United States Report Duplicate  Flag
Google Software Engineer  2of 2 votes
AnswersSay you have an array for which the ith element is the price of a given stock on day i.
 majia168 in United States
Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
, but each time you sell you need to pay transaction fee, please calculate the maximum profit you can take.
public int maxProfit(int[] prices, int fee) {
} Report Duplicate  Flag
Google  0of 0 votes
Answersfor a binary tree, print the root to the leaf path, but add "_" to indicate the relative position.
example:
 majia168 in United StatesA / \ B C / \ / \ D E F G output _ _ A _ B D _A B _E A _C F A _ C _ _ G
 Report Duplicate  Flag
Google Software Engineer  0of 0 votes
Answers/**
 majia168 in United States
* Definition for an interval.
* public class Interval {
* int start;
* int end;
* Interval() { start = 0; end = 0; }
* Interval(int s, int e) { start = s; end = e; }
* }
*/
Given a list of intervals, and a target interval
Our goal is to merge these intervals, so that the results of the merge can cover the target interval, return the minimum number of the original interval required for this merge
For example
IntervalList: [1, 9] [1, 10] [0, 3] [9,10] [3, 14] [2, 9] [10, 16]
Target interval: [2, 15]
we find that there are several ways to cover [2,15], such as:
[1, 9] + [9,10] + [10, 16] or [1, 10] + [10, 16].
We want to merge the least number of ways, so here should return 2 Report Duplicate  Flag
Google SDE1  4of 4 votes
Answers/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */
Find if a given binary tree has duplicate sub trees.
followup:
Find all duplicate subtrees in a binary tree
 majia168 in United StatesFor example, 1 / \ 2 3 / / \ 4 2 4 / 4 The following are two duplicate subtrees: 2 / 4 and 4 Therefore, return [ [2,4], [4] ].
 Report Duplicate  Flag
Google Software Engineer / Developer  0of 0 votes
Answercount Number of balanced Binary Tree given Preorder Sequence length
 majia168 in United States Report Duplicate  Flag
Amazon SDE1  6of 6 votes
AnswersPaper Cut into Minimum Number of Squares
 majia168 in United States
Given a paper of size A x B. Task is to cut the paper into squares of any size. Find the minimum number of squares that can be cut from the paper.
Examples:
Input : 13 x 29
Output : 9
Explanation :
2 (squares of size 13x13) +
4 (squares of size 3x3) +
3 (squares of size 1x1)=9
Input : 4 x 5
Output : 5
Explanation :
1 (squares of size 4x4) +
4 (squares of size 1x1)
geeksforgeeks provides a solution, but it is not right
http://www.geeksforgeeks.org/papercutminimumnumbersquares/ Report Duplicate  Flag
Google  0of 0 votes
AnswersGiven a diamond shape matrix, find the minimum path sum from top to bottom.
Each step you may move to adjacent numbers on the row below.
 majia168 in United States[ [2], [3,4], [6,5,7], [4,1,8,3], [2,5,4], [6,4], [1] ]
 Report Duplicate  Flag
Amazon Software Engineer / Developer  0of 0 votes
AnswersDesign a algorithm to initialize the board of Candy Crush Saga. With M x N board, Q types of candies. (Rules: no 3 for run after initialization, must contain at least one valid move at the beginning)
 majia168 in United States Report Duplicate  Flag
Facebook Software Engineer / Developer  0of 0 votes
AnswersIf a string is matched to any filter, it is in the black list, otherwise not.
 majia168 in United States
Design a data structure and implement following two functions.
addFilter(filter)
isInBlackList(string)
filters are in the form of
“a*b”
“abc”
“aa*b”
having at most one star, which matches 0 or more chars. Report Duplicate  Flag
Amazon Software Engineer
how about this one?
#include <iostream>
#include <vector>
using namespace std;
int minsum(vector<vector<int>> &nums){
int n=nums.size();
if(n==0) return 1;
for(int i=1;i<n;i++){
for(int j=0;j<nums[i].size();j++){
// fom top to middle
if(nums[i].size()>nums[i1].size()){
if(j1>=0&&j<nums[i1].size()){
nums[i][j]+= min(nums[i1][j1],nums[i1][j]);
}else if(j==0){
nums[i][j]+=nums[i1][j];
}else{
nums[i][j]+=nums[i1][j1];
}// from mid to bottom
}else{
nums[i][j]+=min(nums[i1][j],nums[i1][j+1]);
}
}
}
return nums[n1][0];
}
/*
[
[2],
[3,4],
[6,5,7],
[4,1,8,3],
[2,5,4],
[6,4],
[1]
]
*/
int main() {
vector<vector<int>> nums={{2},{3,4},{6,5,7},{4,1,8,3},{2,5,4},{6,4},{1}};
cout<<minsum(nums);
/*for(auto num:minsum(nums)){
for(auto n:num)
cout<<n<<" ";
cout<<endl;
}*/
//cout<<"Hello";
return 0;
}

majia168
March 02, 2017
RepEdwards IVF Surrogate is one of the best & most successful provider of surrogate services.We provide moral, emotional, ethical and ...
RepWant to know how to protect from black magic? Guru Ji is the world’s famous astrologer and he has ...
RepLooking for the best day care center Charlotte? PalARoo’s Child Development Center is a family owned child care facility ...
RepSpent 20012006 getting my feet wet with Slinkies in Fort Walton Beach, FL. mantra to control girl Spent 20012006 working ...
RepPrestige Luxury Rentals, Tech Lead at Prestige Luxury Rentals
Prestige Luxury Rentals is highly recommended company for exotic car rental Miami. With our top brand vehicles like; exotic, luxury ...
RepAmber Van is the top rated company that offers friendly and professional removals services.Our featured services includes domestic moves ...
Rep
RepAre you searching for the most powerful and very strong mantra for your husband? If you want to do Jadoo ...
RepJonathan Galgano, Data Engineer at Blue Jeans
Drive with the most affordable Exotic Car Rental South Beach. Prestige luxury Rentals is offering you with the finest car ...
RepJohn Colcomb, Analyst at A9
With more than 20 years of car rental and dealership experience, responsible for developing growth strategies to maximize operational effectiveness ...
RepLarry Alvarez, Analyst at ASU
Prestige Luxury Rentals is one of the most renowned car rental companies in USA. We are locally owned and operated ...
RepSCREENish employee time tracking software can be used as desktop or mobile app. Once the employee has tracked his working ...
RepBlack magic mantra is simple and easy mantra. Call our specialist today for advice on black magic mantra to kill ...
RepGerard Swearingen, Consultant at ADP
Want to book exotic and luxury car rental in Atlanta, GA ? We, Prestige Luxury Rentals are the best car rentals ...
Repfesfporyi212, Member Technical Staff
My self Fesfpory. I work in agriculture university in India as a professor. I done PHD in Botany in Punjab ...
RepAlisonjaeger755, Data Engineer at Accolite software
I am work in Telecom line in IDEA company. I am data operator and Engineer in back end in Idea ...
Open Chat in New Window
rsrs3
 majia168 May 04, 2017for {"an","dan", "c"}, your codes return [[an], [c], [dan]]
but it should be [[c], [an, dan]]