Problem · String
Concatenate Non-Alphabetic Character Positions
Learn this problemProblem statement
You are given a string text containing only ASCII letters and decimal digits.
For every character that is not an ASCII letter, append that character's zero-based index in text to the result. Append each index in decimal form with no separator, preserving left-to-right order.
Return the resulting string. If every character is a letter, return the empty string.
Function
concatenateNonAlphabeticPositions(text: String) → StringExamples
Example 1
text = "ABC65D19HY09"return = "34671011"The digit characters occur at zero-based indices 3, 4, 6, 7, 10, 11. Concatenating those decimal indices gives 34671011.
Example 2
text = "a1b2"return = "13"The digits are at indices 1 and 3.
Example 3
text = "FastPrep"return = ""Every character is an ASCII letter, so nothing is appended.
Constraints
0 <= text.length() <= 200000textcontains only ASCII lettersA-Z,a-z, and digits0-9.