## Recent Interview Questions

- 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 - 0of 0 votes

AnswersWrite a function to compute n^k. (don't forget negative exponents)

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

Linkedin Software Engineer Algorithm - 1of 1 vote

AnswersPrint (or return) the longest movie title found by successively matching the last and first words in each title, joining to form new titles, given a file containing a list of movie titles.

- gsgy11 April 30, 2018 in United States

For example: 'OF MICE AND MEN' and 'MEN IN BLACK' join to form 'OF MICE AND MEN IN BLACK'.

You could further join 'OF MICE AND MEN IN BLACK' wth 'BLACK MASS' to form 'OF MICE AND MEN IN BLACK MASS'.

The longest title I found (at 143 characters is): WENT TO CONEY ISLAND ON A MISSION FROM GOD BE BACK BY FIVE WIVES THREE SECRETARIES AND ME WITHOUT YOU CANT TAKE IT WITH YOU WERE NEVER LOVELIER| Report Duplicate | Flag | PURGE

Google Software Engineer - 0of 0 votes

AnswersProblem:

- sarunreddy82 April 29, 2018 in United States

Insert + or – sign anywhere between the digits 123456789 in such a way that the expression evaluates to 100. The condition is that the order of the digits must not be changed.

e.g.: 1 + 2 + 3 – 4 + 5 + 6 + 78 + 9 = 100

I have below C solution - Can you please help me to convert to Java. I need this solution in Java.

#include<stdio.h>

#include<conio.h>

int findnumber(int i,int j)

{

int k;

int n;

for(k = 0; k < j; k++)

{

n = i % 3;

i = i / 3;

}

return n;

}

void main()

{

int i, j, k, current, result, operation;

clrscr();

for(i = 0; i < 19683; i++)

{

if(i%3 == 0)

continue;

current = 0;

result = 0;

for(j = 1; j < 10; j++)

{

k = findnumber(i,j);

if(k==0)

{

current = current * 10 + j;

}

else

{

result = result + (operation == 1 ? current : -current);

current = j;

operation = k;

}

}

result = result + (operation == 1 ? current : -current);

if(result == 100)

{

for(j = 1; j < 10; j++)

{

k = findnumber(i,j);

if(k==0)

printf("%d",j);

else

printf("%c%d",k==1?'+':'-',j);

}

printf("\n");

}

}

getch();

}| Report Duplicate | Flag | PURGE

xyz Java

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

Open Chat in New Window