## Recent Interview Questions

- 1of 1 vote

AnswersWrite a method that can take in an unordered list of airport pairs visited during a trip, and return the list in order:

- mandy May 08, 2018 in United States

Unordered: ("ITO", "KOA"), ("ANC", "SEA"), ("LGA", "CDG"), ("KOA", "LGA"), ("PDX", "ITO"), ("SEA", "PDX")

Ordered: ("ANC", "SEA"), ("SEA", "PDX"), ("PDX", "ITO"), ("ITO", "KOA"), ("KOA", "LGA"), ("LGA", "CDG")| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 1of 1 vote

AnswersGiven a binary tree, where each node represents an integer, find the max value of path sum.

- LeetCoder May 07, 2018 in United States| Report Duplicate | Flag | PURGE

Facebook Android Engineer Trees and Graphs - 2of 2 votes

AnswersApril Google Interview 1/4

- aonecoding May 06, 2018 in Korea

A = a+b-c-a-b-c-a-b (Tree)

B = b+a+c+a+b-c+b (Tree)

is A equal to B| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersApril Google Interview 3/4

- aonecoding May 06, 2018 in Korea

Maze

N,M array

Level 1 0,0 to N-1,M-1 => Path exsits?

Level 2 if path exists then print path

Level 3 if path exists then print min cost path

Level 4 O(nm log mn) using Priority Queue.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersYou are given a string S consisting of lowercase English letters denoting different types of candies. A substring of a string S is a string S' that occurs in S. For example, "bam" is a substring of "babammm". Each candy costs 1 unit. You can pick some continuous candies such that you can create a palindrome of length K by using some or all picked candies. Your task is to find the minimum cost to create a palindrome of length K.

- rahul123625 May 06, 2018 in India

Input Format:

First line contains string S.

Next line contains an integer T denoting the number of test cases.

Next T lines contain a single integer K.

Output Format:

For each test case, print minimum cost as mentioned above. If you cannot create a palindrome of length K then, simply print -1.

Constraints:

Constraints:

1≤|S|≤10^5

1≤T≤10

1≤K≤10^5

Sample Input

babammm

2

2

5

Sample Output

2

5

Explanation

Test Case 1: You can pick candies denoted by "mm" and create a palindrome of size 2. So the cost will be 2 units.

Test Case 2: You can pick candies denoted by "babam" and rearrange them, "bamab", to create a palindrome of size 5. So the cost will be 5 units.| Report Duplicate | Flag | PURGE

makemytrip Java Developer - 0of 0 votes

AnswersYou are given a string S consisting of lowercase English letters denoting different types of candies. A substring of a string S is a string S' that occurs in S. For example, "bam" is a substring of "babammm". Each candy costs 1 unit. You can pick some continuous candies such that you can create a palindrome of length K by using some or all picked candies. Your task is to find the minimum cost to create a palindrome of length K.

- rahul123625 May 06, 2018

Input Format:

First line contains string S.

Next line contains an integer T denoting the number of test cases.

Next T lines contain a single integer K.

Output Format:

For each test case, print minimum cost as mentioned above. If you cannot create a palindrome of length K then, simply print -1.

Constraints:

Constraints:

1≤|S|≤10^5

1≤T≤10

1≤K≤10^5

Sample Input

babammm

2

2

5

Sample Output

2

5

Explanation

Test Case 1: You can pick candies denoted by "mm" and create a palindrome of size 2. So the cost will be 2 units.

Test Case 2: You can pick candies denoted by "babam" and rearrange them, "bamab", to create a palindrome of size 5. So the cost will be 5 units.| Report Duplicate | Flag | PURGE

- 0of 0 votes

Answers/**

* Definition for a binary tree node.

* public class TreeNode {

* int val;

* TreeNode left;

* TreeNode right;

* TreeNode(int x) { val = x; }

* }

*/`Find the largest duplicate subtree in a binary tree For example, 1 / \ 2 3 / / \ 4 2 4 / 4 The following are two duplicate subtrees: 2 / 4 and 4`

but the former is the largest, thus return the root of the first subtree

- ajay.raj May 05, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 0of 0 votes

AnswersWrite a function that receives string with decimal number (i.e. all characters are decimal digits) and prints the sum of all possible substring-numbers, example:

- leonid.ge May 04, 2018 in UK

sum(“123”) = 123 + 12 + 23 + 1 + 2 + 3 = 167| Report Duplicate | Flag | PURGE

Credit Suisse Software Developer Algorithm - 0of 0 votes

AnswerGiven N number of Strings, generate all combination of these String's characters, these Strings must be N long, and must contain only one number of char from each string.

- sapadt May 04, 2018

example: "abc", "def", "ghi" --> adg, adh, adi, aeg ... cfg| Report Duplicate | Flag | PURGE

Morgan Stanley Software Developer Algorithm - 0of 0 votes

AnswersGiven a target string, an input request replaces the word after the given index a->b such as:

- ajay.raj May 04, 2018 in United States

Target string: "Hello world!"

Input:{s:0, a:Hello b: Goodbye}

Output:"Goodbye world!".

The requirement is that input be given to several words that need to be changed at one time: {{s:0,a:Hello,b:Goodbye},{s:11,a:!,b:?},{s:6 a: World,b:friend}}

And each modified index is based on the original unmodified target string so the end result is

"Goodbye friend?"| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 0of 0 votes

Answersgiven a n-ary tree, find the total distance from this node to any other nodes

- ajay.raj May 04, 2018 in United States

class TreeNode {

int val;

List<TreeNode> children;

TreeNode(int val) {

this.val = val;

children = new ArrayList<>();

}

}

public int findDistance(TreeNode root, TreeNode node) {

}| Report Duplicate | Flag | PURGE

Amazon Software Engineer - 1of 1 vote

AnswersHow many squares are inside a m*n rectangle where some grids in the rectangle were grey and the gray grid could not appear in the small squares.

- ajay.raj May 03, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon SDE1 - 1of 1 vote

AnswersGiven an int array, check if all the numbers can be divided into 5 consecutive numbers.

- ajay.raj May 03, 2018 in United States

Eg: [1,2,2,3,3,4,4,5,5,6] Yes: (1,2,3,4,5) (2,3,4,5,6)

Followup: ask if you know that all the numbers are between 1 and 13,

what's a good optimization.| Report Duplicate | Flag | PURGE

Amazon SDE1 - 1of 1 vote

AnswerYou have two matrixs, how to move the first matrix

(move up, down, left, and right) so that the two matrix in the two matrixs match most.`eg: matrix 1: matrix 2: 0 0 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0`

Then, after taking matrix1 (1 left shift + 1 down),

- ajay.raj May 03, 2018 in United States

the number of 1 in the match with matrix2 is 3| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

Answershow to check if two graphs are structurally identical

- ajay.raj May 03, 2018 in United States

class UndirectedGraphNode {

List<UndirectedGraphNode> neighbors;

UndirectedGraphNode() {

neighbors = new ArrayList<>();

}

}| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

AnswersTable: Customers

- prasad.hybris May 02, 2018 in United States

id | name

1|alice

2|bob

3|carol

Table: Orders

id | customer_id | content

1|1|House

2|2|car

3|2|dog

4|10|cow

please write a query which returns all of the invalid orders (where invalid means their customer_id does not have an associated customer)

4|10|cow| Report Duplicate | Flag | PURGE

Google Technical Support Engineer Database - 0of 0 votes

AnswersSuppose you have a list of tasks which need to be executed. Some of these tasks have dependencies which must be executed before they are. Please provide a method which, when given a list of tasks, will provide a valid ordering in return.

- prasad.hybris May 02, 2018 in United States

Example:

Input: [ A, B, C, D ]

A <- B, C

B <- C, D

D <- C

Return: [ C, D, B, A ]| Report Duplicate | Flag | PURGE

Google Technical Support Engineer Trees and Graphs - 0of 0 votes

AnswersThere are N (N > 20) team, each team will play 'M' (say M =3) league match against every other team. Design various classes, and write the code and algorithm to find the winner.

- CoolGuy May 02, 2018 in India

Note: One match can be played on a single day, as there is just one stadium.

Note: No team should play matches on consecutive days.

Note: Algorithm should come up with Quarter Final, Semi Final, and Final matches.

Follow-up Question: If N is odd or even.

How your design will be modified if there are 'S' no. of stadiums.| Report Duplicate | Flag | PURGE

Adobe SDE-3 - 1of 1 vote

Answersconvert a Sorted array to complete BST

- ajay.raj May 02, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

AnswersDesign a Twitter-like topic system so that the most popular topics can be retrieved from the system. A post can have one or more topics and these topics can be shared by multiple posts. (hint: thinking of scalability)

- fz May 01, 2018 in United States| Report Duplicate | Flag | PURGE

Software Engineer Software Design - 0of 0 votes

AnswersHow HP Customer Support Works for Users?

- markwood455 May 01, 2018 in United States for HP Customer Support| Report Duplicate | Flag | PURGE

HP Customer Service Sr. technical support - 0of 0 votes

AnswersGiven six digits, find the earliest valid time that can be displayed on a digital clock (in 24-hour format) using those digits.

- translink604 May 01, 2018

For example, given digits 1, 8, 3, 2, 6, 4 the earliest valid time is "12:36:48". Note that "12 : 34 : 68" is not a valid time.

Write a java method:

class Solution {

public String solution(int A, int B, int C, int D, int E, int F);

}

that, given six integers A, B, C, D, E and F, returns the earliest valid time in "HIT :mm: ss" string format, or "NOT POSSIBLE" if it is not possible to display a valid time using all six integers.

For example, given 1, 8, 3, 2, 6, 4 the function should return "12:36:48".

Given 0, 0, 0, 0, 0, 0, the function should return "00 : 00 : oo". Given 0, 0, 0, 7, 8, 9, the function should return "07:08:09".

Given 2, 4, 5, 9, 5, 9, the function should return "NOT POSSIBLE".

Assume that: • A, B, C, D, E and F are integers within the range [0..9].

Correct answer 1 point

Efficient solution 2 points| Report Duplicate | Flag | PURGE

- 0of 0 votes

AnswerGive a connected graph, no cycle,

- ajay.raj May 01, 2018 in United States

Find the node where the average distance from all other nodes is the smallest| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

AnswerInput: an int array without sorting, then do a binary search on it, and find the number of digits that cannot be found by binary search.

- ajay.raj May 01, 2018 in United States| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

Answers<key = "a"; val = "3"; depend_list = null;/>; <key = "b"; val = "a * a";

- ajay.raj May 01, 2018 in United States

Depend_list = {a};/>; <key = "c"; val = "a * b"; depend_list = {a,b};/>;

Lets output a map<key, value>,a -> 3, b -> 9, c -> 27

Follow-up questions: Make a statistic for all keys and corresponding map entries with the same value.| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

AnswersGiven an array, find an x such that all numbers less than x are equal to themselves. Numbers greater than it are equal to x, and all numbers add up to a target

- ajay.raj May 01, 2018 in United States

For example, [1 3 5 7 9] target=24, answer is8. Because when x=8, the array has only 9>8, so 1+3+5+7+8=24 is the closest to the target.| Report Duplicate | Flag | PURGE

Amazon SDE1 - 0of 0 votes

AnswerGive an N-length array with only 0 and 1 inside

- ajay.raj May 01, 2018 in United States

Requires to find the minimum number of conversions needed to convert the array to 0 before all 1.

The conversion is to change a 0 to 1 or a 1 to 0,

And the number of 0 and 1 in the converted array can be arbitrary.

Just find the minimum conversion step| Report Duplicate | Flag | PURGE

Amazon SDE1 - 1of 1 vote

AnswersAssume courses labeled by their index in an array. Given a list of pairs where the first element represents a prerequisite course required for the second course, derive an ordered list of courses.

- vmayer99 April 30, 2018 in United States| Report Duplicate | Flag | PURGE

Software Engineer Algorithm - 0of 0 votes

AnswersFor a given set of non-negative integers get the number of subsets that add up to a target value k.

- vmayer99 April 30, 2018 in United States| Report Duplicate | Flag | PURGE

Linkedin Software Engineer Algorithm - 0of 0 votes

AnswersFor a given array of integers compute the maximum sum of any range in the array. Then modify the function to find maximum product (note the effect of negatives on max product).

- vmayer99 April 30, 2018 in United States| Report Duplicate | Flag | PURGE

Linkedin 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