Problem Statement
You are given an array which contains an increasing sequence of numbers from 1 to N. There is one number missing in the sequence. The task at hand is find the missing number in minimum running time.
Input: An array A of numbers in increasing order, with one number missing.
Output: The missing integer
Constraint: The sequence is strictly increasing. The algorithm should finish in minimum time.
Approach for Finding Missing Number
At first, it looks like a simple problem which can be solved in O(N) time. Indeed it is. Here are the steps:
Start traversing from the...

Read More
# Interview Questions

This category contains few tricky questions asked in interviews..

## Data Structure for Efficient Search

Problem Statement
Given one million 10 digit unique integers, design an efficient data structure which has lowest time complexity for searches. You are given ample amount of space and the time for building the data structure and populating it is not judged.
The only criteria is to offer efficient searches.
Thought Process for Efficient Search
The numbers are 10 digit unique integers and we need a data structure which can offer search in near constant time. The problem is similar to finding if a word exists in a dictionary. Its just that the Strings are replaced by the 10 digit numbers.
...

Read More
## Maximum Element Sliding Window

A very interesting problem indeed! Often asked in Interviews in various forms and we will discuss one of these forms here in this post.
Problem Statement - Maximum Element Sliding Window
Given a stream or array of elements (preferably integers). Find the elements with maximum value in a window of length K where the window slides by one step to the right every time.
What is a Sliding Window?
Given an array A, a sliding window of length K is a range of fixed size K in the array such that the range slides to the right by one index. Here is a diagram to explain how sliding window will look...

Read More
## The Pitfalls of Singleton Design Pattern

Yes! its true that a Singleton object is the loneliest construct in Programming. :) Let us keep the humor aside and listen to this interesting story.
Last time we had a fun story while understanding the Factory Method Design Pattern. This time let us have a story from one of our software developers Manish. He wants to create this wonderful application.
An awesome application
This application uses the socket connections heavily and has to write data over the network. Manish wrote a code which works great. Every time he wants to use the connection he creates one and starts using it. In no ...

Read More
## Abstract Factory Pattern

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