## Algorithm Interview Questions

- 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 - 1of 1 vote

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

AnswerDisplay 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

AnswerGiven 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

AnswersGiven 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 - -1of 1 vote

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

AnswersTwo tables employee (contains name and Id) and employee details having work experience history (contains Id, fromYear, toYear) – find out all the employees who worked w/o career break.

- neer.1304 May 19, 2020 in United States

Java implementation for the same.

From the same table list the name, fromYear, toYear for all employee.

Dependency Injection.

Design patterns which can be used.| Report Duplicate | Flag | PURGE

Microsoft Senior Software Development Engineer Algorithm - 0of 0 votes

AnswersGiven a binary matrix of size M * N. You are given H and V where H denotes the number of horizontal cuts and V represents number of vertical cuts. You need to find whether you can make H and V amount of cuts such that each submatrix formed after the cuts will have equal number of 1. E.g.

- neer.1304 May 16, 2020 in United States

4 5

1 1 1 1 1

0 0 1 1 1

0 1 1 1 1

1 0 1 1 1

Given H=1 and V=3, we can make 1st horizontal cut after 2nd row and 3 vertical cuts after 2nd, 3rd and 4th column such that each of the sub matrix will have equal number of 1s.

| ----------------|

| 1 1 | 1 | 1 | 1 |

| 0 0 | 1 | 1 | 1 |

| ----------------|

| 0 1 | 1 | 1 | 1 |

| 1 0 | 1 | 1 | 1 |

| ----------------|| Report Duplicate | Flag | PURGE

Amazon SDE-3 Algorithm - 0of 0 votes

AnswerGiven a remote having 0-9 digits, plus button (to increase channel), minus (to decrease) and previous channel button (to go to previous channel). We were given 2 numbers stating start and end channel number and an array having various channel numbers. The task is to go to all channel numbers given in array with minimum number of clicks.

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

Amazon SDE-3 Algorithm - 0of 0 votes

AnswersSmallest string

- sobby May 03, 2020 in India

You are given the following :

1. Two strings S and T each of Length N

2. K Pairs of integers L(i) and R(i) (0 <= l(i) < R(i) <= N-1)

You can perform any of the following two operations any number of time.

1. You can replace the character of string S at the ith position with the character of string T at the ith position

2. You can select from any provided K pairs and you are allowed to swap characters at position L(i) and R(i) in string T

Now, you are required to perform all the operations optimally so that string S can be lexographically smallest.

All characters of S and T are of lowercase English letters and there are only two ways to perform all the operations either(111...1) then (2222...2) or (2222...2) then (1111.1)

Input Format :

1. First line contains number of test cases:

2. Second line contains the lengths of string and the number of pairs of integers.

3. Next two line contains S and T two strings.

4. The next K lines contains the space separated integers.

Sample Input :

1

8 4

abagfiab

cbacbcda

0 1

1 2

3 4

4 5

sample output : aaabccaa| Report Duplicate | Flag | PURGE

PayPal SDE-3 Algorithm - 0of 0 votes

AnswersYou are given a list of n people and also a list of m pairs who know each other.

- ff987456321 April 25, 2020 in France

Here is an example input:

List of people: x1, x2, x3, . . . , xn

People who know each other: (x1, x2),(x1, x4),(x2, x4),(x2, x5),(x2, x6),(x4, x5),(x4, x6), . . .

1. Given a positive integer k, write an integer program that finds k people among the given n people with

the maximum number of pairs who know each other. How many variables and constraints are there?

2. Write an integer program that finds the maximum number of people where everyone knows each other. How many variables and constraints are there?| Report Duplicate | Flag | PURGE

Algorithm - 0of 0 votes

AnswersYou are given 2 arrays: one representing the time people arrive at a door and other representing the direction they want to go(in or out) You have to find at what time each person will use the door provided no 2 people can use the door at the same time. Constraints: the door starts with ‘in’ position, in case of a conflict(2 or more people trying to use the door at the same time), the direction previously used holds precedence. If there is no conflict whoever comes first uses the door. Also if no one uses the door, it reverts back to the starting ‘in’ position. Should be linear time complexity.

- neer.1304 April 21, 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.

Open Chat in New Window