Extending our story of Jay the Carpenter, O! you missed the beginning ? Check my previous post.
Last we heard from Jay, he was selling furniture happily and was able to define a strict process for franchises to follow and he also gave them freedom to make furniture as they like.
He basically controlled the post making process, where the customers would get a well painted, polished and packed furniture.
Of course the franchises were not very happy as they were not able to churn out more money after this was outlined. They thought of doing other nasty things. They figured out their own ...

Read More
# Interview Questions

This category contains few tricky questions asked in interviews..

## Factory Method Pattern

It is most likely that you read my previous post on the Misconceptions . If you missed that, then I would advice you to please read that, it is a small post.
So, in this post we will learn about few things:
What exactly is Factory Method Pattern ?
What purpose does it solve?
Where in JDK is Factory Method Design Pattern used?
Key points of Factory Method Design Pattern.
What exactly is Factory Method Pattern
Continuing our story from the previous post, where Jay is now happy with his shops and the simple factory setup. As a business grows people see it and try to earn profit f...

Read More
## Misconception about Factory Method Design pattern

Introduction
This post is intended mostly for beginners who want to understand the Factory Method Design Pattern. Yes! the name is Factory Method Design Pattern and not Factory Pattern.
It is very important for me to start with the misconception about Factory Method Design pattern, this is a starter post and you might not learn anything about the Factory Method design pattern here. But yes! I will tell you what is not a factory method design pattern.
The story
Once upon a time there lived a Carpenter Jay in a village. He had this nice way of making beautiful wooden furniture and he used ...

Read More
## Count Triangles formed by the elements of array

Problem Statement
Given a sorted array of distinct integers, each of these integers can represent a length. The task at hand is to count the number of possible triangles which can be made through these lengths.
Of course, if you chose one length to be one side of the triangle, you cannot use that length again in the same triangle. This means, no triangle contains the same length more than once.
Important Note: For given sides of lengths a, b and c. A triangle can only be formed if sum of any two sides is greater than the third side. This is called the triangle inequality. The sum of any...

Read More
## Median of a Stream of Integers

[nextpage title="Problem Statement"]
Here is a very interesting problem which has been asked in many interviews and coding competitions. The problem statement goes as follows:
Given a never ending stream of number, at any point in time, find the median of all the numbers received till that point.
This means, we need to recalculate the new median whenever there is a number available in the input stream. This problems seems to be a very practical one, imagine a lot of sensors in manufacturing plants are pushing data about temperature, pressure and other physical parameters. It is very importa...

Read More
## Save the largest area

Problem Statement
In the historic city of Technisia there are rectangular monuments made of stones. The monuments are placed on the ground in such a way that they all lie in one row. The width of each monument is one unit and the length may vary. The population of the city is growing and people need empty spaces to build houses and markets. The mayor decides to demolish the monuments and presents a demolition schedule.
You being a monument lover, would like to preserve the most of what can be preserved, hence you start finding a solution to save the largest area. Upon your request the may...

Read More
## Cursed Trees – Interview Question

Problem Statement
This is an awesome interview question which tests our ability to extensively use data structures.
We are given an array of trees with different heights. The trees have a curse upon them, they do not grow any more and for a given pair of trees, if a tree is taller than the one to its left then the tree will die in a year.
The task at hand is to find out, the number of years after which no trees will die.
Explanation
Year 1 : At the end of the first year the trees with height 6 , 14 and 10 will die. All of these trees have a smaller tree to their left and the r...

Read More