Anagram Check
Python
Medium
4 views
Problem Description
Input has two strings a and b are provided (lowercase letters). Output YES if they are anagrams else NO.
Input Format
Two lines: a then b.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if len(lines)<2: sys.exit(0)
a=lines[0].strip()
b=lines[1].strip()
if len(a)!=len(b):
sys.stdout.write('NO')
else:
ca=[0]*26
cb=[0]*26
for ch in a:
ca[ord(ch)-97]+=1
for ch in b:
cb[ord(ch)-97]+=1
sys.stdout.write('YES' if ca==cb else 'NO')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!