Write a code to find if two words are anagrams
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
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
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
public boolean isAnagram(String s, String t) { char[] sortedS = Arrays.sort(s.toCharArray()); char[] sortedT = Arrays.sort(t.toCharArray()); return Arrays.equals(sortedS, sortedT); }
ArrayList
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
Top KPIT Technologies Senior Software Engineer interview questions & answers
Popular interview questions of Senior Software Engineer
Top HR questions asked in KPIT Technologies Senior Software Engineer
Reviews
Interviews
Salaries
Users/Month