Introduction
Matrices have always been of interest in the field of encryption, specifically matrix rotations which leads to a symmetric as well as asymmetric cryptography. To learn more about regular matrix rotation please check my recent posts on the subject. This however is a fancy Ring wise Matrix Rotation and is no where related to the regular rotation of matrices.
Problem Statement
You are given a M*N grid with the restriction that the minimum of M and N is an even number. Rotate each of the rings by a distance K. We can choose the direction of rotation to be either clockwise or anti-c...

Read More
# interview questions

## Closest Pair Points

Introduction
A very interesting problem, indeed. I presume, not a complex one either. Here is what the problem statement looks like. "Given a set of N points in a plane, find the closest pair points". A question which is always asked in interviews in various forms, here we will not just look at the solution but will also understand the intuition behind the solution.
In the adjoining image, we have five points (A, B, C, D, E) in the plane. As a result of the solution we need to return one pair which has the smallest distance between them. Of course there can be multiple such pairs, we a...

Read More
## Pattern Finding – KMP Algorithm

Introduction
Now that you are fully equipped with the Boyer Moore Algorithm and have a notion of Pattern Finding. I would suggest you to get deeper into pattern finding. You can read about the benefits of pattern finding in my previous post about Boyer Moore.
This post will try to make you familiar with all the thought processes which you can use to exploit the known properties of texts and patterns using KMP Algorithm. However, Boyer Moore seems to be slightly intuitive, this one is a real geeky way of finding patterns.
Knuth Morris Pratt
Yes! this is what KMP stands for, you can learn ...

Read More
## Cloning Linked List having Next and Random Pointer

Introduction
This question was asked by a colleague, although it seems to be simple at first but with given restrictions like running time and space limitations, it becomes tricky. You need to be good with Linked Lists to crack the right solution.
Here we try to define the problem in more detail.
Given a Linked List where each node contains two pointers next and random. The next pointer points to the immediate next node and the random pointer points to any random node in the linked list. Clone the linked list and return the head of the clone.
There are definitely certain conditions impos...

Read More
## PostOrder Node Iterator of Binary Tree

Introduction
This is going to be a short post. The problem statement at hand is to write PostOrder Node Iterator of Binary Tree. For those who do not know the Iterator Design Pattern or Post Order Successor, check the next section.
Iterator Design Pattern
This pattern is used to iterate through a collection or group. The Java Iterator supports the following three methods :
hasNext() : returns a boolean true if the collection has elements after the last returned element, false otherwise.
next() : returns the next element in the collection.
remove() : removes the element from the coll...

Read More