## Recent Interview Questions

- 0of 0 votes
Given a array

{{ 4,7,3,6,7}}

construct a triangle like

{{81}}

{{40,41}}

{{21,19,22}}

{{11,10,9,13}}

{{ 4,7,3,6,7}}

- 0of 0 votes
Find the largest sum contiguous sub array. The length of the returned sub array must be at least of length 2.

- 0of 0 votes
Given an unsorted array of ints,sort the shortest sub-array which results in sorting of the whole array.

Ex:

i/p: [-1,0,4,3,2,1,7,8,9]

By sorting sub array [4,3,2,1] the whole Array is sorted.

i/p: [10, 15, 20, 30, 25, 40, 35, 45, 50, 60]

By sorting sub array [30, 25, 40, 35] the whole Array is sorted.

i/p: [-1,0,4,3,2,1,7,8,9,-2]

Shortest sub-arry to be sorted is [-1,0,4,3,2,1,7,8,9,-2]

- 0of 0 votes
if there is a tree

A

B C

C E

D F

G

Then write an API where new given a path lenghth

say length=5, then find the nodes havnig path length (5) traversing from all the leaf nodes and going up (by 5 levels) and print that node.

SO basically, all nodes that are 5 level up the leaf node is to be printed.

my solution:

perform a DFS , using a stack and a used a global variable counter=0

then

algo:-

if(pop)

counter++

if(push)

counter--

if(counter==5)

print node and initialise counter=0;

end....

- 0of 0 votes
Problem Link：https://code.google.com/codejam/contest/4214486/dashboard#s=p1

At new years party there is a pyramidal arrangement of glasses for wine. For example, at the top level, there would just be one glass, at the second level there would be three, then 6 and then 10 and so on and so forth like the following image

.

The glasses are numbered using 2 numbers, L and N. L represents the level of the glass and N represents the number in that level. Numbers in a given level are as follows:

Level 1:

1

Level 2:

1

2 3

Level 3:

1

2 3

4 5 6

Level 4:

1

2 3

4 5 6

7 8 9 10

Each glass can hold 250ml of wine. The bartender comes and starts pouring wine in the top glass(The glass numbered L = 1 and N = 1) from bottles each of capacity 750ml.

As wine is poured in the glasses, once a glass gets full, it overflows equally into the 3 glasses on the next level below it and touching it, without any wine being spilled outside. It doesn't overflow to the glasses on the same level beside it. It also doesn't overflow to the any level below next level (directly).

For example: When the glass of L = 2 and N = 2 overflows, the water will overflow to glasses of L = 3 and N = 2, 4, 5.

Once that the bartender is done pouring B bottles, figure out how much quantity in ml of wine is present in the glass on level L with glass number N.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of three integers, B, L, N, B is the number of bottles the bartender pours and L is the glass level in the pyramid and N is the number of the glass in that level.

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the quantity of wine in ml in that glass.

- 0of 0 votes
Given a graph where every two nodes are either friends or enemies with each other. Find a way to go from one node to the other.

Restrictions:

1) You can also travel from one node to next if they are friends with each other

2) You have some “magic potions”. You can convert an enemy path to a friend path with a magic potion.

I know this can be solved easily using dfs or bfs but i want to know the time complexity of each approach

- 0of 0 votes
There are two string pattern P and searching Expression Ex.. Ex is regular expression contains only # which stand for any character latest one length..

P:- ABABABA Ex:- A#B#A P and Ex are similar so its true.

example2. P: ABACBCB Ex:- A#B result:- true

Example:- P: ABCABCCE Ex:-A#C# result:- true, as P contains the expression as Ex

P: ABCABCCE Ex:-A#C false: P is doesnot contains the express like A#C

# --- means at least one or more character. In java language you have write the algorthim

- 0of 0 votes
There are two string pattern P and searching Expression Ex..

Ex is regular expression contains only # which stand for any character latest one length..

P:- ABABABA

Ex:- A#B#A

P and Ex are similar so its true.

example2.

P: ABACBCB

Ex:- A#B

result:- true

Example:-

P: ABCABCCE

Ex:-A#C#

result:- true, as P contains the expression as Ex

P: ABCABCCE

Ex:-A#C

false: P is doesnot contains the express like A#C

#--- means at least one or more character.

- 0of 0 votes
There are two string pattern P and searching Expression Ex..

Ex is regular expression contains only # which stand for any character latest one length..

P:- ABABABA

Ex:- A#B#A

P and Ex are similar so its true.

example2.

P: ABACBCB

Ex:- A#B

result:- true

Example:-

P: ABCABCCE

Ex:-A#C

false: P is doesnot contains the express like A#C

#--- means at least one or more character.

- 0of 0 votes
What is the diffenrce between join() and wait()?

What is sleep(). Which method releases the lock?

- 0of 0 votes
How can we implement asynchronous call in Java? Say I want to query Google but don’t want to use all the urls want to use later. How can we do that?

- 0of 0 votes
Whats the difference between quick sort and merge sort? Which one to use? Do we need file sorted before merge sort?

- 1of 1 vote
string x = "1..5,8,11..14,18,20,26..29"

string y = "1,2,3,4,5,8,11,12,13,14,18,20,26,27,28,29"

Write a C++ program to expand a given string x to y.

- 0of 0 votes
A certain language uses a set of characters from a-z but not in the same sequence as in english.

Now, words from the language appear in pair to you. e.g. LMOSS,NMOSS which implies that N comes after L, but not necessarily immediately after L. Similary, other words like{NMORR,TMORR}, { KSINN, KXINN }are also available.

What should be the data structure which should be used so that we can find out the character sequence in this language.

- 0of 0 votes
How to test a cheeseburger?

- 0of 0 votes
How long it will take to download a file containing all words of English dictionary on to the RAM

- 0of 0 votes
a music file is downloaded to your computer and you are listening a music you put a pause and you are going to somewhere and you came back and

you want to listen a music again and it is not working how do you trouble shoot and debug the problem?

- 1of 1 vote
We are given an unsorted array of n^2 arbitrary numbers, and we must output an n x n matrix of all the inputs such that all the rows and columns are sorted. For example, suppose n=3, n^2=9, and the 9 numbers are just the integers {1,2,...,9}

Possible ouputs include:`1 4 7 1 3 5`

`2 5 8 2 4 6`

`3 6 9 7 8 9`

Show how to sort this array with a Ω(n^2log n) lower bound.

- 0of 0 votes
Suppose we are given an array of strings over some finite alphabet(say the letters a to z). Each string can have a different number of characters, but the total number of characters in all the strings is n. Show how to sort the strings in alphabetical order in O(n) time.

- 1of 1 vote
Given an array of integers, but instead of all integers having the same length each can have a different number of bits. For example, the numbers 0 or 1 have 1 bit, 2, 3 have 2 bits, 4,5,6,7 have 3 bits. The TOTAL number of bits of all the integers in the array is n. Describe how to sort the array in O(n) time.

- 0of 0 votes
What is memory alignment in terms of compiler

- 0of 0 votes
what are types of memory issues one faces

- 0of 0 votes
Write a program to find 2 complement of number

- 0of 0 votes
How can we divide a large file between multi threads to process it? If we are running a multi threaded application and input is a large file and we have to provide each thread a part of the file to make it fast. How we can achieve it in java?

- 0of 0 votes
Mice and holes are placed in a straight line. There are n holes on this line. Each hole can accomodate only 1 mouse. A mouse can stay at his position, move one step right from x to x+1, or move one step left from x to x−1. Any of these moves consumes 1 minute.

Assign mice to holes so that the time when the last mouse gets inside a hole is minimized.

for example if there are 3 mice positions of mice are:

4 -4 2

positions of holes are:

4 0 5

the answer should be 4

because:

Assign mouse at position x=4 to hole at position x=4 : Time taken is 0 minutes

Assign mouse at postion x=-4 to hole at position x=0 : Time taken is 4 minutes

Assign mouse at postion x=2 to hole at postion x=5 : Time taken is 3 minutes

After 4 minutes all of the mice are in the holes.

- 0of 0 votes
Design an algorithm that, given a set S of n integers and another integer x,

determines whether or not there exist k (n>k>2) elements in S whose sum is

exactly x. Please give the running time of your algorithm

- 0of 0 votes
How can we use union find algorithm for finding the path between two points in a Maze

- 0of 0 votes
If we have all the variables and methods are as static. So would that class be thread safe?

- 0of 0 votes
Judgement Day

Skynet has figured out a way to take over the world. It will keep producing robots and molecular assemblers until it has converted all matter for its own purpose. Robots work to produce more robots and molecular assemblers. Molecular assemblers convert matter into programmable matter to be used to produce more robots and molecular assemblers.

Initial Info On day 0, Skynet started with 3 robots, 1 molecular assembler and 0 units of programmable matter.

On day i (i>0), robots produced can be calculated as the sum of the robots produced on the previous day and thrice the units of programmable matter produced on the previous day.

On day i, number of molecular assemblers produced can be calculated as the sum of robots produced on the previous day and twice the units of programmable matter produced on the previous day.

On day i, the units of programmable matter produced can be calculated as five times the number of molecular assemblers produced on the previous day.

How many robots, molecular assemblers and units of programmable matter will be produced on the Judgement Day (day n)?

Input/Output Specifications

Input format: Two integers x and y (1<=x,y<=10^6) such that the judgement day falls on day n = x*y.

Output format: Since the number of robots, molecular assemblers and units of programmable matter grows very rapidly, we want you to output them modulo 1000000007.

The output should be a string having the following format: R#M#P, where - R is the number of robots produced on judgement day modulo 1000000007 - M is the number of molecular assemblers produced on judgement day modulo 1000000007 - P is the number of units of programmable matter produced on judgement day modulo 1000000007

- 0of 0 votes
Distributing Medals It's the medal distribution ceremony. 10^6 police officers, numbered from 1 to 10^6, are standing in a line. There are N (1<=N<=1000) iterations of medal distribution. In iteration i (0 < = i < N), count[i] ( 1 < = count[i] < = 100) medals are given to all officers from from[i] to to[i] ( 1 < = from[i] < = to[i] < = 10^6 )

If we sum up the number of medals received starting from the first officer, who would be the first officer for which the cumulative sum exceeds a given medal count THRESHOLD ( 1 < = THRESHOLD < = 10^9 )?

Input/Output Specifications Input format:

You are given 5 inputs:

input1 = N, the number of iterations

input2 = count, the array of medal counts in each iteration

input3 = from, the array of starting indices in each iteration

input4 = to, the array of ending indices in each iteration

input5 = THRESHOLD, the medal count threshold

Output format:

An integer, representing the number of the first officer such that the cumulative sum of medals starting from the first officer upto this officer exceeds THRESHOLD. The output should be -1 if such an officer does not exist