Fácil 0 resueltos 0% de aceptación

Anagram Check

Check whether two phrases use the same letters.

Lo que aprenderás

  • Normalize text by case and spaces
  • Compare letter counts or sorted letters
  • Choose between sorting and counting

Problema

Ver traducción

Two phrases are anagrams if they contain exactly the same letters the same number of times, ignoring case, spaces and punctuation.

Implement is_anagram(first, second).

Input

first: The first phrase. second: The second phrase.

Output

Return true if the phrases are anagrams.

Restricciones

0 ≤ length of each ≤ 10,000 (ASCII)

Ejemplos

Ejemplo 1
Entrada:
first = "Listen"
second = "Silent"

Salida esperada:
expected = True
Entrada:
std::string first = "Listen";
std::string second = "Silent";

Salida esperada:
bool expected = true;
Entrada:
string first = "Listen";
string second = "Silent";

Salida esperada:
bool expected = true;

Explicación

Both use e, i, l, n, s, t once each.

Ejemplo 2
Entrada:
first = "apple"
second = "paddle"

Salida esperada:
expected = False
Entrada:
std::string first = "apple";
std::string second = "paddle";

Salida esperada:
bool expected = false;
Entrada:
string first = "apple";
string second = "paddle";

Salida esperada:
bool expected = false;

Explicación

The letters and counts differ.

Cómo abordarlo

Inténtalo primero por tu cuenta y luego abre las pistas una a una.

Pista 1

Remove non-letters and ignore case before comparing.

Pista 2

Count character frequencies for both phrases, or sort their normalized forms.

Pista 3

Punctuation and spaces should not affect the result.

Complejidad esperada

O(n) time, O(1) extra space

Referencias

Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.

Aprende de otros

Soluciones de la comunidad

Aún no hay soluciones publicadas. Resuelve este reto para compartir la primera.