Skip to main content


Showing posts from July, 2017

LCM of two numbers

In this post we discuss a method to find out LCM (least common multiple) of 2 numbers, LCM of 2 numbers is the least number that is divisible by 2 numbers.

for example, if we consider 4 and 5 then their LCM is 20.

Though there are a lot of methods to find LCM of 2 numbers here I will focus on find LCM using GCD of 2 numbers. Consider 'A' and 'B' to be 2 numbers so we calculate LCM  by using the below formula

The product of the numbers is equal to the product of their GCD and LCM. 
A * B = GCD(A,B) * LCM(A,B)

If you want to know about GCD of 2 numbers then follow my post on GCD Here.

In the following programs, we first find the GCD of 2 numbers and then divide the product of two numbers by the GCD to LCM of the numbers.

C ProgramC++ ProgramJava programPython Program C Program C++ Program Java Program Python Program You might also be interested in 

Anagram StringsDouble Linked List
Finding Middle node in a Linked List
Infix to Prefix Conversion
Infix to Postfix Conversion
Binary Sear…

Check is given strings are Anagrams

Checking if 2 given strings are anagrams or not is one of the most common and easiest interview questions which is often asked in interview coding rounds. In this post we discuss method to identify if 2 strings are anagrams or not.

2 strings or words or phrases are said to be Anagrams if they are formed by rearrangement of same letters.
For example we consider "HOST" and "SHOT" they are formed by rearrangement of letters H,O,S,T.
We can find a lot of such examples.

Let us now discuss the method to check if 2 strings are anagrams.

First we remove all the white spaces from the given strings.For strings to be anagrams the length of the strings after removing white spaces must be same, so we compare lengths.if the lengths are equal then we move forward.else we stop as the length of the strings must be same.The next step is to convert the string to lowercase, this step is optional and you can choose not to do it depending on your requirement.Then we need to sort all the char…