Check If Two String Arrays are Equivalent - 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.
Input & Output
Example 1 — Basic Case
$
Input:
word1 = ["ab", "c"], word2 = ["a", "bc"]
›
Output:
true
💡 Note:
word1 represents "ab" + "c" = "abc", word2 represents "a" + "bc" = "abc". Both form the same string "abc".
Example 2 — Different Lengths
$
Input:
word1 = ["a", "cb"], word2 = ["ab", "c"]
›
Output:
false
💡 Note:
word1 represents "a" + "cb" = "acb", word2 represents "ab" + "c" = "abc". The strings "acb" and "abc" are different.
Example 3 — Single Characters
$
Input:
word1 = ["abc"], word2 = ["a", "b", "c"]
›
Output:
true
💡 Note:
word1 represents "abc", word2 represents "a" + "b" + "c" = "abc". Both form the same string.
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] and word2[i] consist of lowercase letters.
Visualization
Tap to expand
Understanding the Visualization
1
Input
Two string arrays that need to be compared
2
Process
Check if concatenated strings are equivalent
3
Output
Return true if equivalent, false otherwise
Key Takeaway
🎯 Key Insight: Two string arrays are equivalent if their concatenated forms produce identical strings
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code