## Algorithm Interview Questions

- 0of 0 votes

AnswerWhat are Parameters, and types of Parameters? How do linking Parameters with Datasets work? How to create parameters for Data sources? How to creating parameters for file paths.

- Ashish Roe August 31, 2023 in United States| Report Duplicate | Flag | PURGE

Accenture Data Engineer Algorithm - 0of 0 votes

Answersalgorithm

- swastikadelhi943 November 22, 2022 in India for callgirl| Report Duplicate | Flag | PURGE

Call Girls In Delhi 9717510588 Cash Payment Unlimited Short Anal Sex Mahipalpur Call Girls In Delhi 9717510588 Cash Payment Unlimited Short Anal Sex Mahipalpur Algorithm - 0of 0 votes

AnswersGiven a list of hotelId, parentHotelId and a score retrieve the top k root parentHotelIds with the highest scores:

- dssd November 27, 2021 in Amsterdam

[{0, 1, 10}, {1, 2, 20}, {3, 4, 10}, {7, 8, 5}] K = 2

Result: [[2, 30], [4,10]]| Report Duplicate | Flag | PURGE

Booking.com Software Engineer Algorithm - 0of 0 votes

AnswersGiven an array of n strings with length m return true if there is one pair such that there is only one difference between the words, e.g, abcd and abce would yield true, but abcd and abdd would be false.

- jllangston November 24, 2021 in United States

I could not think in the space of the interview how to optimize the algorithm| Report Duplicate | Flag | PURGE

Google Software Engineer Algorithm - 0of 0 votes

AnswersFinding Amsterdam Stock Exchange

- wanabeunknown November 08, 2021 in Netherlands

Ian and Sylvia are planning a visit to Amsterdam. They want to plan their sight seeing route. Sylvia is reading from the touristic guide and Ian is writing the list with sights.

Sylvia is giving Ian 2 commands:

- Add <sight> -> to add this sight on top of the visiting stack of sights to be planned for visit.

- Remove -> to move the sight on top of the visiting stack in their itinerary.

Ian wants to be able to also add, at the end of the day, a visit to the Amsterdam Stock Exchange Building, as it is the oldest modern exchange in the world, built in 1602.

To be able to do this, he wants to optimize the route that they are planning, without Sylvia's knowledge.

Whenever she is not watching, he can rearrange the stack of sights, so that, if Sylvia is asking to move the top sight to the itinerary, the itinerary list will still have the optimal path.

Tell Ian the minimum number of times he needs to reorder the sights so that he can achieve his goal.

Sights are numbered from 1 to n, in the order of the optimal path that Ian wants to take.

It is guaranteed that a sight will be added, before it is needed for the sight to be moved to the itinerary.

Clarifications Optimal path is the path from 1 n Amsterdam Stock Exchange is considered to be the sight with number n. You have a time limitation of 60 minutes.

Input :

The first line of input contains the integer n (1 <= n <= 10^6) — the number of sights to be planned Each of the next 2n lines of input starts with a string "add" or "remove".

If the line starts with the "add", an integer x (1 <= x <= n) follows, indicating that Ian should add the sight with number x to the top of the stack.

It is guaranteed that exactly n lines contain "add" operations, all the sights added are distinct, and n lines contain "move" operations.

It is also guaranteed that a sight is always added before it is required to be moved.

Output:

Print the minimum number of times Ian needs to reorder the sights to successfully achieve his goal.

Examples:

Input:

3

add 1

remove

add 2

add 3

remove

remove

Output:

should be 1.

Note In the first sample, Ian should reorder the sights after adding sight 3 to the stack.

Input:

7

add 3

add 2

add 1

remove

add 4

remove

remove

remove

add 6

add 7

add 5

remove

remove

remove

For this, output should be 2.

Note: In the second sample, Ian should reorder the sights after adding sight 4 and sight 7 to the stack.| Report Duplicate | Flag | PURGE

Flow Traders Software Engineer / Developer Algorithm - 0of 0 votes

AnswersIn a tennis tournament of N players every player plays with every other player.

- geek2017 September 28, 2021 in United States

The following condition always hold-

If player P1 has won the match with P2 and player P2 has won from P3, then Player P1 has also defeated P3.

Find winner of tournament in O(N) time and O(1) space. Find rank of players in O(NlogN) time.| Report Duplicate | Flag | PURGE

Facebook Algorithm - 0of 0 votes

AnswersDesign a system to find top 10 sold products for an online website at any point of time for last 15 minutes.

- Mayank Dubey May 19, 2021 in India for Java

Which data structure & algorithm would be the best to design such kind of systems?| Report Duplicate | Flag | PURGE

Kasheruka SDE-2 Algorithm - 15of 15 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 - 5of 5 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 - 22of 22 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 - 1of 1 vote

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 - 4of 4 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

AnswersGiven 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

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