## SDE-2 Interview Questions

- 0of 0 votes
Given an alphabet where we do not know the order of the letters also do not know the number of letters.

We are give an input list of tuples where each entry in the list gives an ordering between the 2 letters

Determine the alphabet order.

Ex-

<A, B>

<C, D>

<C, E>

<D, E>

<A, C>

<B, C>

Order is A, B, C, D, E

- 0of 0 votes
Imagine a horizontal corridor bounded by y = y1 and y = y2 lines on a 2D-plane. There are N sensors with centers (x, y) each of which operates in a range (r) on the plane . So, they cover some circular areas on the plane. See the figure below.

`o | _____o___o__|____________ y = y1 o |OOO __________oo|_____O______ y = y2 O | O _ _ _ _ _ _ | _ _ _ _ _ _ | o O | o O O | | O | |`

The question is whether a path exist from x=-inf to x=+inf via corridor without being detected any radar.

Constraints:

1. You are free to move any direction only if you stay in the corridor.

2. You are free to go through corridor borders.

3. N sensors are given as list of (x, y, r) like [(1, 3, 2), (-1, -3, 4)]. x and y are signed integers. r is a unsigned integer.

4. y1 and y2 are integers.

My solution:

1. Create an intersection graph of N sensors by comparing them each other via Euclidean distance`(x1 - x2)^2 + (y1 - y2)^2 <= (r1 + r2)^2`

2. If there is a path between y=y1 and y=y2 through intersected sensors, there do not exist any path from x=-inf to x=+inf. Otherwise, there do exist a path. So, I used BFS to search such a path.

Worst Case Complexity:

1. O(n^2)

2. O(V + E) = O(n + intersection_count)`Total: O(n^2)`

My Best Case Optimization for Intersection Graph:

1. For each sensor, create two events for start and end of circles vertically. y = (y1 - r) and y = (y1 + r)

2. For each sensor, register those two events into an array.

3. Use a line sweep algorithm over 2, which is O(nlogn + intersection_count) and intersection_count may be n^2 at worst case.

I wonder if I should have had a better solution with the worst case < O(n^2).

- 0of 0 votes
Longest increasing subsequence, Number of Island, Basic SQL questions like joins, select statement etc, Code for finding the Name in the document. Like based on the property of name (which cannot be written in small case). Find its frequency.

- 0of 0 votes
Design online movie ticket system. Hardware and software capabilities, improvements etc

- 0of 0 votes
A number of islands. All the rounds had basic DB questions

- 0of 0 votes
Basic DB questions like joins, aggregations, primary keys etc

- 0of 0 votes
Number of islands. Big(O).

- 0of 0 votes
In the doc file the "Name" without any dictionary. Like finding the property of the name as Starts with the capital letter. Then find the frequency of only names present in the doc. Whiteboard coding

- 0of 0 votes
Longest Increasing Subsequence

- 0of 0 votes
Online movie ticket booking system design

- 0of 0 votes
Design a system to forward 20% of your requests to cloud datacenter and rest to onprem data center. comsider you are fwd api.

- 0of 0 votes
Design S3 file storage system.

- 0of 0 votes
Last Man Standing

A king gathers all the men in the kingdom who are to be put to death for their crimes, but because of his mercy, he will pardon one. He gathers the men into a circle and gives the sword to one man. The man kills the man to his left, and gives the sword to the man to the dead man's left. The last man alive is pardoned.

With 5 men, the 3rd is the last man alive.

Write a program that accepts a single parameter: a number N that represents the number of criminals to start with. The program should output the number of the last two men alive.

Example #1: myProgram 5

would output:

5, 3

Example #2: myProgram 7

would output:

3, 7

- 0of 0 votes
This is a word splitter program, I wanted to know the complexity of this program:

`String s = //"The quick fox jumped over a lazy dog"; "The Java language provides special support for the string " + "concatenation operator ( + ), and for conversion of other " + "objects to strings. String concatenation is implemented " + "through the StringBuilder(or StringBuffer) class and its " + "append method. String conversions are implemented through " + "the method toString, defined by Object and inherited by " + "all classes in Java."; int charLimit = 13; System.out.println("-------------"); char[] chars = s.toCharArray(); boolean endOfString = false; int start = 0; int end = start; while(start < chars.length-1) { int charCount = 0; int lastSpace = 0; while(charCount < charLimit) { if(chars[charCount+start] == ' ') { lastSpace = charCount; } charCount++; if(charCount+start == s.length()) { endOfString = true; break; } } end = endOfString ? s.length() : (lastSpace > 0) ? lastSpace+start : charCount+start; System.out.println(s.substring(start, end)); start = end+1; }`

- 0of 0 votes
Aisles contain products. Product is only going to be in one Aisle.

Product{

AisleID: string

ProductID: string

Price: float

}

Given Array<Product>, find the N highest price combinations. Combination is 1 product from each aisle. You can choose only one instance of each product.

So if you had two aisles

1: {$5,$4,$2}

and

2: {$6,$1)

And they asked for the 2 highest combos you would give $6,$5 and $6,$4

- 0of 0 votes
Fill the arrow with zeros in n*n matrix.{{0,0,0,0,0,0,0

0,0,1,1,1,0,0

0,0,1,0,1,0,0

0,0,1,0,1,0,0

0,1,0,0,0,1,0

0,0,1,0,1,0,0

0,0,0,1,0,0,0}}

- 0of 0 votes
Given a math expression in string format that contains only + & - and numbers. Return the sum in integer format. Eg: Input: "3+4-7+13" Output: 13.

"2+1-8+13" Output: 8

- 1of 1 vote
Print words in order which are occurring once in huge document. The RAM size 100MB and file size 10 GB.

Example: I am good. You are good.

Answer : I am You are

Note : It's not datastructure problem where we can simply make use of LinkedHashMap. The file size is going to be huge.

- 0of 0 votes
I participated interview event with Amazon and receive email from Amazon recruiter that the team was happy with my performance and would be giving me offer at Amazon Vancouver Office, Canada. However,17 days later i still not get an official offer. I did several follow up with the recruiter within the period, just to get some "they are finding team for me" response. What could go wrong? Why is it in my case that the offer is being process so slow?

- 0of 0 votes
given two array of elements representing the connection Nodes output the topology used?

Topology can be either Bus , circular or Star

input:

Number of nodes 3

Number of Connections : 2

{1,2}

{2,3}

Output Bus

Explanation

the topology formed would be 1->2->3 . hence Bus

input

number of nodes : 3

Number of connections : 3

{1,2,3}

{2,3,1}

Output: Circular

the topology formed is 1->2->3->1

hence circular

input:

number of nodes : 5

Number of connections : 5

2 3 4 5

1 1 1 1

Answer : StarTopology

Explanation : A star can be formed with this input

2 4

1

3 5

StarTopology

- 0of 0 votes
Design a system which helps to calculate average Skype call duration per day. In which events are tracked from mobile app. Need to take care of all edge cases like events can be logged to server in any sequence & there can be some events missing on server side also.

- 1of 3 votes
A message containing letters from A-Z is being encoded to numbers using the following mapping:

'A' -> 1

'B' -> 2

...

'Z' -> 26

Given an encoded message containing digits, determine the total number of ways to decode it.

For example,

Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12).

- 0of 0 votes
Design online multiplayer generic board game (like chess). How will you store sessions.(RDBMS or REDIS) How will the

competitor be chosen and notified(HTTP or what?).

What are the appropriate classes?

- 0of 0 votes
Design Recommendation system. How will you generate generate recommendations for millions of users. DB Schema, How will you improve latency? if the user is searching a item, when will you show next recommendations. How will you update, latency basically and consistency.

- 0of 0 votes
You are provided with 2D char array. You have to provide the 2D char array as response which contains the multiplication od the input array. For eg: input=> {{a,b},{c,d}}, output => {{a,c},{a,d},{b,c},{b,d}}

- 0of 0 votes
You are provided with different Excel files and the data format those files contain. You are also provided with low level parser. You have to design a system which takes the excel file and its data type as the input and returns the list of Data objects in the file.

- 1of 1 vote
Design JProfiler. How will you design datastructure and why, function stacktrace. HLD+LLD

- 0of 0 votes
Design a Fresh Grocery System. Means Daily usable Items, you cannot store them in inventory like bread, milk etc.

HLD+ DB Schema + Concurrency issues + Scalable architecture. How will you scale to multiple countries

- 1of 1 vote
How to develop a web based multiplayer chess game. There will be 2 player in each session. There will be multiple sessions.

My answer(I was not selected)

Each player will have a database with columns

user id(primary key), passwd,no of games played, won,drawn,last active time,sq1,sq2,...sq64,move made flag,pawn num, sqstart,sqend

where sq1-denotes square 1 and its value represents the pawn num in sq1

question- what all fields in database will be encrypted

answer-passwd

question- why not others

answer-may be system admin needs to access them

question – how will u start a session between players?

Answer-When a player logs in, his last active time is updated. Each player is shown a list of last active players to chose from.Or system can arbitrarily select one.When a player is selected, he gets a request. Each player receives a list of requests from other players. He choses from one. That player gets an acknowledgement others get negative acknowledgement. If acknowledgement does not come in time then that player is dropped and another player is selected.

Question- http connection, can not send request from server. How the 2 players will send request to each other and how session will be initiated?

Question-how the game will be stored?

The 64 squares sq1,sq2,..sq64 will each store the pawn number in them. From random number calculatio, it will be decided which one is white and which one is black 1st time. When a player makes move,has made move flag will be true. The last move is stored as sqstart,sqend,pawn number. Each time a move is made check for valid move.The other player continuously polls for has made move flag to know if it is his turn

remarks- ur design is not scalable.

- 0of 0 votes
You are given a Log that contains UserId, ProcessId, Start Time, End Time and Resource Consumption during that time, you need to find out the user who has utilized the most resources.

Example:`UID PID StartTime EndTime Consumption`

`1 1 200 300 100`

`2 2 230 340 80`

`1 3 245 315 50`

`1 4 305 330 20`

Time 200 signifies: 02:00.

Output: UID# 1

UserID 1 because he has consumed the most number of resources between 200 to 315 (Resource Consumption: 150).