## SDE-2 Interview Questions

- 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

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

AnswersDesign a system which will keep track of product and its inventory count. The service will expose two api incrCnt(int prodId, int cnt) and decrCnt(int prodId, int cnt). Which db would you use ? How will you handle hot products ?

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

Amazon SDE-2 Software Design - 0of 0 votes

AnswerDesign a system in which read a file which has data and operation to be performed give a line by line. Ex a=5, next line b= 10, next line a*b. This design extended to support float, doubles, boolean, vector and complex numbers. Like if the file has a=5+i8, then how you handle such scenarios. How you will store and process data.

- neer.1304 June 08, 2020 in United States| Report Duplicate | Flag | PURGE

Amazon SDE-2 Software Design - 1of 1 vote

AnswersDesign content ingestion system

- kumar June 03, 2020 in India| Report Duplicate | Flag | PURGE

Amazon SDE-2 System Design - 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 - 1of 1 vote

AnswersA startup website has a lot of real-time traffic . I want to see the real-time view (refreshed every 1 min) of top 20 users by hit count within last 10 mins. Full distributed system, I have to resolve all the concurrency issues.

- acharyashailendra1 December 22, 2019 in India| Report Duplicate | Flag | PURGE

Amazon SDE-2 - 1of 1 vote

AnswersI was asked this during my onsite google interview but was unable to come up with an optimization for it. Here is the question:

- Jaysun October 26, 2019 in United States

There's a list of (x,y) points and a method getCircle with the following signature:

/**

* Given three points returns a circle (Radius, and center) such that all three points lie in its circumference

* or it returns null if no such circle is possible.

*/

Circle getCircle(point1, point2, point3);

getCircle method is already implemented and given to you as a black box. The problems asks you to find the Circle with most points in its perimeter.

The obvious answer is to get all possible triplets of points and find all possible circles and keep track of which one appears most often O(n^3) . Any ideas on how to further optimize this?| Report Duplicate | Flag | PURGE

Google SDE-2 Algorithm - 0of 0 votes

AnswersThere are cards and each card has an identity. e.g. HC1 has ID 1, this ID also represents the cost of the card. Your sister already have some cards and you want to gift her cards which she do not have already. Program is to return the max number of cards you can buy for her.

- acharyashailendra1 September 19, 2019 in India

Constraint : You have amount d, and want to buy as many distinct card as you can.

e.g. Sister Cards = [2, 3, 5], D : 7 Card you buy : 1, 4

Output : 2| Report Duplicate | Flag | PURGE

SDE-2 - 0of 0 votes

AnswersYou have been given a special and normal status of alphabets.

- acharyashailendra1 September 19, 2019 in India

e.g. “01111001111111111011111111” represents “abcdefghijklmnopqrstuvwxyz”. Here 0 represents normal character and 1 represents special character.

Given an Input String S and a number k, find the maximum continuous sub array with maximum k number of number elements. There is no constraint on special character.

e.g.

S = “giraffe”, K = 1, “011110011111111110111111”

Output : 3

How ?

normal characters : a, g, f

one of the possible solution : gir (as this has only one normal character)| Report Duplicate | Flag | PURGE

SDE-2 - 0of 0 votes

AnswerGiven a binary String which represents the target state. Minimum number of flips needed to convert a same size Binary String (with all 0’s) to target state. A flip also causes all the right bits to be flipped.

- acharyashailendra1 September 19, 2019 in India

e.g.

Input : 00101 (Represents Target)

Output : 3

Explanation :

00000 -> 00111 -> 00100 -> 00101| Report Duplicate | Flag | PURGE

SDE-2 - 0of 0 votes

AnswersN cows are standing at the origin on x-axis, each cow has some appetite, in other word hunger index. A cow can sleep of 1 unit of time or eat for one unit of time or move left or move right. There are some vessels placed on the x-axis, they are having infinite supply of fiod. Find minimum time in which all cows appetite would be filled.

- xyz September 15, 2019 in United States

Input:

cow Apetitte = {1,1}

Vessle locations = {-1,1}

Answer would be 2 since both cow can go in different direction they would eat for one seconds. One second for moving and one second for eating.

This problem looks to be similar to rotten eggs/tomatoes.| Report Duplicate | Flag | PURGE

Allegient SDE-2 Algorithm - 0of 0 votes

AnswerDesign and implement rate limiter for limiting api calls for a service distributed multiple users.

- acharyashailendra1 August 27, 2019 in India| Report Duplicate | Flag | PURGE

SDE-2 - 0of 0 votes

AnswerDesign data structures which support millions of products coming in streaming manner, we need to find at any moment what are top n products at any day

- acharyashailendra1 August 27, 2019 in India| Report Duplicate | Flag | PURGE

SDE-2 - 2of 2 votes

AnswerA dictionary is combination of characters from a-z. let's say a=1,b=2.. and so on z=26. you are given n and k. you have to find sum of length k from given combination.

- acharyashailendra1 August 21, 2019 in India

for example n=51 and k=3 then your answer should be =axz

as there can be many combination for given sum so it is suggested to print those string which comes first in dictonary| Report Duplicate | Flag | PURGE

LendingKart SDE-2 Data Structures - 1of 1 vote

Answersbeautiful numbers are those numbers which contains digit only 4 and 5 also they are palindrome.length of number can't be odd. for example

- acharyashailendra1 August 21, 2019 in India

44,55,4554 are beautiful numbers where as 38, 444 are not.

your task is to find nth number in this series. let's say if n=4 then output should be 4554. for n=1 output will be 44 always.| Report Duplicate | Flag | PURGE

LendingKart SDE-2 Data Structures - 0of 0 votes

AnswersThere are N stations in a certain region, numbered 1 through N. It takes di,j minutes to travel from Station i to Station j (1 ¥leq i, j ¥leq N)$. Note that di,j=dj,i may not hold.

- neer.1304 August 15, 2019 in United States

You are now at Station 1. From here, you have to visit all the stations exactly once. We assume that you have already visited Station 1. However, due to your schedule, there are M restrictions that must be satisfied. The format of each restriction is as follows:

• Station si must be visited before Station ti. (1≤i≤M)

Find the minimum time required to visit all the stations. Note that the last station to visit can be any of the stations.

Constraints

• 1≤N≤14

• 0≤di,j≤108 (1≤i,j≤N)

• di,i=0 (1≤i≤N)

• 0≤M≤N(N−1)⁄2

• 1≤si,ti≤N (1≤i≤M)

• si≠ti (1≤i≤M)

• There exists a path visiting all the stations under the given restrictions.

Input

Input is given from Standard Input in the following format: N d1,1 … d1,N : dN,1 … dN,N M s1 t1 : sM tM

Output

Print the minimum time required to visit all the stations.

Sample Input 1

4

0 2 3 4

1 0 3 4

1 2 0 4

1 2 3 0

3

1 2

2 3

3 4

Sample Output 1

9

Due to the restrictions, we can only travel as follows: Station 1 → Station 2 → Station 3 → Station 4. Thus, the answer is 2+3+4=9 and we should print 9.

Sample Input 2

3

0 1 20

1 0 20

10 20 0

0

Sample Output 2

21| Report Duplicate | Flag | PURGE

Indeed SDE-2 Algorithm - 0of 0 votes

AnswersYou are given an array of length N consisting of integers, a={a1,…,aN}, and an integer L.

- neer.1304 August 15, 2019 in United States

Consider the following subproblem:

• You are given an integer S.

• Find the largest value in the interval [S,S+L−1] in the sequence a, that is, find max(aS,…,aS+L−1).

Solve this subproblem for every S=1,…,N−L+1.

Constraints

• 1≤N≤105

• 1≤L≤N

• −109≤ai≤109

Input

Input is given from Standard Input in the following format: N L a1 … aN

Output

Print the answers in N−L+1 lines. The i-th line should contain the answer to the subproblem where S=i.

Sample Input 1

5 3

3 4 2 1 5

Sample Output 1

4

4

5

• The subproblem where S=1 asks the largest value among a={a1,a2,a3}={3,4,2}, so the first line in the output should contain 4.

• The subproblem where S=2 asks the largest value among a={a2,a3,a4}={4,2,1}, so the second line in the output should contain 4.

• The subproblem where S=3 asks the largest value among a={a3,a4,a5}={2,1,5}, so the third line in the output should contain 5.

Sample Input 2

4 1

-1000000000 1000000000 -1000000000 1000000000

Sample Output 2

-1000000000

1000000000

-1000000000

1000000000| Report Duplicate | Flag | PURGE

Indeed SDE-2 Algorithm - 0of 0 votes

AnswersThere are N rooms in a row. The i-th room (1≤i≤N) from the left is called Room i. You are given M closed intervals [ai,bi] (1≤i≤M). At time 0, all rooms j such that ai≤j≤bi for some i (1≤i≤M) are occupied, and the other rooms are vacant.

- neer.1304 August 15, 2019 in United States

You are given Q queries. The i-th query (1≤i≤Q) represents an event happening at time i, as follows:

• In the i-th query (1≤i≤Q), a closed interval [ci,di] (1≤i≤Q) is given.

• This query asks: "Are all rooms j such that ci≤j≤ci" vacant?

• If all those rooms are vacant, the query should be responded by OK, then all rooms j such that ci≤j≤ci get occupied.

• Otherwise, the query should be responded by OK, then nothing happens.

Process these queries.

Constraints

• 1≤N≤109

• 0≤M≤1000

• 1≤ai≤bi≤N (1≤i≤M)

• There are no rooms k such that ai≤k≤bi and aj≤k≤bj at the same time (1≤i<j≤M).

• 1≤Q≤1000

• 1≤ci≤di≤N

Input

Input is given from Standard Input in the following format: N M a1 b1 : aM bM Q c1 d1 : cQ dQ

Output

Print the responses in Q lines. The i-th line should contain the response to the i-th query.

Sample Input 1

5 2

1 1

4 4

3

3 3

2 3

5 5

Sample Output 1

OK

NG

OK

At time 0, Room 1 and 4 are occupied.

• At time 1, a query asks: "is Room 3 occupied?" Since Room 3 is vacant, we should print OK, then Room 3 gets occupied.

• At time 2, a query asks: "are Room 2 and 3 occupied?" Since Room 3 is occupied, we should print NG.

• At time 3, a query asks: "is Room 5 occupied?" Since Room 5 is vacant, we should print OK, then Room 5 gets occupied.

Sample Input 2

1000000000 1

2 999999999

4

1 1000000000

500000000 500000000

1 1

1000000000 1000000000

Sample Output 2

NG

NG

OK

OK| Report Duplicate | Flag | PURGE

Indeed SDE-2 Algorithm - 0of 0 votes

AnswersYou are given N records. The content of the i-th record is represented by a string Si. These records are managed in pages, as follows:

- neer.1304 August 15, 2019 in United States

• The first page: contains the first, ..., K-th records.

• The second page: contains the (K+1)-th, ..., 2K-th records.

• The third page: contains the (2K+1)-th, ..., 3K-th records.

• :

• The ceil(N⁄K)-th page: contains the ((ceil(N⁄K)−1)K+1)-th, ..., N-th records.

Here, ceil(X) represents the smallest integer not less than X. Print the contents of the records contained in the M-th page, in the order given.

Constraints

• 1≤N≤100

• 1≤K≤N

• 1≤M≤ceil(N⁄K)

• 1≤|Si|≤100 (1≤i≤N), where |S| is the length of S.

• Si is a string consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N K M S1 S2 : SN

Output

Print the contents of the records contained in the M-th page, in the order given. Use L lines, where L is the number of records that should be printed. The i-th line (1≤i≤L) should contain the content of the i-th record contained in the M-th page.

Sample Input 1

5 2 2

aaa

bbb

ccc

ddd

eee

Sample Output 1

ccc

ddd

• The first page contains the first and second records, which are aaa and bbb.

• The second page contains the third and fourth records, which are ccc and ddd.

• The third page contains the fifth record, which is eee.

Since the second page is requested, we should print ccc in the first line and ddd in the second line.

Sample Input 2

7 4 2

this

is

not

displayed

this

is

displayed

Sample Output 2

this

is

displayed| Report Duplicate | Flag | PURGE

Indeed SDE-2 Algorithm - 0of 0 votes

AnswerMake a system that returns the average number of hits on the site per minute from the past 5 minutes

- neer.1304 August 15, 2019 in United States| Report Duplicate | Flag | PURGE

Indeed SDE-2 Software Design

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

Open Chat in New Window