Prompt
Replace each letter of a string with its position in the alphabet (A=1, B=2...). Ignore spaces and non-letters. Strip accents before converting.
Solution
This is a character-code mapping problem — the class of tasks where you convert between characters and numbers (Caesar ciphers, base conversions, hashing). The key fact: 'a'.charCodeAt(0) is 97, so code - 96 maps a–z onto 1–26. Memorize 97 (a) and 65 (A); interviewers use them as a fluency check.
The pipeline shape matters as much as the math: normalize → filter → map → join. Each stage does one thing, each is O(n), and the whole thing stays O(n) time, O(n) space. Filtering with the range comparison c >= 'a' && c <= 'z' (strings compare lexicographically) cleanly drops spaces, digits, and symbols after accents have been decomposed — "ñ" becomes "n" via NFD before it reaches the filter, so it converts instead of vanishing.
There's no meaningfully faster approach — the naive and optimal solutions are both linear — so the differentiator here is correctness on dirty input, not complexity.
Red flag: filtering before stripping accents. In that order "é" is rejected as a non-letter and silently disappears from the output — the classic Unicode-ordering bug. Normalization must be the first stage of the pipeline.
Say it: "charCodeAt minus 96 maps lowercase letters onto 1–26; I normalize accents first so filtering only ever sees plain ASCII letters."