Two relay teams are racing to deliver an identical secret message across a canyon using a hand-off system. Each team splits its copy of the message into an ordered list of text segments before the race begins, and each runner on the team carries exactly one segment to the next hand-off point, in order. At the finish line, splicing a team's segments together in the order they were carried reconstructs whatever message that team actually delivered. Given the segment lists carried by Team A and Team B, determine whether the two teams delivered the exact same final message.
n1, the number of segments Team A carries.n1 space-separated strings, Team A's segments in the order they are spliced.n2, the number of segments Team B carries.n2 space-separated strings, Team B's segments in the order they are spliced.Print exactly one line: true if concatenating Team A's segments in order produces the exact same string as concatenating Team B's segments in order, or false otherwise.
Example 1
Input
3 ab c de 2 abc de
Expected
true
Explanation
Team A's segments "ab", "c", "de" splice together to "abcde". Team B's segments "abc", "de" splice together to "abcde". Both teams delivered the identical message, so the answer is true.
Example 2
Input
2 a cb 2 ab c
Expected
false
Explanation
Team A's segments splice to "a"+"cb" = "acb". Team B's segments splice to "ab"+"c" = "abc". These differ at the second character ('c' vs 'b'), so the answer is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →