> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Check If Two String Arrays are Equivalent

> Tested Python solution for LeetCode 1662 with 16 pytest cases. Generate a practice environment with lcpy.

LeetCode 1662, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/array-strings-are-equal/description/).

Generate this problem as a practice environment: tested reference solution, 16 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 1662   # by problem number
lcpy gen -s array_strings_are_equal   # by problem name
```

## Problem

Given two string arrays `word1` and `word2`, return `true` if the two arrays represent the same string, and `false` otherwise.

A string is represented by an array if the array elements concatenated in order forms the string.

### Examples

```
Input: word1 = ["ab", "c"], word2 = ["a", "bc"]
Output: true
Explanation:
word1 represents string "ab" + "c" -> "abc"
word2 represents string "a" + "bc" -> "abc"
The strings are the same, so return true.
```

```
Input: word1 = ["a", "cb"], word2 = ["ab", "c"]
Output: false
```

```
Input: word1  = ["abc", "d", "defg"], word2 = ["abcddefg"]
Output: true
```

### Constraints

* 1 \<= word1.length, word2.length \<= 10^3
* 1 \<= word1\[i].length, word2\[i].length \<= 10^3
* 1 \<= sum(word1\[i].length), sum(word2\[i].length) \<= 10^3
* word1\[i] and word2\[i] consist of lowercase letters.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/array_strings_are_equal/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/array_strings_are_equal/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from collections.abc import Iterator
from itertools import zip_longest


class Solution:
    # Time: O(n + m)
    # Space: O(1)
    def array_strings_are_equal(self, word1: list[str], word2: list[str]) -> bool:
        return all(a == b for a, b in zip_longest(self._chars(word1), self._chars(word2)))

    def _chars(self, words: list[str]) -> Iterator[str]:
        for word in words:
            yield from word
```

## Complexity

| Time | Space |
| - | - |
| O(n + m) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.