Write a code to find if two words are anagrams

AnswerBot
1y

Code to check if two words are anagrams

  • Convert both words to lowercase

  • Remove all spaces and punctuation

  • Sort the characters in both words

  • Compare the sorted words

Anonymous
1y

import string

class AnagramChecker:

def init(self, word1, word2):

self.word1 = word1

self.word2 = word2

def preprocessword(self, word):

word = word.lower()

word = word.translate(str.maketrans('', '',...read more

Sharath Krishana
1y

def are_anagrams(word1, word2):

word1 = word1.replace(" ", "").lower()

word2 = word2.replace(" ", "").lower()

if len(word1) != len(word2):

return False

char_freq1 = {}

char_freq2 = {}

for char in word...read more

Amitabh Soni
1y
public boolean isAnagram(String s, String t) { char[] sortedS = Arrays.sort(s.toCharArray()); char[] sortedT = Arrays.sort(t.toCharArray()); return Arrays.equals(sortedS, sortedT); }
HARSHA
1y

ArrayList ee=new ArrayList(String);

for(int i=0;i

{

ee.add(s1.charAt(i));

}

int c=0;

for(int i=0;i

{

if(ee.contains(s2.charAt(i))

{

c++;

}}

if(c==s1.length(...read more

Add answer anonymously...
KPIT Technologies Senior Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter