X

View By:

Q1 Maximum distance with 50 bikes and a tank of capacity 100 kms

There are 50 bikes with a tank that has the capacity to go 100 kms. Using these 50 bikes, what is the maximum distance that you can go ?

Q2 Maximize probability of picking a pen of a given color

Given 50 red pens and 50 blue pens, two jars(A,B) initially empty. These 100 pens are to be distributed b/w the jars such that the probability of picking a red pen is maximum.

Q3 Tree - Save and Reconstruct

How can you save a Binary Tree and re construct it later?

Q4 Complexity of build-heap procedure.

What is the complexity of build-heap procedure?

Q5 How to find all unique triplets in the set which gives the sum of zero?

Given a set S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the set which gives the sum of zero.

For example, given set S = {-1 0 1 2 -1 -4},

One possible solution set is:

(-1, 0, 1)

(-1, 2, -1)

Note that (0, 1, -1) is not part of the solution above, because (0, 1, -1) is the duplicate of (-1, 0, 1). Same with (-1, -1, 2).

For a set S, there is probably no "the" solution, another solution could be:

(0, 1, -1)

(2, -1, -1)

Q6 Print a matrix in a spiral order.

Given a matrix (2D array) of m x n elements (m rows, n columns), write a function that prints the elements in the array in a spiral manner.

Q7

Implement the following function, FindSortedArrayRotation, which takes as its input an array of unique integers that has been sorted in ascending order, then rotated by an unknown amount X where 0 <= X <= (arrayLength â€“ 1). An array rotation by amount X moves every element array[i] to array[(i + X) % arrayLength]. FindSortedArrayRotation discovers and returns X by examining the array.

Q8 How to print all edge nodes of a complete binary tree anti-clockwise?

Print all edge nodes of a complete binary tree anti-clockwise.

That is all the left most nodes starting at root, then the leaves left to right and finally all the rightmost nodes.

In other words, print the boundary of the tree.

Q9 How will you print a string in reverse order, using only putchar and nothing else.

Given only putchar (no sprintf, itoa, etc.), print a string in reverse order.

Q10

Given a string of lowercase characters, reorder them such that the same characters are at least distance d from each other.
Input: { a, b, b }, distance = 2
Output: { b, a, b }