Algoritme & struktura të dhënash

Checking anagrams & permutations of strings

Në shqip: Kontrolli i anagrameve

ShpjegimiSQ

A janë dy fjalë anagrama? Numëro shkronjat e secilës me një fjalor (O(n)) ose rendit të dyja dhe krahaso (O(n log n)). Me dritare rrëshqitëse kontrollon nëse një permutacion gjendet brenda një teksti tjetër.

EnglishEN

Are two words anagrams? Count each word's letters with a dictionary (O(n)) or sort both and compare (O(n log n)). With a sliding window you check whether a permutation appears inside another text.

Si ta mendosh

Si të kontrollosh nëse dy thasë kanë saktësisht të njëjtat shkronja Scrabble.

Lexoje në anglisht

Like checking whether two bags hold exactly the same Scrabble tiles.

Shembull kodipython

from collections import Counter
print(Counter("listen") == Counter("silent"))   # True

Terma të lidhur