## SDE1 Interview Questions

- 0of 0 votes
Given a continuous stream of strings, maintain strings such that duplicate are eliminated on the fly. The interviewer wanted working code. So coded the solution during the interview and emailed it to him 10 mins after.

So if you get “Ted”, “John”, “Mark”, “Ted”, “David”, at the moment in

time, the list should contain John, Mark, David

- 0of 0 votes
Foo was not amongst the most brilliant students of his class. So, he has some pending exams to clear. As the exams are approaching, this time he vowed to pass in all of them. This will only happen if he is not under stress. Foo's stress can be calculated using a simple function called Foo_function which depends upon the time for which Foo studies continuously .

Foo_funtion is defined as follows:

F(t)=A(t^3)+B(t^2)+C*(t)+D, F(t)<=10^18

where A,B,C,D belong to the set of prime numbers. t is the time in minutes for which foo studies continuously.

As foo is not very good at solving cubic equations, he seeks your help to find out the maximum number of minutes for which he can study continuously without taking stress. Help him find t such that F(t+1) > K, and F(t) <= K, where K is the maximum stress Foo can bear.

Input:

The first line of the input contains a single integer T denoting the number of test cases. each test case consists of a single line containing 5 space seperated positive numbers a, b, c, d, K.

Output:

for each test case, output a single integer t denoting the maximum time for which foo can study continuously without taking stress.

Constraints:

1 <= T <= 10^4

A, B, C, D belong to a set of prime numbers such that F(t) would never exceed 10^18

t >= 0

1 <= K <= 10^18

Sample Input (Plaintext Link)

2

2 2 2 2 10

2 3 5 7 1000

Sample Output (Plaintext Link)

1

7

Explanation

In the 1st test case for t = 2 foo will be under stress because F(2)=30 > K, therefore he can study for a maximum time of 1 minute without having stress.

In the 2nd test case for t = 8 foo will be under stess because F(8)=1263 > K, therefore he can study for a maximum time of 7 minutes continuously without having stress.

Time Limit 5 sec(s) (Time limit is for each input file.)

Memory Limit256 MB

Source Limit1024 KB

- -1of 1 vote
Given a integer N, print the decimal form of 1/2n.

Example:

N=1, print 0.5

N=2, print 0.25

Adding leading/unsignificant zeroes will lead to wrong answer. Example, printing 0.50 instead of 0.5 in above case will lead to wrong answer.

Input and Output:

First line contains T, the number of testcases. Each testcase consists of N in one line.

Print required answer in one line for each testcase.

Constraints:

1 ≤ T ≤ 100

1 ≤ N ≤ 200

Sample Input (Plaintext Link)

2

2

1

Sample Output (Plaintext Link)

0.25

0.5

Explanation

You need to print output in decimal form only. There is no limit on number of decimal digits in output.

So correct output of 100 will be "0.0000000000000000000000000000007888609052210118054117285652827862296732064351090230047702789306640625"

Time Limit1 sec(s) (Time limit is for each input file.)

Memory Limit256 MB

Source Limit1024 KB

- 0of 2 votes
Use smart ways to find prime factors and then arrive at the result for large A & B in input. Bruteforce won't work.

Given A,B print the number of pairs (a,b) such that GCD(a,b)=1 and 1<=a<=A and 1<=b<=B.

Input:

First line contains an integer T, the number of testcases. Each of next T lines contains two space separated integers denoting Aand B.

Output:

Output T lines, each containing single integer, the required output for each test-case.

Constraints:

1 <= T <= 10

1 <= A <= 10^5

1 <= B <= 10^5

Sample Input (Plaintext Link)

1

3 2

Sample Output (Plaintext Link)

5

Explanation

1,1

1,2

2,1

3,1

3,2

Time Limit5 sec(s) (Time limit is for each input file.)

Memory Limit256 MB

Source Limit1024 KB

- 1of 1 vote
Given a BST, find out the minimum length form root to leaf with sum S. Note that:

a) Path from root to leaf node.

b) Sum of node of the path is S.

c) if multiple such path exist, print minimum length path.

d) What is advantage of BST rather than BT used for this algorithm, how it improve the performance. in BST, is it required to explore both side ?

- 1of 1 vote
You have given M array each of size n all array are sorted separately write a program to make a big sorted array of size m*n . during discussion he told me to prove many lemma like height of tree is log(n)( for n elements) sum of n natural number is (n*n+1)/2 and many more. He modified problem many times don’t use extra space do it in space etc.

- 1of 1 vote
Write a program to convert a decimal number into binary your code should work on both big endian and small endian machine. U have given a variable which tell u whether machine is big endian or small endian

- 0of 0 votes
U have given 10 files and you have given a string suggest data structure which ll facilitate efficient search of string in the file if string appears more than ones in that case u have to print line number and file in which they appear.

- 4of 6 votes
You are given a sequence of black and white horses, and a set of k stables numbered 1 to k. You have to accommodate the horses into the stables in such a way that the following conditions are satisfied:

a. You fill the horses into the stables preserving the order of horses. For instance, you cannot put for horse 1 into stable 2 and horse 2 into stable 1. You have to preserve the ordering of horses.

b. No stable should be empty and No horse should be left unaccommodated.

c. Take the product (number of white horses * number of black horses) for each stable and take the sum of all these products. This value should be the minimum among all possible accommodation arrangements.

- 2of 2 votes
Given a floor of dimensions 2 x W and tiles of dimensions 2 x 1, write code to find the number of ways the floor can be tiled. Any suggession for this?

- 0of 0 votes
Let's say a website attracts a lot of traffic . How would you find at what instant of time (milliseconds or seconds , assume as you want) the traffic was super high ? What data structure would you go for and why ?

- -2of 2 votes
Draw a graph as a graph. Assume there is graphics library to draw lines and all. Just tell how will you order the vertices such that the edges don't intersect and they seem ordered.

- 0of 2 votes
Need to implement something like pastebin wherein you paste some text, you are given an url. The url can be used anywhere to access the text.

Various problems, features and design of this architecture were discussed.

- 0of 0 votes
There are N lanes, and the speed of each lane is given. There are many cars in all the lanes and the start position and the length of each car and its corresponding lane is given. There is a frog which an do 2 functions: wait() or jump().

Find if there is a path for the frog to go from lane 1 to lane N without getting hit by any of the moving cars.

- 0of 0 votes
You are given very huge file , with each line containing a single word. We have to give the count and word which is repeated most. I answer of using TRIE data structure to hold the word. I am reading a word at a time and incrementing the counter if i am getting the same word. I am keeping a global max count to keep the max count and the word. Complexity will be O(total letters in the file);

- 0of 0 votes
Given a binary search tree (BST) with each node having some value. You have to compute for each node the summation of all nodes whose value is greater than the current node.I have used the DFS kind of algorithm.

`Dictionary<node,bool> visited = new Dictionary<node,bool>(); int Traverse(node n ) { if(node.Right == null) if(node.Left != null && !visited(node.Left)) Traverse(node.Left); return node.value; node.Summation = Traverse(node.Right); if(node.Left != null && !visited(node.Left)) Traverse(node.Left); return node.Value + node.Summation; }`

- 0of 0 votes
Given a table of the form:

1 A,B,C,A,B

2 A,B,A,A,A

3 C,D,C

Give the number of duplicate characters, eg: for 1 there are 2 A's and 2 B's, so the result is 2

For 2 A is repeated 4 times so the result is 3

For 3, C is repeated twice so the result is 1

My suggestion was to use a CLRSQL function to calculate it

- 0of 0 votes
Provided a number dictionary and a number, x , which is formed from the number dictionary. Find the rank of the number x? Rank is defined as the position of the number x when all the number formed from the dictionary are sorted.

Example

Input :{4,1,5}

X : 451

Output : 4

(145,154,415,451,514,541). 451 comes at 4th position

- 0of 0 votes
Write a binary search function in C that will work for any datatype. You cannot accept the datatype in the function arguments.

- 0of 0 votes
write a program to generate random numbers without using the in-built functions?

- 0of 0 votes
Machine Coding 1 hour

------------------------------

U have an organizational structure, which shows hierarchy of the organization. This hierarchy contains employees E or managers M who has some Employees or Managers reporting to M.

Employee has ( id, name, JobDesc, salary etc).

Design the data structure you would be using to store this hierarchy

problem 1: Given an ID of an employee , print all the employee ID's who are directly reporting or indirectly reporting to the manager.

problem 2: prefix search of employees by String. If employees have nishant and nikhil. If searched by "ni" we need to print all details of both nishant and nikhil.

problem 3(bonus): search should print all emloyee's and their details if a given string is subString of the name of an employee.(Like a phonebook contacts search)

P.S- This was asked to one of my friend in Flipkart.

- 4of 4 votes
Given a random generator rand(5) which generates numbers between 0 to 4. How do u generate numbers between 0 to 6, I.e. Implement rand(7).

- 4of 4 votes
Car parking problem. An array given represents actual order of cars need to be parked. Like for example order is 4,6,5,1,7,3,2,empty. If cars are parked in some order like empty,1,2,3,7,6,4,2. Some person needs to get them into correct order, list out all instructions to the person to get in correct order with least number of swaps.

- 0of 2 votes
given a N x N matrix find the no. of times a word is present in that matrix. constraints you can move in 3 directions from one cell 1. forward , 2. down 3. diagonal . Find all teh occurance of all the word

forward means right (x+1,y)

down mean (x,y+1)

diagonal means (x+1,y+1)

it can be done with BFS. {search the no. of occurance of a given word example "sachin" in the whole NxN matrix}

w | s | r | t | g | g|

a | a | c | h | i | n |

k | c | h | u | j | j |

o | h | i | n | y | q |

in this sachin can be found out 3 times.

- 1of 1 vote
Given a huge file 100 million integers. He further divided the file into 100 files with 1 million integers in each and each file is sorted. Needed to find the k smallest integers.

I used the concept of min-heap. Take the first element from each file and construct a min-heap. Take the root,as it is the smallest element and insert the next element from the file which contains the root root element. Heapify the tree and repeat k times.

The interviewer asked if another efficient method exists?

- 3of 3 votes
Given a set of intervals like 5-10, 5-10, 8-12, 9-15

Find the ith smallest number in these intervals.

for eg:-

Suppose we have intervals like 5-10, 8-12.

Then total numbers in these two intervals would be: {5,6,7,8,8,9,9,10,10,11,12}

So, 1st smallest number: 5

4th smallest number: 8

5th smallest number: 8 (here is the

change since now we have duplicate elements also) and so on.

- 0of 0 votes
Sliding window problem where window size is 3 and we need to find the minimum from the window.

- 0of 0 votes
Given a list with duplicate values find the first unique elements in it.

for eg: BH BH F AL HJ AL HJ PK

so answer is F

- 0of 0 votes
Given a matrix and need to traverse through it last position from first position and the matrix has 0 and 1 if there is 1 we cant proceed ahead.

- 0of 0 votes
Compare two release version and tell me which is larger

eg: 1.0.10 and 1.0.2

1.0.2 is greater

1.2.0 and 2.1.0

2.1.0 is greater