Problem Statement
Another question which is favorite among interviewers is rotating an array by a fixed distance. Before understanding how can we do that, it is important to understand what it means to rotate an array. Given an array of length N, rotation by a fixed distance K means shifting each element to the right by K indices. The indices of course are computed in a rotational manner such that if the new index of the element goes beyond the array boundaries, it can be wrapped to the beginning of the array.
Here is an example of input and output.
The problem seems very easy until s...

Read More
## Removing Duplicates from Sorted Linked List

Problem Statement
You are given a singly sorted linked list, which has repeated elements. The task at hand is to remove the duplicates from the linked list.
Here is a diagram to explain the problem statement
Solution for Removing Duplicates from Sorted Linked List
As the linked list is sorted, if two nodes contain duplicates, they will always be adjacent to each other. Hence, the trick is to
Maintain two pointers (Current_Node_Ptr and Next_Node_Ptr).
If the Next_Node_Ptr points to a duplicate node, delete the node and advance the Next_Node_Ptr
Make the next of Current_No...

Read More
## TechieMe New Android App

Hello there! I have recreated a completely new and better android app for this blog. Have a glimpse of the new UI and features below
This app is a companion to the this programming blog and a possible improved replacement to the older version
This is an ever increasing knowledge repository, with classic and configurable user interface and awesome user experience. The content is cleanly segregated and presented.
The app contains posts on topics like:
1) Java/J2EE
2) Algorithms
3) Datastructures
The Send a Suggestion feature allows you to request ...

Read More
## Find the Point of Rotation in Sorted Array

Problem Statement
You are given a sorted array. However, there is a problem. Someone just rotated the sorted array by K spaces and we do not know the value of K.
Write a program to find the value of K by which the array is rotated. As the array has millions of numbers, it would be good to have a solution which takes minimal time.
Approach to Find the Point of Rotation
Brute Force
Let us try out my favorite approach, the Brute Force Method. It is quite simple, below are the steps:
Start traversing the array from the beginning
There will be a index in the array where the value sto...

Read More
## Find the maximum possible profit

Problem Statement
Given an array of stock prices per share for a given share over a time period. Calculate the maximum possible profit per share one could have made . Here we do not consider short selling as an option. The trader must have purchased the stocks before selling it.
The problem statement is a real world definition of the problem called maximum positive difference.
For the above two arrays, here are the maximum profit per share one could have made:
A : 18.0 (difference between 21 and 3)
B : 13.0 (difference between 19 and 6)
What is Maximum Positive Difference?
...

Read More