## SDE-2 Interview Questions

- 1of 3 votes
One of the questions in one of the interviews -

Given a stack S and another empty stack T and a variable v, write a function that returns S but with its elements reversed.

- 0of 0 votes
Design a download manager. The download manager would be shipped with a browser. Detailed design of components and interaction between them.

Follow up question - What features would you add to the download manager so that it is more marketable than others.

- 0of 0 votes
Shopkeeper want sells in the packs of 20,9 and 6. Given an n, you need to find whether its possible to buy the items or not.For example n=21, you can buy 2 packs of 6 and one pack of 9(2*6 + 9)

Output 1 if possible and 0 if not

Test cases:

1) n=47 ==> possible, output = 1

2) n=7 ===> not possible, output = 0

- 0of 2 votes
Consider 0 as water and 1 as land. Write code in C to find out whether there is pool in the following matrices.

11111

10001

10001

11111

above matrix is pool

11111

11001

11001

10111

11111

above matrix is NOT pool

11111

11001

11001

10001

11111

above matrix is pool

11111

11101

11001

10001

11111

above matrix is pool

- 1of 3 votes
There are N objects kept in a row. The ith object is at position x_i. You want to partition them into K groups. You want to move all objects belonging to the same group to the same position. Objects in two different groups may be placed at the same position. What is the minimum total amount by which you need to move the objects to accomplish this?

Input:

The first line contains the number of test cases T. T test cases follow. The first line contains N and K. The next line contains N space seperated integers, denoting the original positions x_i of the objects.

Output:

Output T lines, containing the total minimum amount by which the objects should be moved.

Constraints:

1 <= T <= 1000

1 <= K <= N <= 200

0 <= x_i <= 1000

Sample Input:

3

3 3

1 1 3

3 2

1 2 4

4 2

1 2 5 7

Sample Output:

0

1

3

Explanation:

For the first case, there is no need to move any object.

For the second case, group objects 1 and 2 together by moving the first object to position 2.

For the third case, group objects 1 and 2 together by moving the first object to position 2 and group objects 3 and 4 together by moving object 3 to position 7. Thus the answer is 1 + 2 = 3.

- 1of 1 vote
Given an input string.

* It has numbers from M to N in increasing order. But no prior information about the values of M and N.

* There is one missing number.

Output the missing number.

Eg.

I/p: 960961962964

O/p: 963

I/p: 12345789

o/p: 6

- 0of 0 votes
given 2 Dimensional array

I/P -- String[][] input = { { "abc", "def", "gh" },

{ "f", "g" },

{ "qrt","xyz","pqr" } };

Program shd return a 2-D Array with

O/P -- { { "abcfqrt", "abcfxyz", "abcfpqr" ,abcgqrt and so on ..

- 1of 1 vote
Given 2D matrix of chars, you can find substring by moving in any [of 8]direction inside the range.

Get the list of sorted palindromes without duplicate which are available inside all possible substring in the Matrix.

- 1of 1 vote
Find the digits count in the number from Range 0-n

For Example: Input range 0-10

count[0]=2

.

.

.

count[9] =1

- 2of 2 votes
You are given numbers from 1 through 100 in an array, there is one number missing, find that one

- 0of 0 votes
Suppose you are given one number decomposed in binary representation.

Input : 101011

Output : 000000

Needs to write algo and tell the approach in how efficiently we can flip the given input numbers to all zero's

Interviewer not mentioned about time complexity but it should be very efficient.

- 0of 0 votes
Design a job scheduler.

- 0of 0 votes
Design news aggregator like google news, without using pull, push or page crawl. Explain how are you going to scale it.

- 0of 0 votes
You are a cashier, and any item purchased in the store is in the range of 1c to 99c . Customer always pays 100 c i.e 1$. You need to deliver change with 25c, 10c,5c ,1c.

1. Code to get the most optimal solution with lease number of coins used

2. Some time in India 1 Rs = 150 ps and following coins were available {50,25,20,10,5,2,1}. Here if the change was 40, you should display 2 20ps and not 25ps,10ps,5ps. . What are the optimizations you will make

- 1of 1 vote
Given a 3-D array, if any m[r][c][d] is <=0 mark all the cells in the entire row,col and depth as zero and return the o/p array

- 0of 0 votes
Design event system, that is receiving events from various client (iPad,mobile,browser) across the world. It is getting approx 1 billion events /day. At any point of time the PM comes and says , retrieve how many events occurred in last 60s and we should be able to retrieve that

- 1of 1 vote
Given an integer array find all pythogorean triplets. a^2 + b^2 = c^2 print the a,b,c and their indexes

- 2of 4 votes
Given a Binary tree and a arbirary node of that tree , find all the nodes at a Distance of K from that Node .Nodes DONâ€™T have parent pointers

- 0of 0 votes
You are responsible for maintaining a web service that sits behind a load balancer. If the web service starts failing, how will you go about fixing it?

- 0of 0 votes
Design "YOU TUBE".

Like how do you upload/where to do you upload/how do you fetch/ how millions of incoming requests will be addressed.

Also take care of things like how do you provide services.

- 1of 1 vote
`In given array find zero and replace the entire row and column with zeros E.g Input: 1 2 3 4 5 6 7 8 9 10 0 11 12 13 14 15 Output: 1 2 0 4 5 6 0 8 0 0 0 0 12 13 0 15`

- 0of 0 votes
Write a function which verifies a binary tree where all leaf nodes are at the same level.

- 0of 2 votes
Design a Logging mechanism. Should be thread safe.

Initially i came up with Command Pattern, and write into a File. Was asked how i will synchronize multiple threads writing into Same File?

Later he gave hint about Aspect-oriented Programming(AOP). And also he gave a hint of Not always writing into the File, can also be a Mail,etc..

- 0of 0 votes
Implement a circular queue of integers of user-specified size using a simple array. Provide routines to initialize(), enqueue() and dequeue() the queue. Make it thread safe.

- 2of 2 votes
Write a function that receives three integer inputs for the lengths of the sides of a triangle and returns one of four values to determine the triangle type (1=scalene, 2=isosceles, 3=equilateral, 4=error). Generate test cases for the function assuming another developer coded the function

- 0of 0 votes
Identifying the number of occurrences of each palindrome in a file

- 1of 1 vote
Given 78 cents (target) you need to tell how many ways it is possible to make the change using 25 cents(quarter), 10 cents(nickel), 5cents(dime), 1cents(penny)

- 0of 0 votes
Given following definition, implement hashmap

`Public class HashMap { Public void put(object key, object value); Public void get(object value); }`

- 1of 1 vote
Given a sorted array with duplicates, move the distinct elements to the top

Ex: 1,1,2,3,4,4,5 -> 1,2,3,4,5

- 0of 0 votes
For a given string of some sentence, reverse words in that sentence. Ex: I am Don..return Don am I.