## Algorithm Interview Questions

- 0of 0 votes

AnswersYou are given a directed cyclic graph represented by an adjacency matrix. The graph has at least one terminal node (i.e. the node with no outgoing edges).

Each edge of the graph is assigned a positive integer representing a probability of taking this edge. E.g. if you have 3 outgoing edges with numbers 3, 2, and 4, this means that the prob. of taking these edges are: 3/9, 2/9 and 4/9, respectively.

You need to find the probability of reaching each terminal node from the starting node 0.

Example:

adjacency matrix 5x5:`m = {{0 1 0 0 1}, {0 0 3 2 0}, {4 0 0 1 0}, {0 0 0 0 0}, {0 0 0 0 0}}`

so we have two terminal nodes here: 3 and 4

- pavel.emeliyanenko@toptal.com May 11, 2021 in United States

we can take the following paths:

0 -> 1 -> 3 = probability: 1/2*2/5 = 1/5

0 -> 1 -> 2 -> 3 = probability: 1/2*3/5*1/5 = 3/50

0 -> 1 -> 2 -> 0 -> 1 -> 3 ... and so on

or to the node 4:

0 -> 4: probability: 1/2

0 -> 1 -> 2 -> 0 -> 4: probability 1/2*3/5*4/5*1/2 = 3/25

and so on, summing up probabilities of all possible paths we get:

total probability to reach node 3: 13/38

total probability to reach node 4: 25/38| Report Duplicate | Flag | PURGE

Microsoft SDE-2 Algorithm - 3of 3 votes

AnswersGiven a stream of integers where probability of a smaller number being first in stream is more than probability of larger number in stream.

- James March 17, 2021 in United States

Implement a method that returns true if you have already seen that element in stream otherwise return false.

eg. stream could look like 1,2,3,5,6,11,7,3......

more examples - 3,4,1,2,5,9,22,12

---

I explained using a hashset but that solution was not viable because of the space requirement.

I don't think I handled this question well. So would love people's opinion on it.| Report Duplicate | Flag | PURGE

Microsoft Algorithm - 0of 0 votes

AnswersAs we all know that poker cards have four suites: Spades, Hearts, Clubs and Diamonds with figures from 1 to 13.

- holmespanda2 December 28, 2020 in United States

Now you are given a set of poker cards, you can pick any one card as the first card. And except for the first card, you can only pick the card that has the same suit or figure with the previous one.

Return the max number of cards you can.

For example: [(H, 3), (H, 4), (S, 4), (D, 5), (D, 1)], it returns 3 as follows: (H,3)-->(H,4)-->(S,4)| Report Duplicate | Flag | PURGE

Amazon SDE-3 Algorithm - 0of 0 votes

AnswersWhat are the steps of the algorithm with order O(m log (mn)) for finding k-th smallest element (or median) of 2D array [1..M] [1..N] where each row of this matrix is sorted and independent from all other rows (ascending order, distinct elements)?

- Google Q November 20, 2020 in United States| Report Duplicate | Flag | PURGE

N/A IIT Exam Algorithm - 0of 0 votes

AnswerPower list has the following conditions

- coder October 16, 2020 in India

first element should b1

Next L2 element should be 2

Next L3 element should be 3

Next L4 element should be 4

Next L5 element should be 5

Next L6 element should be 6

Next L7 element should be 7

Next L6 element should be 6

...

Next L1 should be 1

e.g.,

1 2 3 4 5 6 6 7 6 5 4 3 2 1 -- power list

1 2 3 4 5 6 7 6 5 4 3 2 11 - not a power list since last two elements are 1 .

Wrte a code to find out whether arr [] represents a power list or not.| Report Duplicate | Flag | PURGE

Algorithm - 0of 0 votes

AnswerGiven a binary tree, find the maximum product path.

- cricketRipunjoy October 09, 2020 in India

In other words, find the path inside the binary tree which has maximum product.| Report Duplicate | Flag | PURGE

Wells Fargo Analyst Algorithm - 0of 0 votes

AnswersImplement an algorithm that takes in a string containing a parenthesized expression and prints it out with all sibling expressions at the same indent level, each on its own line.

- Priyanka September 14, 2020 in United States

Definitions:

A parenthesized expression consist of an opening parenthesis, one or more expressions separated by one or more spaces, and a closing parenthesis.

An expression is either a word or a parenthesized expression.| Report Duplicate | Flag | PURGE

Snap Inc Software Developer Algorithm - 0of 0 votes

AnswersExamples:

- kamal suthar August 26, 2020 in India

(((abc))) --> abc

(ab(c)) --> ab(c)

(abc09%(c)) --> abc09%(c)

ab(c) --> ab(c)

(ab)c --> (ab)c

abc(c)) → INVALID

(abc)(def) --> (abc)(def)

(abc)typ(def) --> (abc)typ(def)

((abc)(def)) --> (abc)(def)| Report Duplicate | Flag | PURGE

Amazon Computer Scientist Algorithm - 0of 0 votes

AnswersYou are in charge of designing a small, in-memory social network, with the basic functionality of adding friendship

- tassecarriere August 26, 2020 in United States

between two people via an AddFriendship function, and a GetSuggestedFriends function for a particular user in the

network. The criteria is to pick someone with whom the given user has the most number of friends in common.

Start by discussing the most suitable data structure, and implement all the objects and functions.| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 2of 2 votes

AnswersImplement binary addition of two strings.

- fruktoed August 14, 2020 in UK, London

For example "101101" and "111101" equal "1101010"

You cannot use any type conversion, operate only with strings.| Report Duplicate | Flag | PURGE

Facebook Android Engineer Algorithm - 0of 0 votes

Answersfind target in chess board with given start position of knight

- thosh July 31, 2020 in United States| Report Duplicate | Flag | PURGE

Facebook Software Engineer / Developer Algorithm - 0of 0 votes

AnswersBob and Alice have teamed up on a game show. They won the first

- shashankesh July 23, 2020 in India

round, allowing them access to a maze with hidden gold. If Bob can

collect all the gold coins and deliver them to Alice's position, they can

split the gold. Bob can move North⇆South or East⇆West as long as he

stays in the maze and the cell is not blocked. The task is to determine

the shortest path Bob can follow to collect all gold coins and deliver

them to Alice. If it is not possible, return -1.

You will be given an n × m array where each of the values ∈ {0, 1, 2}

representing open, blocked and open with a gold coin. Alice's position is

given as (x,y) = (row, column). Bob starts at the top left in cell (0, 0).

For example, maze = [[0,2,1],[1,2,0],[1,0,0]] with Alice at (2,2) is

represented as follows:

0 2 1

1 2 0

1 0 0

minMoves has the following parameter(s):

maze[maze[0][0],...maze[n-1][m-1]]: a 2D array of integers

x: an integer denoting Alice's row coordinate

y: an integer denoting Alice's column coordinate

Constraints

1 ≤ n, m ≤ 100

0 ≤ the number of coins ≤ 10

1 ≤ x < n

1 ≤ y < m

The first line contains an integer n, the numbers of rows in maze.

The second line contains an integer m, the number of columns in

maze.

Each of the next n lines contains m space-separated integers

describing the cells of each row in maze.

The next line contains an integer x.

The next line contains an integer, y.

Sample Input 0

3

3

0 2 0

0 0 1

1 1 1

1

1

Sample Output 0

2

Explanation 0

The shortest path Bob can take is (0, 0) → (0, 1) → (1, 1).

Sample Input 1

3

3

0 1 0

1 0 1

0 2 2

1

1

Sample Output 1

-1

Explanation 1

It is not possible for Bob to reach Alice, so we return −1.

Sample Input 2

3

3

0 2 0

1 1 2

1 0 0

2

1

Sample Output 2

5

Explanation 2

The shortest path Bob can take is (0, 0) → (0, 1) → (0, 2) → (1, 2) → (2, 2) → (2, 1).| Report Duplicate | Flag | PURGE

Adobe SDE1 Algorithm - 0of 0 votes

AnswersGiven a array of integers find the index which partitions the array to two with high numbers and low numbers. For example [5, -1, 3, 8,6] the index 3 will partition the array to [5,-1,3] and [8,6] all the numbers in the second partition are greater than first. The solution has to work in O(n).

- neer.1304 July 15, 2020 in United States| Report Duplicate | Flag | PURGE

Microsoft Algorithm - 0of 0 votes

AnswersGiven an n-ary tree and some queries for the tree, in every query you’ll be given a node you are supposed to print preorder traversal of the subtree rooted at that node.

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

Amazon SDE-2 Algorithm - 3of 3 votes

AnswersYou have an array of numbers. You have to give the range in which each number is the maximum element. For Example, If array is 1, 5, 4, 3, 6 The output would be

- neer.1304 July 12, 2020 in United States

1 [1, 1]

5 [1, 4]

4 [3, 4]

3 [4, 4]

6 [1, 5]| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswerGiven an array of billion of numbers. Billions of queries are generated with parameters as starting and an ending index. Both these indices lie within that array. Find the maximum number between these two indices in less than O(N)

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersMultiply two numbers without using * and only be using bitwise operations

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersDisplay nodes of a tree in level order using DFS

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersImplement a deque using stacks

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersGiven the entire dictionary of English words, what data structure will you use to efficiently store and match the custom regex string like "D*sk", where * represents any single alphabet, and return the list of matched words?

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswerGiven a skewed tree, an insect is sitting at the root of the tree at t = 0min, every minute insect steps down in the tree, find the probability of the insect being at any node at t = infinity. Once I came up with a solution various other complexities has been added to the problem such as: What if the tree is binary tree (written code for this) What if three is n-ary What if it is now a directed acyclic graph Handle cases that there can be more than one entry point There can be more that one way to reach a node

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersGiven a binary tree of numbers and a search number has given, find out first occurence of that number and smallest distance from root node. if you have given k search numbers find their occurence and nearest from root node in a single walk.

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersGiven a string of numbers put commas so that it become readable like million trillion thousands. eg 1010503 ===> 1,010,503

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

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersGiven an array of 0s and 1s. find maximum no of consecutive 1s. If you have given chance to flip a bit to 1 such that it maximises the consecutive 1s. find out that flipped bit and after flipping that bit maximum no of consecutive 1s. Above question but you have options to flip k bits.

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

Amazon SDE-2 Algorithm - 0of 0 votes

Answers/**

- Tekfiesta June 23, 2020 in United States

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

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

Example 1:

Input: [[1,1],2,[1,1]]. - 1 at depth 2, 1 at depth 2, 2 is at depth 1, 1 at depth2, 1 at depth 2

// [1] - at depth 1, [[1]] - at depth 2, [[[[1]]]] at depth 4

Output: 10

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

1*2 + 1*2 + 2*1 + 1*2 + 1*2 = 10

Example 2:

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

Output: 27

Explanation: One 1 at depth 1, one 4 at depth 2, and one 6 at depth 3; 1*1 + 4*2 + 6*3 = 27.

[[[1]]] - at depth 3

*/

/**

* // This is the interface that allows for creating nested lists.

* // You should not implement it, or speculate about its implementation

* public interface NestedInteger {

* // Constructor initializes an empty nested list.

* public NestedInteger();

*

* // Constructor initializes a single integer.

* public NestedInteger(int value);

*

* // @return true if this NestedInteger holds a single integer, rather than a nested list.

* public boolean isInteger();

*

* // @return the single integer that this NestedInteger holds, if it holds a single integer

* // Return null if this NestedInteger holds a nested list

* public Integer getInteger();

*

* // Set this NestedInteger to hold a single integer.

* public void setInteger(int value);

*

* // Set this NestedInteger to hold a nested list and adds a nested integer to it.

* public void add(NestedInteger ni);

*

* // @return the nested list that this NestedInteger holds, if it holds a nested list

* // Return null if this NestedInteger holds a single integer

* public List<NestedInteger> getList();

* }

*/

public int depthSum(List<NestedInteger> nestedList) {

}| Report Duplicate | Flag | PURGE

8x8 Applications Developer Algorithm - 0of 0 votes

Answers Given Two array with the preference of two developers say Ying and Ming, both need to create a team according to the preference, you need to return the String containing the Initial of the team the developers got selected it Note: Ying will always got the chance to make a first pick? {{{Example says Ying Preference table [1,2,3,4] and Ming Preference table is [1,2,3,4] than the Output should be 'YMYM' 2nd Example Ying Preference input array [1,3,2] and Ming Preference input array is [3,1,2] than the String return would be 'YYM'. - sam21088 June 22, 2020 in India for PWM| Report Duplicate | Flag | PURGE

Morgan Stanley Java Developer Algorithm - 0of 0 votes

AnswersGiven array of ball size we need to return the sum of shadow balls

- Dinesh Pant June 01, 2020 in India

For example

7 3 2 8 1

shadow ball of 7 ---> 3, 2, 1

shadow ball of 3 ---> 2, 1

shadow ball of 2 ---> 1

shadow ball of 8 ---> 1

Output ---> 3+2+1+1 --> 7

Complexity should be better than 0(n^2)| Report Duplicate | Flag | PURGE

Microsoft SDE-3 Algorithm - -4of 4 votes

AnswersGiven an integer array and an integer K, find the number of sub arrays in which all elements are less than K.

- neer.1304 June 01, 2020 in United States

Follow up -

Given an integer array and an integer K, find the number of non overlapping unordered pairs of sub arrays in which all elements are less than K.| Report Duplicate | Flag | PURGE

Facebook Software Engineer Algorithm - 0of 0 votes

AnswersQ.1 Rather than separate T[1…m] into two half size arrays for the purpose of merge sorting, we

- ninjaaarashi May 23, 2020 in United States

might choose to separate it into three arrays of size x%3, (x+1)%3, and (x+2)%3, to sort each of

these recursively, and them to merge the three sorted arrays. Give a more formal description of

this algorithm and analyze its execution time. Justify your answer with example.| Report Duplicate | Flag | PURGE

Algorithm Arrays Data Structures Programming Skills - 0of 0 votes

AnswersGiven two very large files – first contains Id and name, another one contains Id and address – you need to create 3rd file which will contain id, name, and address. -First, ask the clarifying questions and then tell the approach.

- neer.1304 May 19, 2020 in United States| Report Duplicate | Flag | PURGE

Microsoft Senior Software Development 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