## SDE-2 Interview Questions

- -1of 1 vote
What is the best way to generate first N primes? (not primes up to N but first N primes)

- 0of 2 votes
How do find out the top trendings products on a last hour/day/monthly basis?

Given that we have access to a real-time stream of sold product ids.

- -1of 1 vote
Design Amazon prime video

- -1of 1 vote
How is code review done?

- -1of 1 vote
How is design review done?

- 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}}