Problem · String

Concatenate Non-Alphabetic Character Positions

Learn this problem
EasyTexas Instruments logoTexas InstrumentsNEW GRADOA

Problem 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) → String

Examples

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() <= 200000
  • text contains only ASCII letters A-Z, a-z, and digits 0-9.

More Texas Instruments problems

drafts saved locally
public String concatenateNonAlphabeticPositions(String text) {
    // write your code here
}
text"ABC65D19HY09"
expected"34671011"
checking account