## Algorithm Interview Questions

- 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

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

AnswersWrite your own class for key value store which has four methods:

- Desi May 14, 2019 in United States for ATG

put(key,value)

get(key)

getRandom() this should return a random value with equal probability

deleteWithKey(key)

I was allowed to use hashmap internally to store data.

this was my second technical phone interview because they wanted to get some more idea about my technical skills.| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 0of 0 votes

AnswersAt first Interviewer asked me to write a problem to solve sudoku and return error if sudoku is invalid.

- Desi May 14, 2019 in United States for ATG

I told him I already had seen the problem before and he said he really appreciates my honesty.

this was my second technical phone interview because they wanted to get some more idea about my technical skills.| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 0of 0 votes

AnswerI dont remember the exact problem anymore. but the problem's solution included going through an array and at every step taking 2 minimum element and adding the result. this also includes the result itself.

- Desi May 13, 2019 in United States for Robotics

so lets say for following array:

2,54,4,10,1,7

you first take 1 and 2 and add

then add the result 3 to the array

so now your array looks like :

3,54,4,10,7

then you take 3 and 4 and add them and add result back

I basically used a heap where i take two mins and add them and add the result back to heap.

I have give amazon online test twice in last 8 months and both the times the first question was about heaps and second something about finding shorted path in a grid between two cells| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersThe problem was very similar to the problem from geeksforgeeks:

- Desi May 13, 2019 in United States for Robotics

Shortest distance between two cells in a matrix or grid

Given a matrix of N*M order. Find the shortest distance from a source cell to a destination cell, traversing through limited cells only. Also you can move only up, down, left and right. If found output the distance else -1.

instead of source and destination, they asked for robot to be able to get rid of obstacle at a certain cell.

I have give amazon online test twice in last 8 months and both the times the first question was about heaps and second something about finding shorted path in a grid between two cells| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersI am given jobs with starttime and end time and we unlimited VMs. at any point a VM can only take one job. so bascially I had to find overlapping jobs and assign them to different machines and those that are not overlapping could be assigned to same machines. The tricky part was when there are two different overlaps and they could be assigned to 2 machines instead of all overlapping jobs being assigned to different machines.The method should return minimum number of VMs used to finish all jobs.

- Desi May 13, 2019 in United States for Robotics

I mentioned sorting the jobs based on start time. and then returning number_of_overlapping jobs +1. but again in some cases if there are two different overlaps which could be assigned to two machines then we need to take care of that.| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersExpression tree evaluation and also write the class for the node and tree itself. (just basic structure like node and data)

- Desi May 13, 2019 in United States for Robotics| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersLRU cache. Basically started off with how would I store values and get them from memory for faster access. So I mentioned HashMap. and then interviewer added more info about deleting least recently used element.

- Desi May 13, 2019 in United States for Robotics| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 0of 0 votes

AnswersGiven a list of files. Return all the unique lines from all files.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswerGiven a set of points, find the smallest rectangle by area.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven N shop coordinates on a 2-d plane, Find the nearest shop from a man whose coordinates are given.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswersGive you a text file, remove duplicated lines.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswersA string consists of ‘0’, ‘1’ and '?'. The question mark can be either '0' or '1'. Find all possible combinations for a string.

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

Google Software Engineer Algorithm - 0of 0 votes

AnswersGiven a nxn grid with 1's and 0's find the length of largest black square formed with 1's.

- Desi April 29, 2019 in United States for ATG

So for below example:

00000

11110

01111

01110

The largest square length is 3.

With dynamic programming it can be done in O(n^2) time

It was a technical screen but it was taken in person for an event.| Report Duplicate | Flag | PURGE

Uber Software Engineer Algorithm - 1of 1 vote

AnswersGiven movement of Robot -

- neer.1304 April 22, 2019 in United States

G-GO one unit

L-Turn left

R-Turn right

Given an input of string have to find whether there exists a circle which the robot would traverse. Input of string is the set of G,L,R have to return yes or no.| Report Duplicate | Flag | PURGE

Flipkart SDE-2 Algorithm - 1of 1 vote

AnswersGiven a list of strings. Check whether any two strings, if concatenated will form palindrome or not.

- neer.1304 April 22, 2019 in United States| Report Duplicate | Flag | PURGE

Flipkart SDE-2 Algorithm - 0of 0 votes

AnswerThere is a hierarchical structure in an organization. A party is to be organized. No two immediate subordinates can come to the party. A profit is associated with every person. You have to maximize the total profit of all the persons who come to the party.

- neer.1304 April 22, 2019 in United States| Report Duplicate | Flag | PURGE

Flipkart SDE-2 Algorithm - 0of 0 votes

AnswerYou have been given a set of inter-dependent tasks along with the time taken to execute them. We have more number of parallel processors available than the number of tasks given. There could be multiple starting tasks. There could also be cyclic dependencies. Calculate the minimum time required to complete all the task.

- neer.1304 April 21, 2019 in United States| Report Duplicate | Flag | PURGE

Amazon SDE-2 Algorithm - 1of 1 vote

AnswersGiven unsorted array, find how many elements can be found using binary search

- neer.1304 April 21, 2019 in United States

- ex : [5,4,6,2,8] -> Ans : 3 -> '6' and '8' and '5' can be found using binary search| 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