Amazon Interview Question

Determine if two strings are anagrams.

Interview Answers

Anonymous

May 8, 2012

public static boolean isAnagram(String s1, String s2) { boolean result = false; //Basic check for the length if(s1.length()!=s2.length()) return result; char c1[]= s1.toLowerCase().toCharArray(); char c2[]= s2.toLowerCase().toCharArray(); HashMap h = new HashMap(); //Put chars from c1 in hashmap one by one. First with value as 1; then if the same letter is present as key then increment the value for (int counter = 0; counter

1

Anonymous

Jul 23, 2012

if sort(s1) == sort(s2) then its an anagram

1