Aligned Word Joining
Context
Let two finite sequences be written in order. At each shared position, join the two strings into one string. The resulting sequence contains only positions present in both input sequences.
Problem
Implement a function that receives two lists of strings. Process their positions from left to right in alignment. For every position available in both lists, concatenate the first string with the second string, without adding characters or separators, and append the combined string to the result. Stop as soon as either list has no remaining element. Preserve the order of processed positions and omit all unmatched trailing elements. If either input list is empty, return an empty list.
Examples
left = ["red", "green", "blue"]right = ["apple", "pear", "berry"]["redapple", "greenpear", "blueberry"]left = ["sun", "moon", "star"]right = ["light", "rise"]["sunlight", "moonrise"]left = []right = ["alpha", "beta"][]Constraints
0 <= len(left) <= 500 <= len(left[i]) <= 30 for every i0 <= len(right) <= 500 <= len(right[i]) <= 30 for every ileft and right contain only lowercase letters.- Types:
leftis str[],rightis str[]; result is str[]
Function signature
def join_aligned_words(left: list[str], right: list[str]) -> list[str]
leftlist[str]- The first ordered list of strings.
rightlist[str]- The second ordered list of strings.
- returns list[str]
- The ordered list formed by concatenating corresponding strings until the shorter input list is exhausted.
Adapted from MBPP problem task_213 (CC BY 4.0). Rewritten, extended and verified by Iksha.