interview questions

Program to Detect if Two Strings are Anagrams


In the article, we will show how to find whether numbers are anagram. This article is part of interview preparation series.

What is anagram?

An anagram is a word or phrase formed by rearranging the letters of a different word or phrase in different order

For example: team and meat are anagram. Secure and rescue are anagram

How to check whether 2 words or anagram

To check out whether 2 words or phrases are anagram, you need to check whether each letter or words are common .



As you can see all of the characters are same, and just the differently arranged in both words.

Python code to find 2 words are anagram

def findAnagram(str1,str2):
		return "Not found"

	str_arr1 =list(str1)
	str_arr2 = list(str2)
		if(str_arr1[j] in str_arr2):
			return "Not found"
	return "Found"


End note

In the article, you have seen how to check anagram in string in Python.

If in case you have doubt regarding implementation, please feel free to share us your concerns in discussion thread below, or mail us to

This article is for technical interview preparation. Find more useful programming exercises in link below.

  • How to check whether string is palindrome or not
  • How to find prime numbers between a given range
  • How to check whether number is Armstrong number

Xamnation is helping students in interview preparation and learning programming language. We are offering live classes, study material and interview preparation course. Please find below useful course.

  • Aptitude preparation course for job interviews
  • Puzzles course for job interviews
  • Python course for job interviews
  • Amazon job preparation course
  • TCS job preparation course

Leave a Comment

Your email address will not be published. Required fields are marked *