## majia168

- 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 - 3of 3 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 non-negative int array and target number, check if the target can be equal to the sum of non-negative 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 non-overlap 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

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).

, but each time you sell you need to pay transaction fee, please calculate the maximum profit you can take. However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).

public int maxProfit(int[] prices, int fee) {

}| 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 States`A / \ 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 - 3of 3 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 States`For 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 - 5of 5 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/paper-cut-minimum-number-squares/| 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

**CareerCup**is the world's biggest and best source for software engineering interview preparation. See all our resources.

Open Chat in New Window

how about this one?

- majia168 March 02, 2017