199. Check if Two String Arrays are Equivalent

EasyStringString

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

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

Input: arrays separated by ',' between arrays; '|' between words within each array.
Format: word1_0|word1_1,...,word2_0|word2_1,...

Input: Two comma-separated groups; within each group words are '|' separated.

Output: Return 'true' if the concatenated strings are equal, otherwise 'false'.

Examples

Example 1
Input: ab|c,a|bc
Output: true
Explanation: 'ab'+'c'='abc' and 'a'+'bc'='abc' → equal.
Example 2
Input: a|cb,ab|c
Output: false
Explanation: 'acb' ≠ 'abc' → false.
Example 3
Input: abc|d|defg,abcddefg
Output: true
Explanation: Both concatenate to 'abcddefg'.

Constraints

Asked by

MetaAmazonGoogle
Solve this problem in the editor →