## SDE-2 Interview Questions

- 0of 2 votes
Given a room with thief on left side of the room with finite number of sensors. He has to reach on right side missing the sensors. Each sensor is placed at any random point in the room and has its coverage in the radius r. Find out if the thief can reach to the right side without touching the range of any sensor.?

please discuss approach first & then code it..

- -1of 1 vote
Amazon delivery services find shortest path

Given x^2 + y^2 will give you the distance and coordinate can be nagative

int[,] allLocations=new int[,] { { 1, 3 },{1,2 },{3,4 } };

var x=Closestdestinations(3, allLocations, 1);

public static List<List<int>> Closestdestinations(int numDestinations,

int[,] allLocations,

int numDeliveries)

- 0of 0 votes
Design an email client where you can only send emails to people who are present in your contact list. Build for only the following functionaliy

1) Send/Receive Emails

2) Add/Remove Contacts

3) See Inbox

4) See Sent Mail

- 0of 0 votes
Design a distributed LRU Cache.

- 0of 0 votes
What would be the sample class design of notification system?

- 0of 0 votes
What would be the sample class design of tic tac toe game?

- 0of 0 votes
What would be the sample class design of Outlook like meeting scheduler?

- 1of 1 vote
There are 3 threads. 1 is producer thread. 2 consumer threads. There is 1 buffer. Producer writes to the buffer. Consumers consume from buffer. How to synchronise between them so that consumers consume from buffer one after another, that is, the number of tokens that consumer thread1 consumes is same as number of tokens consumer thread2 consumes. Answer in c,linux

- 0of 2 votes
What is the best way to generate first N primes? (not primes up to N but first N primes)

- 1of 3 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.

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