## SDE-2 Interview Questions

- 0of 0 votes
Find all paths in binary tree that add up to a given sum.

Given a tree like this:`2 3 5 4 8 6 -2 2`

return {3,4}, {2,5}, {2, 5, -2, 2}

- 0of 0 votes
Design the "what other people bought feature." This was focused on database design/creating an api to lie on top of it, and he asked questions to see if I understood how dbs actually work(like what does group by do). I was given an example table with the schema of like

itemID, purchaseDate, customerID

He asked big O complexity of sql query as well.

- 0of 0 votes
Design Amazon Questions and Answers. This question was to see how I code, and how I would modularize things. He wanted me to code every single thing as realistically as possible on a whiteboard.

- 0of 0 votes
Design a push notification system for android. Assume that we have 1 million users this year, but next year we will have 15 million. Assume that Google can handle infinite notifications per second.

I would love to see this answered, as I did not answer it well.

- 0of 0 votes
You are given a String S that consists of characters '0' and '1' only.Return the smallest positive integer K such that it is possible to cut S into K pieces, each of them being a power of 5. If there is no such K, return -1 instead.

Examples

0)

"101101101"

Returns: 3

We can split the given string into three "101"s.

Note that "101" is 5 in binary.

1)

"1111101"

Returns: 1

"1111101" is 5^3.

2)

"110011011"

Returns: 3

Split it into "11001", "101" and "1".

3)

"1000101011"

Returns: -1

4)

"111011100110101100101110111"

Returns: 5

- 0of 0 votes
Design an Email sender, need to send 100,000000 emails and you have 5 machines how could you do it efficiently.

- 0of 0 votes
Given an URL you need to analyze all the images( they may be in 1000’s of number) and return the cumulative quality of images present in that url.

lets say: you can configure image quality as very good, good, average, poor..etc, so you have to return one value among them.The given URL may contain several other URLs and they also contain lot of images . you need to consider all of them. lot of questions like how to avoid visiting same url again,

how would you determine the quality of an image if you encounter an url that contains only an image..etc.

- 0of 0 votes
Design Elevator system. And then write an algorithm for that Design such that, the user request should be completed in logN time in a N story building with M elevators.

- 0of 0 votes
In an online teaching system, there are n number of teachers and each one teaches only one subject to any number of students.

And a student can join to any number of teachers to learn those subjects.

And each student can give one preference through which he can get updates about the subject or class timings etc.

Those preferences can be through SMS or twitter/facebook or email..etc.

Design above system and draw the diagram for above.

- 0of 0 votes
How to debug deadlock or heap corruption from DUMP using WinDbg tool?

- 0of 0 votes
Design classes and interface for BookShelf

- 1of 1 vote
Given a file, read last n lines from the file

string ReadNLines(sttring fileName, int n);

- 0of 0 votes
Identify the output

`Class A { } Class B { } B b = new B(); A a = (A) b; sysout(b.getClass()); sysout(a.getClass());`

- 0of 0 votes
Given Two classes A & B. How will B know if an instance of A is already created?

- 0of 0 votes
Log file contains UserId.Every day has new log file.Given range of n days find top 10 users?

- 0of 0 votes
Given an int[] multiply all numbers except index I/p {1,2,3,4} O/P {24,12,8,6} How can you minimize multiplication

- 0of 0 votes
Move all zeros to beginning input {1,2,3,0,0,0,4,5} output {0,0,0,1,2,3,4,5}

- 0of 0 votes
class Node{ int nodeId,int nodeParentId} is given.

Input : List<Node>

Output:Tree

- 0of 0 votes
Design TIC TAC TOE problem

- 4of 4 votes
Given a big rectangular plot of land that has rectangular or square sized buildings (all sides of every building are parallel to the big rectangular plot)... find the location and dimensions of the largest square that can be built in this rectangular plot

- 2of 2 votes
Find the number of bits set in a given character array.

After giving him a bit wise operation that was O(n) where n is the number of bits set, he wanted a more optimum solution

- 1of 1 vote
Given an array of integers and a number. WAP to find the pairs which sum of upto given number.

I solved it. Then he asked about writing test cases for this function.

I wrote below test cases

1.) All the elements should be number.

2.) Length of array should not be 0.

3.) Array itself should not be null.

4.) Given number, arrayLength can be represented by 32bits or 64 bits.

5.) number should not be negative.

6.) Input does not has pair, It should return false

7.) Input has pair, It should return true

8.) Input has all negative values and pair exists, then function should return true

9.) Input has all negative values and pair does not exists, function should return false

He told that he is looking for more test cases. Can you guys think of some more complex test cases.

- 1of 1 vote
You are given a catalog of books, which have following attributes :-

Name, Author, Publisher, Publish year, Category, Price, Count (sold)

Implement following APIs on top of this catalog -

1) addBookToCatalog(Book)

2) searchBook(by partial book name/author)

3) getMostSoldBooks(by author name/category, limit)

Expectations:

Maintain DB on memory

Code should be readable. Design, handle naming convention,handle exceptions & should be running

- 3of 3 votes
You have to compress a string in the following format.

eg 1- : input : aasasatb

output : 2a2sa1t1b

eg2 -: input: abcdbcdff

output :- 1a2bcd2f

- 0of 0 votes
design snakes and ladders game(multiplayer). extend it so that it can be hosted overs a server and played over a server

- 0of 0 votes
code library management system

a) add a book

b) issue a book

c) return a book

d) if a user has kept a book more than 10 days then there should be a fine of Rs. 1 per day post 10 days.

- 0of 0 votes
given daily stock rates of last year give the average stock rate price for a given day range

- 0of 0 votes
given n-ary tree. zigzag level order traversal.

- 0of 0 votes
given unsorted array and a number K. Find 2 numbers such that sum is K

- 0of 0 votes
there are M chocolate packets each packet can have variable number of chocolates in each packet.

There are N students (N<M).

Distribute chocolate packets to student such that

1) each student gets 1 packet

2) suppose m1,m2,...mn are the packets which are chosen to be distributed in sorted order of number of chocolates in them (nm-n1 must be minimum)

M = 1, 3, 4, 6 (4 packets with specified number of chocolates in them)

N = 2

Ans = 3,4