Problem · String

Check Anagrams

Learn this problem
EasyDeloitte logoDeloitteFULLTIMENEW GRADONSITE INTERVIEW

Problem statement

You are given two strings s and t.

Determine whether the two strings are anagrams of each other. Two strings are anagrams if they contain exactly the same characters with the same frequencies, possibly in a different order.

Return 1 if the strings are anagrams, otherwise return 0.

Function

checkAnagrams(s: String, t: String) → int

Examples

Example 1

s = "listen"t = "silent"return = 1

listen and silent contain the same letters with the same frequencies.

Example 2

s = "race"t = "care"return = 1

race and care are anagrams.

Example 3

s = "hello"t = "world"return = 0

The two strings do not have matching character frequencies.

Constraints

  • s and t consist of printable characters.
  • The comparison is case-sensitive.

More Deloitte problems

drafts saved locally
public int checkAnagrams(String s, String t) {
  // write your code here
}
s"listen"
t"silent"
expected1
checking account