## Algorithm Interview Questions

- 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

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

AnswersGiven a stream of integers, a value k and a value w, consider the integers in the window w and chop off greater k and smaller k elements from the window w. From the remaining elements, compute the average.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswersImplement the version control map system which takes the snapshot of the versions of data. Implement the following functions:

- neer.1304 July 03, 2019 in United States

put(key, value) -> puts the value again the key in the latest version of the map

get(key) -> get the value of the key for the latest version of the data

snapshot() -> take a snapshot and increment the version

getValVersion(version id, key) -> return value of the key of the particular version| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswerGiven various subsequences of an array, print the overall array:

- neer.1304 July 03, 2019 in United States

Example: [1, 3, 5], [1, 3, 9], [9, 5]

Array : [1, 3, 9, 5]| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswerA graph has N vertices numbered from 1 to N. We have two lists. One list M consisted of edges between vertices. The other list K consists of restricted paths. We have to add edges one by one from M and check whether the addition of the particular edge leads to a path between the restricted edges given in K. If it creates a path, we have to discard the edge.

- neer.1304 July 03, 2019 in United States

Example: N = 4; K = {(1, 4)}; M = {(1, 2), (2, 3), (3, 4)}. Here, addition of edge (3, 4) will create a path between 1 and 4. Hence we discard edge (3, 4)| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersYou are given 2 strings which are exactly same but 1 string has an extra character. Find that character.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswerYou are given an array of million numbers and provided a range of index (say left, right). For multiple queries, each with input left and right indexes, output the maximum in that range.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven (x, y) coordinates, create a function such that each coordinate is uniquely mapped to an integer. Also make sure that given an integer, you should be able to find (x, y) coordinates. So F(x, y) = z and also that inverse F(z) = (x, y).

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

Google Software Engineer Algorithm - 1of 1 vote

AnswerWe have to paint n boards of length {A1, A2…An}. There are k painters available and each takes 1 unit time to paint 1 unit of board. The problem is to find the minimum time to get

- neer.1304 July 03, 2019 in United States

this job done under the constraints that any painter will only paint continuous sections of boards, say board {2, 3, 4} or only board {1} or nothing but not board {2, 4, 5}.

Input : k = 2, A = {10, 10, 10, 10}

Output : 20.

Here we can divide the boards into 2

equal sized partitions, so each painter

gets 20 units of board and the total

time taken is 20.

Input : k = 2, A = {10, 20, 30, 40}

Output : 60.

Here we can divide first 3 boards for

one painter and the last board for

second painter.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven two numbers m and n. Find all numbers between these two numbers such that difference between adjacent digit is 1

- neer.1304 July 01, 2019 in United States

For ex m =0 n =22

O/p - 0,1,2,3,4,5,6,7,8,9,10,12,21| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersN number of balloons are kept at different heights. You are asked to find out number of arrows to burst them. When an arrow hits the balloon it goes one level down.

- Raj June 27, 2019 in United States

Assume that the balloons are having same size.

for example given the balloons heights as array(Array will be given in decreasing order of size) :

5 4 3 3 2 2 1 1 1

minimum number of arrows to shoot them is: 3

explanation:

using first arrow shoot: 5 4 3 2 1

using second arrow shoot: 3 2 1

using third arrow shoot: 1

Example 2:

5 4 2 1

minimum number of arrows to shoot them is: 2

using first arrow shoot: 5 4

using second arrow shoot: 2 1

Expecting the solution to be in O(1) space complexity.| Report Duplicate | Flag | PURGE

Walmart Labs Java Developer Algorithm - 0of 0 votes

AnswersIn a garden, there are several apples trees planted in a grid format. Each point (i,j) in the grid has |i| + |j| apples.

Allie can buy a square plot centred at (0,0). Find the minimum perimeter of the plot (1 unit having length = 1) such that she can collect at

least X apples. All plants on the perimeter of the plot are also included.

Sample:

- bertram_gilfoyle June 27, 2019 in India`Input = 1 Output = 8 input = 11 Output = 8 Input = 13 Output = 16`

| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm - 0of 2 votes

AnswersGiven an array of integers A. calculate the sum of A[i] %A[j] for all possible i,j pair. return sum%(10^9+7) as an output solve this problem on o(n).

- Dhioyt June 19, 2019 in India

input :-

A=[1,2,3]

Output:-

5

Explanation:-

(1%1)+(1%2)+(1%3)+(2%1)+(2%2)+(2%3)+(3%1)+(3%2)+(3%3)| Report Duplicate | Flag | PURGE

Amazon SDE1 Algorithm - 1of 1 vote

AnswerPrint an unbalanced binary tree in level order with new lines after each level.

- CoderDude7 June 17, 2019 in United States| Report Duplicate | Flag | PURGE

Bloomberg LP Python Developer Algorithm - 0of 0 votes

AnswersSay you have two large files (100 TB each) and only 1 MB of RAM. What's an efficient algorithm that will print the missing lines (diff)? The files don't necessarily contain duplicates.

- CoderDude7 June 17, 2019 in United States

The two files are not sorted and could have different ordering in both files.

e.g.:

File1 File2

A B

B A

C C

D E

F D

F

Output:

File 2: E

The input are two large files (containing strings).

The output is a list of strings telling you the presence of a line in File X and not in File Y.| Report Duplicate | Flag | PURGE

Bloomberg LP Python Developer Algorithm - 0of 0 votes

AnswersP0, P1, ...., Pn players in tournament. In first level, P0 plays with P1, P2 plays with P3 and so on. In level 2, Winner of P0,P1 plays with winner of P2,P3. For i,j output level in which they will face each other assuming they win all games.

- neer.1304 June 11, 2019 in United States| Report Duplicate | Flag | PURGE

Curefit SDE-2 Algorithm - 1of 1 vote

AnswersGiven directory change command -

- neer.1304 June 10, 2019 in United States

cd a/b/../c/d/e/../../

Output the visit count for each directory such as -

Root - 1

a - 2

b - 1

c - 2

d - 2

e - 1| Report Duplicate | Flag | PURGE

Amazon SDE-3 Algorithm - 0of 0 votes

AnswersGiven a nested list of integers, return the sum of all integers in the list weighted by their depth.

- koustav.adorable June 09, 2019 in United States

Each element is either an integer, or a list -- whose elements may also be integers or other lists.

Different from the question where weight is increasing from root to leaf, now the weight is defined from bottom up. i.e., the leaf level integers have weight 1, and the root level integers have the largest weight.

Example 1:

Input: [[1,1],2,[1,1]]

Output: 8

Explanation: Four 1's at depth 1, one 2 at depth 2.

Example 2:

Input: [1,[4,[6]]]

Output: 17

Explanation: One 1 at depth 3, one 4 at depth 2, and one 6 at depth 1; 13 + 42 + 6*1 = 17.| Report Duplicate | Flag | PURGE

SDE-2 Algorithm - 0of 0 votes

AnswersGiven range of routing numbers, determine which bank it belongs to.

- neer.1304 June 08, 2019 in United States

Ex-

I/p -(123400,123500, BOA), (12538, 12548, GCU)…

For 123450 - Output BOA

12540 - Output GCU| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

Answerwrite a JSON validator

- boony June 04, 2019 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 0 votes

AnswersGiven multiple tuples in the form of (A,B) where A is the parent and B is the child in a binary tree, find if the input is valid or not. 4 error conditions were provided:

- neer.1304 May 31, 2019 in United States

1. If a parent has more than 2 children,

2. If duplicate tuples entered,

3. If the tree has a cycle,

4. If more than one root possible.

For violation of multiple validity conditions, print the condition coming first in the above order.

If the input is valid, print the tree in a serial representation. For eg: If input is (A,B), (B,C), (A,D), (C,E) , output: (A(B(C(E)))(D))| Report Duplicate | Flag | PURGE

Swiggy SDE-3 Algorithm - 0of 0 votes

AnswersGiven character a-z find out nth permutation. Where all permutation are only ascending. For e.g

- neer.1304 May 31, 2019 in United States

Given characters a,b,c. valid permutations are : a,b,c,aa,ab,ac,bb,bc,cc,aaa,aab,aac,abb,acc,baa,bab,bac,bbb,bbc,bcc,caa,cab,cac,cbb,cbc,ccc

Ex- 4th permutation is : aa| Report Duplicate | Flag | PURGE

Swiggy SDE-3 Algorithm - 0of 0 votes

AnswersIn a binary tree if the neighbours are set on fire for every node , find the path to optimally set the entire tree on fire.

- neer.1304 May 31, 2019 in India| Report Duplicate | Flag | PURGE

Swiggy SDE-2 Algorithm - 0of 0 votes

AnswerGiven an input stream of Swiggy order timestamps and costs, at any instant find the costliest order in the last X mins

- neer.1304 May 31, 2019 in India| Report Duplicate | Flag | PURGE

Swiggy SDE-2 Algorithm - 1of 1 vote

AnswersYou have a plot with a limited amount of points on it.

Find the cluster of points, which contains the biggest amount of point grouped together.

Conditions:

The cluster means, that points are placed not farther than 5 units (Can be measured px, cm, etc.) between each other. The distance is calculated by where`|x1-x| < 5`

and

`|y1-y| < 5`

The cluster should contain at least 3 points.

- denis.zayats May 30, 2019 in United States

If there are a few clusters with the same amount of points - return all of them.

Example:

The points are:

(15,116), (1345, 123), (456, 11), (34, 17), (19, 112), (556, 111), (454, 15), (12, 120).

In this case, the best cluster is (15,116), (19, 112), (12, 120)| Report Duplicate | Flag | PURGE

Google SDE-3 Algorithm - 0of 0 votes

AnswerYou are given an N-Dimensional list with 2 methods:

- neer.1304 May 27, 2019 in United States

i) getDim -> returns the dimensions .e.g [5,4,3].

ii) getElement([i,j,k]) -> return list[i][j][k] . You have to implement a method to sum all elements in the list.| Report Duplicate | Flag | PURGE

Linkedin Senior Software Development Engineer Algorithm - 0of 0 votes

AnswersLCA of directed graph.

- shushantsharan May 20, 2019 in India| Report Duplicate | Flag | PURGE

Flipkart SDE1 Algorithm - 5of 5 votes

AnswersTree Game

- aonecode May 17, 2019 in United States

class TreeNode {

TreeNode parent; //parent node

TreeNode left; //left child

TreeNode right; //right child

}

Two people in a game, player scores by claiming nodes in binary tree, tree node class as shown above.

The player who eventually owns more nodes wins the game.

Player A and B each claims a node at first.

After the first round, a player will only be able to claim a node adjacent to any node owned by himself.

A tree node is adjacent to its parent, left right and right child.

A node owned cannot be re-claimed.

End game when all nodes are owned.

If player A gets the first claim at node N, find whether it is possible for player B to win.

If yes, find out which node player B should claim at his first move.

Follow up: if player B takes the first hand instead, which node should he pick?| 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