Given two strings s1 and s2, check if both the strings are anagrams of each other.
Input : s1 = "listen" s2 = "silent" Output : The strings are anagrams. Input : s1 = "dad" s2 = "bad" Output : The strings aren't anagrams.
Python provides a inbuilt function sorted() which does not modify the original string, but returns sorted string.
Below is the Python implementation of the above approach:
The strings are anagrams.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check whether two strings are anagram of each other
- Check whether two Strings are Anagram of each other using HashMap in Java
- Using Counter() in Python to find minimum character removal to make two strings anagram
- Python Dictionary | Check if binary representations of two numbers are anagram
- Longest common anagram subsequence from N strings
- Remove minimum number of characters so that two strings become anagram
- Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character
- Python | Check if list is sorted or not
- Search in an array of strings where non-empty strings are sorted
- Python | Check for Descending Sorted List
- Check if any anagram of a string is palindrome or not
- Check if binary representations of two numbers are anagram
- Check if binary representation of a given number and its complement are anagram
- Python - Check if two strings are Rotationally Equivalent
- Python | Check if substring is part of List of Strings
- Number of sub-strings which are anagram of any sub-string of another string
- Meta Strings (Check if two strings can become same after a swap in one string)
- heapq in Python to print all elements in sorted order from row and column wise sorted matrix
- Anagram checking in Python using collections.Counter()
- Python Counter to find the size of largest subset of anagram words
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.