Le migliori 150 intervisteFacile

Anagramma valido

Guida dettagliata e implementazione Python per il problema 'Anagramma valido'.

Dichiarazione del problema

Facile

Date due stringhe s e t, restituisce True se t è un anagramma di s e False altrimenti.

Un anagramma è una parola o una frase formata riorganizzando le lettere di una parola o frase diversa, utilizzando tutte le lettere originali esattamente una volta.

Scrivi una funzione isAnagram(s: str, t: str) -> bool.

Vincoli
  • 1 <= len(s), len(t) <= 5 * 10^4
  • s and t consist of lowercase English letters

Esempi

Example 1
Input
s = "anagram", t = "nagaram"
Output
True
Explanation

Both strings contain the same characters with the same frequencies: a(3), n(1), g(1), r(1), m(1).

Example 2
Input
s = "rat", t = "car"
Output
False
Explanation

'rat' contains 't' but 'car' does not. They have different character compositions.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche per array e hashing come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Apri nell'editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.