Introduction
This is another interesting interview question and took me sometime to think for an answer. The problem statement goes as follow:
"There are wine glasses stacked such that the top level has one glass, the second level has two glasses, the third one has three glasses and so on.
Imaging that the levels are deep enough. Each of the glass in the stack has volume u. Now given a jug of volume V full of wine such that V >= u, find the lowest level where wine can reach."
Analyzing the problem statement
Here is a supporting image for the problem statement.
Now I pick up the ju...

Read More
# interview questions

## Student Enrollment Interview Question

Introduction
This is another interview question which I find interesting. The problem statement goes as follow:
"Its the beginning of a new academic year and I am a teacher of Data Structures and Algorithm subject. Many students with distinct roll numbers want to enroll for the class. After sometime few students wanted to opt out from the enrollment because they found some other subject much more interesting. Now, I also have a teaching assistant who can ask me the roll number of a student who is still enrolled into my class. It is not mandatory to tell him a different roll number every ti...

Read More
## Polynomial Operations

Introduction
This is a famous interview question where it is asked to write program for simple arithmetic polynomial operations. The operation may include adding, subtracting and multiplication of two polynomials (mostly in one variable).
For those who want to refresh their knowledge of polynomials, I would include a section below:
Understanding Polynomials
Polynomials are mathematical expressions of the form a1xnym + a2xn-1ym-1+ . . . + akxn-ky + . . . + anx + an+1.
The above polynomial is said to be a polynomial in two variables (x and y).
a1xn + a2xn-1 + a3xn-2 + . . . + an-1x + ...

Read More
## Combination of Numbers

Introduction
I already have one post on this blog which explains the permutations code, now its time for the combinations.
The idea behind Combination of Numbers
Combination by definition is a concept of discrete mathematics which essentially relates to the act of selecting a list of items from a collection. For e.g. If I have to pick up 3 fruits from a basket of 10 fruits then what all ways are there to pick them up? Combinations is the answer to this question.
Let us say that I picked an Apple, a Banana and a Strawberry from the basket, then it really won't matter in what order I pi...

Read More
## Interleaving Strings

Problem Statement
This is a question from one of the interview experiences. The statement, "Given three strings A, B and C find if C is an interleaving of A and B." Interleaving is defined as below:
A string C is said to be an interleaving of two strings A and B if C contains a sub sequence of A and B such that the relative order of characters in A and in B are preserved in C.
For e.g. :
A - ABCD
B - BACDX
C - ABACDXBCD
The Idea - Interleaving Strings
Here I am not giving any solution which is less than O(M*N) solution where M is the length of the shortest string among A and B...

Read More
## Find Frequency In Sorted Array

Problem Statement
This is a question from one of the interview experiences. You are given a sorted array of numbers (this can be extended for arrays of characters, strings and what not) and a number K. Find the number of occurrences of K in the array.
Solution
Yes you got that right, it is really very simple. Walk through the array sequentially and if you get K then start counting till you get anything bigger than K. You can break out of the loop after this and the counter will tell you the obvious answer.
So, why am I even writing this post?
Because this is not fun, the above approach te...

Read More
## Find Pair of Numbers in Array with a Given Sum

Problem Definition
This problem has appeared in many interviews as well as the qualifying round of Google Code Jam in the past. There are various versions of the problem. To list a few:
Find Pair of Numbers in Array with a Given Sum - The array is unsorted and contains a given range of numbers bounded by min and max.
Find Pair of Numbers in Array with a Given Sum - The array is sorted and contains a given range of numbers bounded by min and max.
Find Pair of Numbers in Array with a Given Sum - The array contains unique numbers only.
In all the above versions, we have to return the ...

Read More