Skip to content

Different Symbols Naive

Given a string, find the number of different characters in it.

Example

For s = "cabca", the output should be

different_symbols_naive(s) = 3

There are 3 different characters a, b and c.

Input/Output

  • [input] string s A string of lowercase English letters.

Solution

py
def different_symbols_naive(s):
    return len(set(s))


print(different_symbols_naive('cabca'))
js
function differentSymbolsNaive(s) {
  return new Set(s).size;
}

print(differentSymbolsNaive('cabca'));

my thoughts are neither my employer's nor my wife's