Problem statement:
Given an array of strings, remove each string that is an anagram of an earlier string, then return the remaining array in sorted order.
str = ['code', 'doce', 'ecod', 'framer', 'frame']
here you can find solution for to find anagrams
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'funWithAnagrams' function below.
#
# The function is expected to return a STRING_ARRAY.
# The function accepts STRING_ARRAY text as parameter.
#
def checkForAnagrams(word, arr):
for x in arr:
if (sorted(word) == sorted(x)):
return True
return False
def funWithAnagrams(text):
limit = len(text)
text.reverse()
final_text = list(text)
count = 0
for i in range(0, limit):
if text[i+1:] and checkForAnagrams(text[i], text[i+1:]):
final_text.pop(i - count)
count += 1
return sorted(final_text)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
text_count = int(input().strip())
text = []
for _ in range(text_count):
text_item = input()
text.append(text_item)
result = funWithAnagrams(text)
fptr.write('\n'.join(result))
fptr.write('\n')
fptr.close()
Fun with Anagrams
Making Anagrams. Solution Approach with code example. HackerRank Challenge
94 - Anagram | Strings | Hackerrank Solution | Python
Amazon D-E-shaw Snapdeal Interview Question | Anagram Palindrome #100DaysOfCode | code io | English
Question: Mary is an anagram of Army
function isAnagram(str1, str2){
let str1Arr = str1.split("");
let str2Arr = str2.split("");
str1Arr.sort();
str2Arr.sort();
if(str1Arr.join("") === str2Arr.join("")){
return true;
}
return false;
}