Check If Two String Arrays are Equivalent
Easy
106
2
73.1% Acceptance
In this coding lab, you will determine if two given string arrays word1
and word2
represent the same string. A string is represented by an array if the array elements concatenated in order forms the string. You have to write a function arrayStringsAreEqual
that returns true
if the two arrays represent the same string, and false
otherwise.
Consider the following examples:
Example 1:
const word1 = ["ab", "c"]; const word2 = ["a", "bc"]; arrayStringsAreEqual(word1, word2); // Output: true
Explanation:
word1 represents string "ab" + "c" -> "abc"
word2 represents string "a" + "bc" -> "abc"
The strings are the same, so return true.
Example 2:
const word1 = ["a", "cb"]; const word2 = ["ab", "c"]; arrayStringsAreEqual(word1, word2); // Output: false
Example 3:
const word1 = ["abc", "d", "defg"]; const word2 = ["abcddefg"]; arrayStringsAreEqual(word1, word2); // Output: true
Constraints
1 <= word1.length, word2.length <= 103
1 <= word1[i].length, word2[i].length <= 103
1 <= sum(word1[i].length), sum(word2[i].length) <= 103
word1[i]
andword2[i]
consist of lowercase letters.
Challenges
- Export your function
arrayStringsAreEqual
using ESM export. - Confirm that your function works correctly for the provided examples, as well as additional cases.
Note that you must export any function or variable that you use in your code, as this will be required for evaluation during testing.