# String Abbreviation Matching

Iterative optimization from recursive version

```
  public boolean match(String input, String pattern) {
    //base case: si and ti at end, true
    //Recursive Rule: 
    //if si or ti out of bounds, false
    //if not digit, check equal, recurse si + 1, ti + 1
    //if digit, count digit, increase ti and si
    
    //Recursive impl on gitbook

    //iterative
    int si = 0;
    int ti = 0;

    while (si < input.length() && ti < pattern.length()){
      if (pattern.charAt(ti) < '0' || pattern.charAt(ti) > '9'){
        if (pattern.charAt(ti) != input.charAt(si)){
          return false;
        }
        si++;
        ti++;
      } else {
        int count = 0;
        while(ti < pattern.length() && pattern.charAt(ti) >= '0' && pattern.charAt(ti) <= '9'){
          count = count * 10 + (pattern.charAt(ti) - '0');
          ti++;
        }
        si += count;
      }
    }
    return si == input.length() && ti == pattern.length();

  }
```

Time Comp: O(N) one traversal

Space Comp: O(1) no addition data structure or calls made on stack


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://llssff.gitbook.io/coding-problems/string/string-abbreviation-matching.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
