Valid Anagram

Beginner Problems Basic Strings Easy
  • Fun Fact: The concept of checking for anagrams, as given in the problem, has practical uses in natural language processing and computer science
  • This logic is often incorporated in games such as Scrabble or Words with Friends, where users must form words from a given set of letters
  • It is also used in spell-checking algorithms and plagiarism detection software to spot potential copy-pasting by comparing anagrams
  • Highlighting the versatility of this concept, it is also applied in bioinformatics where it is necessary to look for anagrams in DNA sequencing, which can support meaningful discoveries in genetics

Given two strings s and t, return true if t is an anagram of s, and false otherwise.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Examples:

Input : s = "anagram" , t = "nagaram"

Output : true

Explanation : We can rearrange the characters of string s to get string t as frequency of all characters from both strings is same.

Input : s = "dog" , t = "cat"

Output : false

Explanation : We cannot rearrange the characters of string s to get string t as frequency of all characters from both strings is not same.

Input : s = "eat" , t = "tea"

Constraints

  • 1 <= s.length , t.length <= 5*104
  • s and t consist of only lowercase English letters

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree