Problem Statement
Given two strings, find the total number of characters we need to delete from these strings to make them anagrams of each other.
Understanding Anagrams
Anagrams are defined with respect to a given string of characters (not necessarily characters in the English Alphabet) but a wider set of characters may be.
Given two strings A and B, if the number of time each character occurs in both the string is exactly same, we say A and B are anagrams. However, the order in which the character appears may be different and doesn't matter.
For example
A = axbbxxcecdeedda
B = abacb...

Read More
# interview questions

## Arrays are permutation of each other

Problem Definition – Arrays are permutation of each other
The problem definition goes as follows: Given two arrays of equal length, find out if the elements of one array is the permutation of the elements of another array.
Of course the constraint is to solve it in constant space and linear time. Which means that the running time should be O(N) and auxiliary space required should be O(1).
Approach
There may be several thoughts which seem to work but eventually they will fail at one or the other ways. Here are few interesting ways which may not work for all the conditions:
XORing the ...

Read More
## Dutch Flag Problem

Problem Definition - Dutch Flag Problem
The dutch flag looks like the below image.
The problem "Dutch Flag Problem" derives its name from the arrangement of colors in the flag. The actual problem definition goes like this:
Given an array of balls of three colors ( Red, White and Blue). The balls are kept in random positions in the array. We need to develop a mechanism which can arrange the balls in groups (based on colors). Below is the image of a possible input and the expected output.
The balls of different colors in the above image are randomly distributed in the input where...

Read More
## Shift Zeroes To Right

Problem Definition - Shift Zeroes To Right
We are trying to solve a problem at hand in which we are given an array of zeroes and positive integers. We need to Shift Zeroes To Right and positive integers to the left without disturbing the relative order of the positive integers.
Approach
I try to solve the problem in a simple way, you may find a similar problem on the web, here is a approach which solves this problem in O(N) time using constant auxiliary space (may be one or two extra variables).
The first thing which comes in mind can be traversing the array and swapping zeroes with the ...

Read More
## Interview Question – Sorting Time Strings

Introduction
This is a pretty famous problem asked in most of the interviews, "Sorting the dates". This is not a complicated one but sometimes, it becomes real confusing or starts giving unexpected results, if not properly taken care of. To learn more about similar problems, please visit the Interview Section.
Do not forget to use the Subscribe feature on the right to get updates on new articles.
Problem Statement- Sorting Time Strings
You are given an array of Time objects in which the times are in the following format "13:24:56.123" i.e. "HH:mm:SS.Z" and you need to sort them in ascendin...

Read More
## Interview Question – Static variables

Introduction
This question was asked in a recent java interview in Goldman Sachs, this isn't complicated but candidates might get confused solving it. This is about static blocks and static variables initialization, so I publish this article under the heading Interview Question - Static variables. To get updates on the other articles in the series, please use the Subscribe feature on the right panel.
Problem Statement
What would be the result when the below code is executed?
[crayon-58ff0b89a2bb2850373289/]
Solution
What is the approach for solving this question?
Remember your b...

Read More
## Interview Question – Pirate and the Gold Chest

Interview Question – Pirate and the Gold Chest :
Once there were five pirates, each of them equally rational, intelligent and greedy. The pirates can be numbered as P1, P2, P3, P4 and P5 such that P5 has 1 years of service experience, P4 has 2 years of experience, P3, P2 and P1 has 3, 4 and 5 years of experience respectively.
One day they find a chest of 100 gold coins and they decided to divide it among themselves. Everyone being equally greedy wanted maximum profit, so they decided for the following solution:
1) Each pirate will get a chance to propose a distribution rule, and then a ...

Read More