FastPrepEncoded String Match
Problems/Encoded String Match

Encoded String Match

Datadog logoDatadog● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Firsthand reports describe whole-string matching with numeric skips, multi-digit counts, inclusive ranges and escaped literal digits. This exercise specifies the callable, valid grammar, zero and empty cases, bounds, and caret as a backslash-equivalent escape. The core task matches the reports at about 85%.

Return whether pattern matches the entire text. Matching is case-sensitive. Parse the pattern from left to right using these rules:

  • A maximal unescaped run of decimal digits skips exactly that many arbitrary text characters. Thus d3dog matches datadog, and a11y matches accessibility.
  • {lo,hi} skips any number of arbitrary characters from lo through hi, inclusive. Each occurrence chooses its count independently.
  • A backslash \ or caret ^ escapes the next single character, which must then match literally. The escape marker consumes no text. This exercise gives both markers the same literal-escape behavior.
  • Every other character matches itself. An unescaped { begins a range; an unescaped } appears only as its closing delimiter. Escape a digit or reserved character when it should be literal.

A skip of zero consumes nothing. Escapes always have a following character. Empty text and empty pattern match each other. A match must consume all text characters and all pattern tokens; matching only a prefix is insufficient.

Function

encodedMatch(text: String, pattern: String) → boolean

Examples

Example 1

text = "datadog"pattern = "d3dog"return = true

The first d matches, the skip consumes ata, and the remaining literal dog matches. All seven text characters are consumed.

Example 2

text = "accessibility"pattern = "a11y"return = true

The first a and last y match literally. The eleven characters between them are consumed by the single number 11.

Example 3

text = "d3dog"pattern = "d\\3dog"return = true

The backslash escapes 3, so it must match the literal digit in the text. The other four characters match literally; no skip occurs.

Example 4

text = "datadog"pattern = "d\\3dog"return = false

After the first d, the escaped 3 requires a literal digit. The next text character is a, so the match fails.

Example 5

text = "datadog"pattern = "d{1,3}dog"return = true

Choose the allowed skip length 3 to consume ata. The literal prefix d and suffix dog then consume the whole text.

Constraints

  • 0 <= text.length, pattern.length <= 200
  • Both inputs contain only printable ASCII characters (codes 32 through 126).
  • The pattern is valid under the grammar above. Every numeric value is between 0 and 1000000000 inclusive, written as 0 or without a leading zero. Each range has lo <= hi.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public boolean encodedMatch(String text, String pattern) {
    // Write your code here.
}
Checking account…