Count the characters in a string that are neither letters nor digits

Quick Overview

Count how many characters in a string are neither ASCII letters nor digits, so spaces, punctuation and other symbols each count once per occurrence. The warm-up tests a single linear scan, exact character-range checks, and care with library helpers such as regex word classes that treat the underscore as valid.

Count the characters in a string that are neither letters nor digits

Company: Wells Fargo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given a string `s`, return the count of error characters in `s`. An **error character** is any character that is neither a letter (`a`-`z` or `A`-`Z`) nor a digit (`0`-`9`). Spaces, punctuation, and any other symbols are considered error characters. ### Function Signature ```python def error_count(s: str) -> int: ``` ### Rules - Count every occurrence. A string that contains two spaces gets 2 from those spaces. - Uppercase and lowercase letters are both valid. The underscore `_` is neither a letter nor a digit, so it is an error character. ### Constraints - `1 <= len(s) <= 10^5` - `s` consists of printable ASCII characters. ### Examples ```text Input: s = "hello world! 123" Output: 3 ``` The error characters are the two spaces and `!`. The other 13 characters are letters or digits. ```text Input: s = "AllGood123" Output: 0 ``` Every character is a letter or a digit, so there are no error characters. ```text Input: s = "a_b-c@1.0" Output: 4 ``` The characters `_`, `-`, `@` and `.` are error characters. The remaining five (`a`, `b`, `c`, `1`, `0`) are valid, and 4 + 5 matches the length of 9.

Overview: Count how many characters in a string are neither ASCII letters nor digits, so spaces, punctuation and other symbols each count once per occurrence. The warm-up tests a single linear scan, exact character-range checks, and care with library helpers such as regex word classes that treat the underscore as valid.

Wells Fargo logo
Wells Fargo
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given a string s, return the count of error characters in s.

An error character is any character that is neither a letter (a-z or A-Z) nor a digit (0-9). Spaces, punctuation, and any other symbols are considered error characters.

Function Signature

def error_count(s: str) -> int:

Rules

  • Count every occurrence. A string that contains two spaces gets 2 from those spaces.
  • Uppercase and lowercase letters are both valid. The underscore _ is neither a letter nor a digit, so it is an error character.

Constraints

  • 1 <= len(s) <= 10^5
  • s consists of printable ASCII characters.

Examples

Input: s = "hello world! 123"
Output: 3

The error characters are the two spaces and !. The other 13 characters are letters or digits.

Input: s = "AllGood123"
Output: 0

Every character is a letter or a digit, so there are no error characters.

Input: s = "a_b-c@1.0"
Output: 4

The characters _, -, @ and . are error characters. The remaining five (a, b, c, 1, 0) are valid, and 4 + 5 matches the length of 9.