## Algorithm Interview Questions

- 0of 0 votes

AnswersIn a 2-D matrix of m*n select m-1 elements from each row such that that the resulting sum is minimum and each column is selected atleast once.

- neer.1304 July 20, 2019 in United States

Ex -

2 3 5

3 2 5

4 4 7

Selecting (2,3) from 1st row, (2,5) from 2nd row and (4,4) from 3rd row would result in minimum sum of 20| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 1of 3 votes

AnswersQuestion: Can you break the given string into words, provided by a given hashmap of frequency of word as <word: n>

- nitinguptaiit July 18, 2019 in United States

Example:

HashMap -> {"abc":3, "ab":2, "abca":1}

String: abcabcabcabca

output: Yes; [ abc, abc, abc , abca ]

Example:

HashMap -> {"abc":3, "ab":2}

String: abcabab

output: No

Example:

HashMap -> {"abc":3, "ab":2, "abca":1}

String: abcx

output: No| Report Duplicate | Flag | PURGE

Facebook Algorithm - 0of 0 votes

AnswersFind LCA for list of nodes of a tree

- neer.1304 July 17, 2019 in United States

Function defined as below -

TreeNode findLCA(TreeNode root, List<TreeNode> nodes)| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswerA set of points in the 2D plane. Find the first k number of points with the shortest distance to the point (0, 0), where k is a positive integer.

- fz July 13, 2019 in United States

e.g.

Input

{[-16, 5], [-1, 2], [4, 3], [10, -2], [0, 3], [-5, -9]}

k = 3

Output:

{[-1, 2], [0, 3], [4, 3]}

.| Report Duplicate | Flag | PURGE

Algorithm - 0of 0 votes

AnswersA matrix represents a sequence of travel points. One only can travel either left/right or up/down. Some of those points are dead points which one can't travel any further. There is a destination point in the matrix. Find the shortest path from the top left point (1, 1) to the destination.

- fz July 13, 2019 in United States

e.g.

Input

[

[‘O’, ‘O’, ‘O’, ‘O’],

[‘D’, ‘O’, ‘D’, ‘O’],

[‘O’, ‘O’, ‘O’, ‘O’],

[‘X’, ‘D’, ‘D’, ‘O’],

]

Output

Route is (0, 0), (0, 1), (1, 1), (2, 1), (2, 0), (3, 0) The minimum route takes 5 steps.| Report Duplicate | Flag | PURGE

Algorithm - 0of 0 votes

AnswersGiven a positive integer array and a positive integer. Find a pair of integers in the array so that the sum of the pair is the largest one among all pairs not larger than the given integer.

- fz July 12, 2019 in United States

e.g.

Input

{90, 85, 75, 60, 120, 150, 125}

d: 250

Output:

{90, 125}| Report Duplicate | Flag | PURGE

Algorithm - 0of 0 votes

AnswersWrite a program to find number of words in a file not using any standard tokenizing API's.

- neer.1304 July 12, 2019 in United States| Report Duplicate | Flag | PURGE

Boomerang Commerce Algorithm - 0of 0 votes

AnswersGiven n, you will be getting stream of sets each set may contain like (1,3,4,5) which signifies that 1,3,4,5 are related. Similarly you may get like (6,7) , (1,8).

- neer.1304 July 12, 2019 in United States

And you will be asked to find whether 1 & 4 are related => Yes (as they are from same set).

3 & 8 are related => yes as 8 & 3 are related through 1.

5 & 7 are related =>No| Report Duplicate | Flag | PURGE

Boomerang Commerce Algorithm - 0of 0 votes

AnswersImplement a function which accepts a number and returns top 10 big numbers the function is called with so far;

- vasa.v03 July 10, 2019 in India

If we call the function with 1.. to 100 , for the call function(100) the function will return 91 to 100 in reverse order since they are top 10 biggest number so far| Report Duplicate | Flag | PURGE

British Telecom Software Engineer Algorithm - 0of 0 votes

AnswersAn array is called a Good Array if the elements continually increasing or continually decreasing or continually decrease and then increase.

- neer.1304 July 09, 2019 in United States

Question 1: He asked how will you tell whether a given array is a good array or not.

Question 2: Given an array, you are allowed to add any number of values to each of the element. Find the minimum sum of elements that can make the array a good array.| Report Duplicate | Flag | PURGE

Nutanix Algorithm - 0of 0 votes

AnswersA software-based LRU Cache replacement algorithm has to be implemented for a Single Touch/Multi-Touch Cache. Single Touch can occupy at least 30% of the total cache space. A key accessed for the first time will appear in the Single Touch cache. When accessed multiple times, this will be part of the multi-touch cache. Also, multiple threads will access the cache. Following are the functions allowed for cache access.

- neer.1304 July 09, 2019 in United States

1. get(key): returns the value against the key if present else return NULL

2. set(key, value): set the value against the key| Report Duplicate | Flag | PURGE

Nutanix Algorithm - 0of 0 votes

AnswersGiven a tree, and there will be treasure in one of the nodes. We can query any node, it will return the node itself if it contains the treasure or it returns the branch which leads to the treasure. we need to find out the treasure in minimum number of queries.

- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE

Nutanix Algorithm - 0of 0 votes

AnswerImagine someone maliciously duplicated every file on your computer, and completely randomized their names and locations on your hard drive. Discuss an efficient way to clean up your drive of all these duplicates.

- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE

Nutanix Algorithm - 0of 0 votes

AnswersTwo very very large files F1, F2 containing key, value pairs. Write these key, values to a third file without any duplicates.

- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE

Cohesity MTS Algorithm - 1of 1 vote

AnswersBuild a key-value data structure that allows the user to take a snapshot of the data. The user can read the key-value store from any snapshot.

- neer.1304 July 09, 2019 in United States

Structure has the normal key/value like methods plus something like

snapshot = dataStructure.takeSnapshot()

value = dataStructure.get(key, snapshot)

void dataStructure.deleteSnapshot()| Report Duplicate | Flag | PURGE

Rubrik MTS Algorithm - 0of 0 votes

AnswersA table has some number of balls at various positions on a line segment. 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

- neer.1304 July 09, 2019 in United States| Report Duplicate | Flag | PURGE

Rubrik MTS Algorithm - 1of 1 vote

AnswersGiven a list L of video names and their watch rates, write a function that will return the videos with the top 10 watch rates. Video names may appear more than once.

- neer.1304 July 03, 2019 in United States

Example:

L = [(‘abc’, 10), (‘def’, 15), (‘ghi’, 10), (‘abc’, 12), …, (‘xyz’, 100)]

The function should return [‘xyz’, ‘abc’, …, ‘def’, ‘ghi’]| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersWrite a function that takes a list L and returns a random sublist of size N of that list. Assume that the indexes must be in increasing order. That is, you cannot go backwards.

- neer.1304 July 03, 2019 in United States

Example:

L = [1, 2, 3, 4, 5]

N = 3

The function should return one of these lists:

[1, 2, 3]

[1, 2, 4]

[1, 2, 5]

[1, 3, 4]

[1, 3, 5]

[1, 4, 5]

[2, 3, 4]

[2, 3, 5]

[2, 4, 5]

[3, 4, 5]| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersConsider an undirected tree with N nodes, numbered from 1 to N. Each node has a label associated with it, which is an integer value. Different nodes can have the same label. Write a function that, given a zero indexed array A of length N, where A[j] is the label value of the (j + 1)-th node in the tree and a zero-indexed array E of length K = (N – 1) * 2 in which the edges of the tree are described, returns the length of the longest path such that all the nodes on that path have the same label. The length is the number of edges in that path.

- neer.1304 July 03, 2019 in United States

Example:

A = [1, 1, 1, 2, 2]

E = [1, 2, 1, 3, 2, 4, 2, 5]

This tree is shown below. A node follows the form label, value.

----------1, 1

-----1, 2 1, 3

2, 4 2, 5

The function should return 2, because the longest path is 2->1->3, and there are 2 edges in this path.

Assume that 1 <= N <= 1000 and each element of the array A is an integer in the range [1, 1000000000].| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersGiven a string A consisting of n characters and a string B consisting of m characters, write a function that will return the number of times A must be stated such that B is a substring of the repeated A. If B can never be a substring, return -1.

- neer.1304 July 03, 2019 in United States

Example:

A = ‘abcd’

B = ‘cdabcdab’

The function should return 3 because after stating A 3 times, getting ‘abcdabcdabcd’, B is now a substring of A.

You can assume that n and m are integers in the range [1, 1000].| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven 1-D list of co-ordinates determine if interval (a,b) is covered

- neer.1304 July 03, 2019 in United States

Ex - [(2,5), (5,7),(1,4)] and interval = (1,6)

return true

Explanation - Points 1 to 6 lies in list of interval given 1 to 4. 2 to 5 and 5 to 7.

[(1,4),(6,7),(2,5)] and interval - (1,6)

return false

Explanation - Distance between 5 to 6 is not covered in the list given so return false| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswerCompare two documents(string array) based on n grams.

- neer.1304 July 03, 2019 in United States

e.g doc1 – Today is Sunday.

doc2 – Today is Saturday

if n = 2 then number of duplicates is 1 (Today is)

if n = 1 then number of duplicates is (Today, is)

if n = 3 duplicates is 0| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven a bench with n seats and few people sitting, tell the seat number each time when a new person goes to sit on the bench such that his distance from others is maximum

- neer.1304 July 03, 2019 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswersGiven a room with thief on left side of the room with finite number of sensors. He has to reach on right side missing the sensors. Each sensor is placed at any random point in the room and has its coverage in the radius r. Find out if the thief can reach to the right side without touching the range of any sensor.

- neer.1304 July 03, 2019 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersGiven an infinite chessboard, find minimum no. of steps for a knight to reach from the origin to (x, y).

- neer.1304 July 03, 2019 in United States

Extension A list of forbidden coordinates are introduced where knight can’t reach. Handle this in your code. Make sure the infinite loop is handled since the board is infinite.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven a matrix of people(denoted by small alphabets) and bikes(denoted by capital alphabets), find the nearest bike for a given person.

- neer.1304 July 03, 2019 in United States

How will you change your solution if you have to find bikes for a set of people? (assuming multiple bikes can be at the same distance from 1 person)| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswersGiven an array of n integers, find the lexicographically smallest subsequence of length k.

- neer.1304 July 03, 2019 in United States| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswersGiven a list of player names and their scores – {Carl, 70; Alex, 55; Isla, 40}, design a data structure that can support following modules in optimal time-

- neer.1304 July 03, 2019 in United States

i) updateEntry(string name)

ii) getEntryFromRank(int rank)| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven an input stream of boolean values, design a data structure that can support following modules in optimal time-

- neer.1304 July 03, 2019 in United States

i) setTrue(index)

ii) setFalse(index)

iii) setAllTrue()

iv) setAllFalse()

v) getIndex(index)| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 1of 1 vote

AnswerGiven two strings, A and B, of equal length, find whether it is possible to cut both strings at a common point such that the first part of A and the second part of B form a palindrome.

- neer.1304 July 03, 2019 in United States

Extension1. How would you change your solution if the strings could be cut at any point (not just a common point)?

Extension2. Multiple cuts in the strings (substrings to form a palindrome)? Form a palindrome using a substring from both strings. What is its time complexity?| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm

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

Open Chat in New Window